Question

i need to add text at cursor position on key_up event of keyboard. first i move cursor using arrow. then when i was trying to write anything it goes to end of the textInput. because i used setrange().

Here is my code sample.....

var view:MainView;

eventMap.mapListener(view.numDisplay,KeyboardEvent.KEY_DOWN,onKeyBoardKeyDown);


private function onKeyBoardKeyDown(vEvent:KeyboardEvent):void
{
    view.numDisplay.selectRange(view.numDisplay.text.length, view.numDisplay.text.length);
    var cno:String=String.fromCharCode(vEvent.charCode);
    var no:String=view.numDisplay.text;
    if(no=="0") no="";
    view.numDisplay.text=no+cno;    
}

example:- if i write

hii alll

then its ok.

after that i use arrow key to move cursor. let's say my cursor was at

a

then if write any thing then it appears like

hii alll123

But i need output as

hii a123lll

Was it helpful?

Solution

i don't know why you are using the line:

view.numDisplay.selectRange(view.numDisplay.text.length, view.numDisplay.text.length);

but maybe you can change it to

view.numDisplay.selectRange(view.numDisplay.caretIndex, view.numDisplay.caretIndex);

to set the selection to the actual cursor position so your text won't be at the end but at the correct position.

Did you try without the line ? what problem do you try to correct with this ? With the standard behavior, the cursor is always after the last character typed. I don't understand why you want to force it to be at the end of the text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top