Sorry to ask, but im hitting a little brick wall with this one!
Is it possible to find the location of the cursor in a text box?
I just need it so I can return a user to the same cursor position after Ive run some other code that is causing the text box to lose its focus. When I focus back on the control it places the cursor at the end and not where it was, which is a little annoying for the user.
Id guess I need to use....
select after char tMyChar of field "myField"
to place the user where I want them, but how do I find out the value of tMyChar.
If its not possible, Ill try to figure out how to keep the focus on the control while executing the code, but the quick option for me at the moment would to simply log the position in a temporary variable, then pick it back up when the code is finished.
Thanks
Andy
Getting the position of the cursor in a text field.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Sorry, managed to get there in the end.
Just posting the solution I found in case its any use to anyone else...
Im sure there are more elegant ways to do it, but this seems to work!
Thanks
Andy
Just posting the solution I found in case its any use to anyone else...
Code: Select all
set the itemdel to space
put item 4 of the selectedchunk of field "myField" into tMyCharLoc
-- Code here that loses the focus..., then to re-gain it...
select after char tMyCharLoc of field "myField"
Thanks
Andy
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
You don't have to change the itemDelimiter - just use the word chunk
HTH,
Jan Schenkel.
Code: Select all
put word 2 of the selectedChunk of field "Foobar" into tSelectionStart
put word 4 of the selectedChunk of field "Foobar" into tSelectionEnd
if tSelectionEnd < tSelectionStart then
-- the cursor is currently between two chars
else
-- there is actually a chunk of text selected
end if
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- Livecode Opensource Backer
- Posts: 10094
- Joined: Fri Feb 19, 2010 10:17 am
Re: Getting the position of the cursor in a text field.
- Attachments
-
- INSERT.livecode.zip
- Here's the stack.
- (1.36 KiB) Downloaded 151 times