Way to insert text where cursor is in field?

J. Landman Gay jacque at hyperactivesw.com
Sun Aug 24 23:49:01 EDT 2003


On 8/24/03 10:53 PM, Rob Gould wrote:

> I'm sure I must be overlooking something simple - - - - What I'm trying to do is 
> have a text field that detects when the user presses the character "*", and when 
> they do, it replaces that "*" with a bitmap graphic.  (Using the imageSource 
> call). 
> 
> I've got the below code which _almost_ does this, except that it replaces all 
> the astericks except the one that the user just pressed.  The trick here is that 
> the user can click and put the cursor anywhere in the text field, so it's not 
> like I can just add an "*" to the last char of the field and swap it out.  I 
> somehow need to find out the position in the text field where the cursor is, and 
> add the asterick, and THEN run the "refreshnotes" handler.

The "selectedChunk" function is your friend here. Try this:

on keydown theKey
   if theKey = "*" then
     get the selectedchunk
     do "put theKey into" && it
     set the imagesource of char (word 2 of it) of me to "checkbox"
   else
     pass keydown
   end if
end keydown

You don't need a "refreshnotes" handler, just this one in the script of 
the field.

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




More information about the use-livecode mailing list