textarea caret position when shift and arrow keys are used?

370 views Asked by At

I found a few nice answers for finding the caret position in a textarea but I have yet to find one that can detect the caret position after the shift key is held and arrow keys are used. When the shift key is held the cursor could go back or forward during a selection and so using the selectionStart and selectionEnd concept does not seem to be reliable for cursor position in that case.

Anyone have a good solution?

Thanks!

1

There are 1 answers

0
C.B. On

Actually, considering that the caret can only be at either selectionStart or selectionEnd, you could solve this by merely keeping track of the previous start+end, and see which changed. It is a bit of work (since it requires set operations for such cases as 15-20 changing to 20-25 after a Shift+End operation), but i don't think it's too difficult.