This content has been marked as final. Show 4 replies
Clicking the button makes the TextArea lose the focus, which means you can't access the Selection.getCaretIndex();
If someone else has an easier solution I'd love to hear about it... but here's my approach:
In the past when I've dealt with this, its been by listening for the focusIn event for the TextArea... then using setInterval to call a function periodically (maybe every 50 ms) to record the Selection.getCaretIndex() and as long as it is != -1 (-1 means its not there) storing it in a variable. You can then use clearInterval to cancel the inteval when the focusOut event occurs on the TextArea. Your button would use the stored version of the caret index as the insertion point for what you want to add to the text... and for a nice touch you can set the focus back to the text area and then Selection.setSelection for the range of the text you just "pasted" if you want. You may have to manually "fire" the focusIn event to start the sequence for the setInteval again... I can't remember if it fires when done by code.
Fantastic! I'll give that a try. Thanks for the help!
you don't need to use a loop. just use the onMouseUp method to record the Selection.getBeginIndex() and Selection.getEndIndex() (if it's greater than -1).
if you have more than one textfield, you can use the onSetFocus() method of textfields to pass the textfield that's being selected to your onMouseUp handler.
kglad... good option.. and far more elegant...would you use the Key object to track selection changes made using the keyboard as well? arrow keys etc