How do you programmatically move the caret of a Flex TextArea to the end?

前端 未结 6 1241
眼角桃花
眼角桃花 2021-01-12 15:25

I\'m trying to move the caret in a Flex TextArea to the end after appending some text from my code. I\'ve looked through the reference documentation for TextArea and its und

相关标签:
6条回答
  • 2021-01-12 16:02

    Try this

    textArea.selectionBeginIndex = textArea.length;
    textArea.selectionEndIndex = textArea.length;
    
    0 讨论(0)
  • 2021-01-12 16:07

    For people looking for the Spark component way to do this, Flex 4.5, use selectRange(anchorIndex, activeIndex)

    0 讨论(0)
  • 2021-01-12 16:08

    @Paul Stewart verticalScrollPosition is a property not a method so you have to use it similar to a field, like:

    var newPosition:NUmber = 1;
    textArea.verticalScrollPosition = newPosition;
    

    The advantage of using it over a selectionBeginIndex/selectionEndIndex is there you do not have to set a foucus.

    0 讨论(0)
  • 2021-01-12 16:11

    Simply add the following code after adding a text to the TextArea:

    textArea.verticalScrollPosition = textArea.maxVerticalScrollPosition;
    
    0 讨论(0)
  • 2021-01-12 16:12

    I believe you can directly set the textarea's scrollbar with

    verticalScrollPosition : Number
    textArea.verticalScrollPosition(i);
    
    0 讨论(0)
  • 2021-01-12 16:20

    To set the caret at any position in a textArea all u need to do is

    textArea.setSelection(beginIndex, endIndex);

    if u set the beginIndex & endIndex to the same value (in your case textArea.text.length) the caret will be placed at that positon. If you set it to different values, text in that range will be highlighted.

    0 讨论(0)
提交回复
热议问题