Return first visible text at scroll point?

J. Landman Gay jacque at hyperactivesw.com
Tue Feb 22 14:41:54 EST 2005


On 2/21/05 11:16 PM, Mark Swindell wrote:

> How could I return the first visible line of text at a random scroll 
> point in a text field?  Say my scroll is 1745... I want to know the 
> first words that appear at that point in the scroll... not the line 
> number  which could begin above the scroll,  but the actual text that is 
> first visible at 1745...

I think I'd cheat a little and let the engine do it:

on getword
   put the selectedchunk into tSaveChunk
   get the topleft of fld 1
   put (item 1 of it + 10, item 2 of it + 10) into tStartLoc
   get the topright of fld 1
   put (item 1 of it - 10, item 2 of it + 10) into tEndLoc
   drag from tStartLoc to tEndLoc
   put the selectedText -- here's your text
   select tSaveChunk
end getword

You may need to adjust the click location if your margins aren't 
standard. You can also remove the part that saves and restores the 
current selection if the field is not editable. I didn't try it, but 
this may require that the field have its traversalOn set to true.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com


More information about the use-livecode mailing list