how to get ibeam location

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

how to get ibeam location

Post by dhobbs » Thu Apr 18, 2013 6:48 pm

Hey, I'm interested in controlling the properties of text as it is being entered into a field. Specifically, I'm making a chemistry application and need to distinguish numbers and letters, then would like to make all the numbers to be subscript as I type them in. The following code works but is a bit too simple:

Code: Select all

on keyDown tKey
   put toUpper (tKey) after fld "test"
   put the length of fld "test" into y
   
   if isNumber (char y of fld "test") is true then
      set the textSize of char y of fld "test" to 10
      set the textShift of char y of fld "test" to 3
   else if matchText (char y of fld "test", "[A-Z]") is true then 
      set the textSize of char y of fld "test" to 12
      set the textShift of char y of fld "test" to 0
   end if
end keyDown
The problem is that I always add the new characters at the end of the string. If someone makes a mistake and moves the cursor to the middle, deletes a character and retypes, my code sticks the changes at the end. How to I poll the cursor position? I think this should be easy to do, but can't find the proper handler to access the position in the text the ibeam is located.

Sorry if this seems trivial, but it's amazing how simple things can completely stall progress.

--Doug

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: how to get ibeam location

Post by dunbarx » Thu Apr 18, 2013 7:26 pm

Hi.

It is always the little things.

You tell the handler to append the text with "after".

Try this:

Code: Select all

 put toUpper (tKey) after the selection
Can you handle where the selection is? You will need to...

Craig Newman

Post Reply