Flex 3 SetSelection con htmltext
-
28-10-2019 - |
Domanda
In Adobe Flex 3, questo causa problemi.
textArea.setSelection( textArea.htmlText.indexOf( 'testString' ), textArea.htmlText.indexOf( 'testString' ) + 10 );
Ciò mette il cursore nel posto sbagliato, perché l'indice di TEINT dei tag HTML, ma SetSelection no.
Qualcuno sa come farlo? Un modo semplice è A /<[^>]*> /g di espressione regolare, ma questo non fa il lavoro ogni volta.
Aiuto per favore!
Andrea
Soluzione
Prova invece questo:
textArea.setSelection( textArea.text.indexOf( 'testString' ), textArea.text.indexOf( 'testString' ) + 10 );
Usando la proprietà "Testo" invece di "HTMLText", stai rimuovendo i tag HTML. Inoltre, non userei 2 ricerche sull'indice, non è efficiente. Prova questo:
var string:String = 'testString';
var index:int = textArea.text.indexOf(string);
textArea.setSelection(index, index + string.length);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow