0

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

andrewpthorp
  • 4,998
  • 8
  • 35
  • 56
  • What if you use text instead of htmlText? textArea.text.indexOf( 'testString' ). In theory that should give you the same text that 'setSelection' is looking at. – JeffryHouser Mar 21 '11 at 18:06

1 Answers1

0

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);
J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • I am not sure why, but Alert.show( textArea.htmlText ) shows the correct html text, Alert.show( textArea.text ) shows a blank string. – andrewpthorp Mar 21 '11 at 21:29
  • Marking yours as correct, because ideally your answer is absolutely correct. Sorry this took so long! – andrewpthorp Apr 20 '11 at 13:43