如何在 Flex 4.5 的 TextInput 中控制光标(克拉)位置

发布于 2024-12-04 22:54:56 字数 257 浏览 1 评论 0原文

我需要处理图,然后将它们即时转换为正确的 unicode 表示形式。例如,当用户输入:

Sx

我的应用程序需要将其替换为:

Ŝ

现在,我已经能够毫无问题地进行替换。但问题是,一旦我完成替换,光标就会转到文本框的开头而不是结尾。当我试图动态更新用户的文本时,这显然不起作用。

如何才能使替换 TextInput 框中的文本后,光标位于右侧而不是左侧?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

撩发小公举 2024-12-11 22:54:56

找到了解决方案。

您所要做的就是不要更新整个文本,而是擦除当前内容,然后使用:

textInput.appendText()

希望这对其他人有帮助:)

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

离不开的别离 2024-12-11 22:54:56

setSelection 方法是设置光标的方法。

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

您可以使用 TextInput.selectionAnchorPosition 获取当前选择的开始位置,使用 TextInput.selectionAnchorPosition 获取当前选择的结束位置

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

调妓 2024-12-11 22:54:56

看看这个问题:如何以编程方式将 Flex TextArea 的插入符移动到末尾?

如果您使用的是 textArea 那么这将起作用(从所选答案):

textArea.selectionBeginIndex = textArea.length;
textArea.selectionEndIndex = textArea.length;

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;
素罗衫 2024-12-11 22:54:56

对于来这里寻求 Spark textInput 解决方案的人来说,方法如下:

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

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

textInput.selectRange(textInput.text.length, textInput.text.length);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文