I have a div with contenteditable="true". At times I insert tokens into the content. I don't want to user to modify the token (except to delete it if desired). When a selection enters one of these tokens I skip it on over to the other end. Unfortunately, if someone makes a selection with the caret on the left side, and I modify it, it suddenly is on the right side in Firefox. (I will be extending this to accommodate other browsers, but one thing at a time.) How can I preserve which end the caret is on when I'm modifying the selection?
Asked
Active
Viewed 58 times
0
-
http://stackoverflow.com/a/4802994/96100 – Tim Down Sep 13 '13 at 09:36
-
@TimDown Thanks. Unfortunately [this](https://developer.mozilla.org/en-US/docs/Web/API/Selection) is all I found on selections. It lists it as experimental and I can't find what supports it and to what extent. Otherwise [this](https://developer.mozilla.org/en-US/docs/Web/API/Selection.extend) would be very useful. Without it, I'm restricted to using [ranges](https://developer.mozilla.org/en-US/docs/Web/API/range) to modify selections, but I can't get it to work in this case. – ricksmt Sep 16 '13 at 17:18
-
1It's not really very experimental. Mozilla made up the API about 10 years ago and it's been copied by everyone else since, and [(mostly) standardized](https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections). Using ranges is generally the most flexible way to modify the selection but gives you no control over the direction. – Tim Down Sep 16 '13 at 22:36
-
1I can tell you how well Selection's `extend()` method is supported: everything except IE supports it, as mentioned in the linked answer. – Tim Down Sep 16 '13 at 22:38