Flex 3 setSelection with htmlText
-
28-10-2019 - |
Frage
In Adobe Flex 3, this causes problems.
textArea.setSelection( textArea.htmlText.indexOf( 'testString' ), textArea.htmlText.indexOf( 'testString' ) + 10 );
This puts the cursor in the wrong place, because indexOf takes into account the HTML tags, but setSelection does not.
Anyone know how to do this? A simple way is a /<[^>]*>/g regular expression, but this doesn't do the job every time.
Help please!
Andrew
Lösung
Try this instead:
textArea.setSelection( textArea.text.indexOf( 'testString' ), textArea.text.indexOf( 'testString' ) + 10 );
By using the 'text' property instead of 'htmlText', you're removing the html tags. Also, I wouldn't use 2 index searches, it's not efficient. Try this:
var string:String = 'testString';
var index:int = textArea.text.indexOf(string);
textArea.setSelection(index, index + string.length);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow