I would like to the coordinates of caret or selection or recently
typed character in a textArea control.
I'm trying to display a context menu below the line with the caret,
when a user presses a specific key or an accelerator sequence. The
menu would dispay a list of suggested words to complete the typed
word. It's code-completion.
I've been thinking about the following solution:
Is it posiible to get the coordinates by somehow getting the
textRange of selected text only, or for example getting the
textRange of the whole text in textArea and then retrieving the
coordinates by counting the lines and characters from the beginning
of text in textArea control to the caret positon.
Anyway, how to retrieve these coordinates?
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As far as I know, there is no standard way to retrieve the carret position on text fields or text areas.
This sucks, and led to lots of extra code on the mask scripts, and even with that extra code, after typying, the cursor is positioned at the end... :-(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, I saw there's no standard way to do that.
But, there are specific ways on specific browsers.
Take a look at http://www.codingforums.com/archive/index.php/t-907
Perhaps future versions of the mask will include this...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have used some extra time I had and implemented some functions on JavaScriptUtil to manipulate a text selection / caret. They are only supported on Internet Explorer and Mozilla based browsers, and on IE requires a (unique) call to prepareForCaret(input).
The masks now use this information too, allowing the user to type text on the middle of the mask and keep the caret where it was expected to be...
Cool! :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to the coordinates of caret or selection or recently
typed character in a textArea control.
I'm trying to display a context menu below the line with the caret,
when a user presses a specific key or an accelerator sequence. The
menu would dispay a list of suggested words to complete the typed
word. It's code-completion.
I've been thinking about the following solution:
Is it posiible to get the coordinates by somehow getting the
textRange of selected text only, or for example getting the
textRange of the whole text in textArea and then retrieving the
coordinates by counting the lines and characters from the beginning
of text in textArea control to the caret positon.
Anyway, how to retrieve these coordinates?
Thanks in advance.
As far as I know, there is no standard way to retrieve the carret position on text fields or text areas.
This sucks, and led to lots of extra code on the mask scripts, and even with that extra code, after typying, the cursor is positioned at the end... :-(
Well, I saw there's no standard way to do that.
But, there are specific ways on specific browsers.
Take a look at http://www.codingforums.com/archive/index.php/t-907
Perhaps future versions of the mask will include this...
I have used some extra time I had and implemented some functions on JavaScriptUtil to manipulate a text selection / caret. They are only supported on Internet Explorer and Mozilla based browsers, and on IE requires a (unique) call to prepareForCaret(input).
The masks now use this information too, allowing the user to type text on the middle of the mask and keep the caret where it was expected to be...
Cool! :-)