setting the default folder to the folder where the stack is..

Dave Cragg dcragg at lacscentre.co.uk
Mon Dec 17 03:49:01 EST 2001


At 2:48 pm -0800 16/12/01, John wrote:
>     Hope someone can help.  I have an application that needs to look 
>the text the user is typing and editing in real time.  For each 
>keystroke I need to work out what the current word is.  This is 
>complicated a bit by the fact that the user is free to edit text 
>anywhere in the field - simply capturing keystrokes and building the 
>word as they type will not work because they could have begun 
>editing a word in previously typed text.  The following example 
>solves the problem but is very, very slow (to the point of making it 
>unusable).
>
>on keyDown
>   global keyDownPoint
>   put the selectedLoc into keyDownPoint   --get the location of the 
>insertion point
>   pass keyDown
>end keyDown
>
>
>on keyup
>   global keyDownPoint
>   put the selectedLoc into lastPoint             --get the location 
>of the insertion point
>   click at keyDownPoint                          --click at the word 
>based on the KeyDown event
>   put the clicktext & return after field "debug" --so I can see what 
>has happened
>   click at lastPoint                             --put the insertion 
>point back so I don't type 'backwards'
>   pass keyUp
>end keyup
>
>
>    Does anyone know of a way to do this that is reasonably fast? 
>Any thoughts at all would be appreciated.

Try this. (Not fully tested.)

Putting it in a rawKeyUp handler will also get the current word when, 
for example, the delete key is pressed.

on rawKeyUp
   put  length(the text of me) into tLength
   put word 4 of the selectedChunk into tStart
   repeat with i = tStart down to 1
     if char i of the text of me is in space & tab & cr or i = 1 then
       put i into tP1
       exit repeat
     end if
   end repeat

   repeat with i = tStart  to tLength
     if char i of the text of me is in space & tab & cr or i = tLength then
       put i into tP2
       exit repeat
     end if
   end repeat
   put char tP1 to tP2 of the text of me into field "debug"
   pass rawKeyUp
end rawKeyUp

Cheers
Dave Cragg



More information about the use-livecode mailing list