Caret/insert position in field
J. Landman Gay
jacque at hyperactivesw.com
Fri May 14 16:12:33 EDT 2010
Jeff Massung wrote:
> Just want to take a moment and re-explain my problem a little.
>
> The user is typing in the field, and I'd like to do some special formatting
> when the user hits the tab key. So, immediately I have:
>
> on tabKey
> put the selectedLine
> end tabKey
>
> This will give me something like "line 204 of field 2", which is great, and
> I can use that to get the text on that line so I can begin formatting.
>
> The problem is that I need to know the user's caret (insert) position,
> because the formatting will behave differently if the insert position is at
> the beginning of the line as opposed to somewhere in the middle. For
> example, if at the beginning, it might actually insert a tab, otherwise it
> will do something else.
>
> But, I can't seem to figure out where the insert position within that line
> happens to be. The selectedChunk returns characters from the start of the
> field.
>
> Thanks for the suggestions.
This seems to work but I'm not sure how fast it would be on huge data
sets. The engine is pretty fast in general though when it comes to text
chunking:
function charCount
put (the number of chars in line 1 to (word 2 of the selectedline)-1 \
of me) + 1 into tTotal -- to end of prev line plus the CR
put word 4 of the selectedchunk into tCharPos
return tCharPos - tTotal
end charCount
That extra "+1" at the end of the first line is to account for the
carriage return, which Rev won't count otherwise.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list