[英]How to get word under current cursor position in textarea in flex 4
[英]How to find current cursor position in textArea in flex4?
我想用键盘(内置键盘)在文本区域写东西,并希望在当前光标位置添加由我制作的键盘中的其他东西。
只需使用TextArea的属性即可
selectionActivePosition
这是一个有效的例子 。
//编辑
要在textarea中插入新字符串,请使用字符串函数,如substr()和length()。 插入后,您应该通过添加插入字符串的长度来更改光标的当前位置。
编辑//
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
protected function onBtnInsert(event:MouseEvent):void
{
var str:String = "[new text]";
var pos:int = taMain.selectionActivePosition;
if (pos != -1)
{
taMain.text = taMain.text.substr(0, pos) + str + taMain.text.substr(pos, taMain.text.length - pos);
taMain.selectRange(pos + str.length, pos + str.length);
}
}
]]>
</fx:Script>
<s:VGroup x="20" y="20">
<s:TextArea id="taMain" width="200" height="150" text="I want to write something in text area with keyboard(built in keyboard) and want to add something other from the keyboard made by me at the current cursor position."/>
<s:HGroup verticalAlign="bottom">
<s:Button label="Get Pos" click="{laPos.text = taMain.selectionActivePosition.toString()}"/>
<s:Label text="Current position: "/>
<s:Label id="laPos"/>
</s:HGroup>
<s:Button label="Insert text" click="onBtnInsert(event)"/>
</s:VGroup>
</s:Application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.