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?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
PeterM
  • 2,534
  • 6
  • 31
  • 38

4 Answers4

6

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 :)

PeterM
  • 2,534
  • 6
  • 31
  • 38
2

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

deontologician
  • 2,764
  • 1
  • 21
  • 33
  • selectionActivePosition is a read only attribute so you can't actually set it to anything unfortunately. I found some examples like this but obviously I couldn't get them to work :-/ – PeterM Sep 16 '11 at 08:08
1

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;
Community
  • 1
  • 1
Todd Moses
  • 10,969
  • 10
  • 47
  • 65
0

For the people coming here for the solution for the Spark textInput, this is the way:

textInput.selectRange(textInput.text.length, textInput.text.length);
Wes
  • 399
  • 5
  • 14