[英]Insert text at cursor position in textInput
i need to add text at cursor position on key_up event of keyboard. 我需要在键盘的key_up事件上的光标位置添加文本。 first i move cursor using arrow. 首先,我使用箭头移动光标。 then when i was trying to write anything it goes to end of the textInput. 然后,当我尝试编写任何内容时,它会转到textInput的末尾。 because i used setrange(). 因为我使用了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 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 hii alll123
But i need output as 但是我需要输出
hii a123lll hii a123lll
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. 我不明白您为什么要强制将其放在文本末尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.