How to set caret (cursor) position in a textField from a KeyEvent...
...that follows the up-Arrow.
Hi all,
I'm building part of an UI that suggests certain words based on to the user's input. (Quit like Google's suggestions) It works quite well but one detail bothers me:
When I have a list of suggestions I highlight the list-items by listening to the arrow up and down keys. When the fist element is highlighted, and the user presses the up arrow, I want the cursor to be in the Text(Input)Field again, but at the last position.
(I removed the focus from the InputField not to move the cursor in my singel line field to the first position when the up-arrow is pressed)
I set the cursor to the last Position using setSelection() but as it is the field receives the key-press after my event callback is executed and the pressing of the up-arrow in a single line field does what it always does, it places the cursor at the first position.
My somewhat dirty solution is to use a Timer to solve it, but a fast typer might still experience problems.
I considered using the CHANGE event, but as the arrow key does not actually change the content of the TextField, that is not working. Still I think that the solution might be along that way, as the CHANGE event is/would be at the end of the event-chain, where I need to do the repositioning of the cursor.
I did some research, but could not find something so I would be very glad I someone could point me into the right direction.
TA
M
