Question

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

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top