The "get" command puts the value into the universal variable "it". In this case, the script gets the value of the the selectedchunk, so "it" contains "word x to y of field z". Using "it" is just shorter to type than this:
if word 4 of the selectedchunk > word 2 of the selectedchunk then...
Using "it" also saves the engine from having to retrieve the value twice. You wouldn't need to use "it", you could use a normal variable instead:
put the selectedchunk into tSel
if word 4 of tSel > word 2 of tSel then...
Mark is correct that my first handler didn't allow for partial word selections. To do that, we need to track the timing of the user selection. If the selection changes within the double-click interval, then it is a double click. This should work:
Code: Select all
local sClickTime
on selectionchanged
if (the milliseconds - sClickTime) <= the doubleclickinterval then -- it's a double click
get the selectedchunk
if word 4 of it > word 2 of it then
get the number of words in char 1 to (word 2 of the selectedchunk) of me
select word it of me
end if
end if
put the milliseconds into sClickTime
end selectionchanged
This handler will assume there has been a double-click the first time it is used if you do not initialize sClickTime when the field opens. You should probably add an openField handler that puts the milliseconds into sClickTime.