Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control cursor (carat) position in TextInput in Flex 4.5

I need to handle diagraphs and then convert them on the fly to the proper unicode representation. For example when the user types in:

Sx

My app needs to replace it with:

Ŝ

Now, I've been able to do the replacement no problem. The issue though is that once I've done the replacement, the cursor goes to the beginning of the textbox rather than the end. As I'm trying to update the user's text on the fly, this obvious doesn't work.

How can I get it so that once I replace the text in the TextInput box, the cursor is on the right hand side rather than the left?

like image 911
PeterM Avatar asked Sep 15 '11 17:09

PeterM


3 Answers

Found a solution.

All you have to do is instead of updating the whole text, wipe the current content and then use:

textInput.appendText()

Hopefully this will help someone else :)

like image 150
PeterM Avatar answered Sep 19 '22 14:09

PeterM


The setSelection method is how you set the cursor

textInput.setSelection(textInput.text.length, textInput.text.length);

You can get the current beginning of the selection with TextInput.selectionAnchorPosition and the end of the selection with TextInput.selectionAnchorPosition

like image 26
deontologician Avatar answered Sep 16 '22 14:09

deontologician


Take a look at this SO Question: How do you programmatically move the caret of a Flex TextArea to the end?

If you are using a textArea then this will work (from the selected answer):

textArea.selectionBeginIndex = textArea.length;
textArea.selectionEndIndex = textArea.length;
like image 42
Todd Moses Avatar answered Sep 19 '22 14:09

Todd Moses