Translate metadata to field content

Niggemann, Bernd Bernd.Niggemann at
Wed Feb 19 16:40:42 EST 2020

>J. Landman Gay wrote:
>I haven't converted Bernd's script to use formattedStyledText yet but that looks like the way to go.

There is no difference to using styledText for this use case. The number of lines and the number of words are the same between the  two.

You mentioned that you want to apply this to a huge text field.

I tested with the script of RevDataGridLibraryBehaviorsDataGridButtonBehavior which I copied twice into a field. That is about 23,000 lines and about 130,000 runs.
This found a specific metadata of a word towards the end of the text in word 80,000 of roughly 100,000 words in about 250 milliseconds (this excludes loading but includes hiliting of word and setting scroll, each about 25 ms).

However the loading time of styledText a little more than 300 milliseconds (no difference between styledText and formattedStyledText, but htmlText loading of this heavily formatted text is 800 ms). 

If you can manage preloading of the styledText into e.g. a script local variable at startUp or openCard or first run it would save more than half of the processing time.

here is Richard's script which I changed to get the number of words of the line with the tagged word, the number of lines are taken from the array.

The tagged word is then: word tNumWords of line (current array key)

put item 2 of the extents of tDataA into tExtents
   repeat with i = 1 to tExtents
      put item 2 of the extents of tDataA[i]["runs"] into tCounter
      repeat with j = 1 to tCounter
         if tDataA[i]["runs"][j]["metadata"] is tSearchText then
            repeat with m = 1 to j
               add the number of words of tDataA[i]["runs"][m]["text"] to tNumWords
            end repeat
            put true into tFlagExit
            exit repeat
         end if
      end repeat
      if tFlagExit then exit repeat
   end repeat

select word tNumWords of line i of field "x"

Kind regards

More information about the use-livecode mailing list