AnsweredAssumed Answered

Get( ActiveSelection* ) functions counting combining accents! oops!

Question asked by mrwatson-gbs on Sep 26, 2017
Latest reply on Sep 27, 2017 by tsplatypus


I reported today the problem that Save as PDF renders combined accents incorrectly ... whilst trying to build a correction function / workaround for that problem I discovered a further related bug:


Get( ActiveSelectionStart ) and Get( ActiveSelectionSize ) functions

return incorrect results, when there are combining accents in the field ...


The problem is that they count the combining accents as an extra character, causing the start position and size to be  too big.


In the following screenshot the o-umlaut characters in the two words "Wöchentlich" comprise an o and a combining umlaut, ... as you see from the data viewer expression on the right the start position is 1 too large, and the length is one two large, causing the WRONG TEXT to be returned from the standard expression.


BUG in ActiveSelectionStart and Size.png



(I think this bug also explains some strange behaviour we have seen in the past, and not been able to identify.)



Steps to reproduce

  1. Using the example file from the related issue, …
  2. Select some text from the first field (where all the accented characters are constructed using a combining character
  3. Enter the expression into the data viewer:
    Middle ( Get( ActiveFieldContents ) ; Get( ActiveSelectionStart ) ; Get( ActiveSelectionSize ) )
  4. Repeat 3 + press [Refresh Values] as necessary


Expected result

The data viewer should return exactly the selected text


Actual Result

The data viewer returns a selection slightly further down the line


A bad workaround

Instead of using these functions you can use Copy + a plugin function to read the clipboard, but this requires a third party plugin, AND overwrites the current clipboard contents.


An attempted Workaround

I wrote a function to recalculate the selection (you can recognize + count the combining marks due to a %cc in the URL-encoded version of the string) :


/* G_SY_SelectedText

2017-09-26 RW: Version 0.1




vActiveSelectionStart = Get( ActiveSelectionStart ) ;

vPreText = Left( Get( ActiveFieldContents ) ; vActiveSelectionStart-1 ) ; /* TOO MUCH */


vActiveSelectionStartCorrected = vActiveSelectionStart - PatternCount ( GetAsURLEncoded ( vPreText ) ; "%cc" ) ;



vActiveSelectionSize = Get( ActiveSelectionSize ) ;

vText = Middle( Get( ActiveFieldContents ) ; vActiveSelectionStartCorrected ; vActiveSelectionSize ) ; /* TOO MUCH */

vURL = GetAsURLEncoded ( vText ) ;

vCountCombiningMarks = PatternCount ( vURL ; "%cc" ) ;

vSelectionSizeCorrected = vActiveSelectionSize - vCountCombiningMarks ; /* possibly TOO LITTLE */


vTextCorrect = Middle( Get( ActiveFieldContents ) ; vActiveSelectionStartCorrected ; vSelectionSizeCorrected )








but it does not work, if there are further combining characters close AFTER the end of the real selection:


Workaround fails.png


...It's a tricky one!


Please update these functions soon ... it makes correcting the other problem very difficult!


Have fun fixing it FMI!