Question

Dans Adobe Flex 3, ce provoque des problèmes.

textArea.setSelection( textArea.htmlText.indexOf( 'testString' ), textArea.htmlText.indexOf( 'testString' ) + 10 );

Cela met le curseur au mauvais endroit, parce que indexOf prend en compte les balises HTML, mais setSelection ne fonctionne pas.

Quelqu'un sait comment faire cela? Une façon simple est un / <[^>] *> / g expression régulière, mais cela ne fait pas le travail à chaque fois.

Aide s'il vous plaît!

Andrew

Était-ce utile?

La solution

Essayez ceci:

textArea.setSelection( textArea.text.indexOf( 'testString' ), textArea.text.indexOf( 'testString' ) + 10 );

En utilisant le « texte » propriété au lieu de « htmlText », vous supprimez les balises HTML. En outre, je ne voudrais pas utiliser 2 recherches d'index, ce n'est pas efficace. Essayez ceci:

var string:String = 'testString';
var index:int = textArea.text.indexOf(string);
textArea.setSelection(index, index + string.length);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top