3

I need to create a selection in JavaScript in a content editable HTML with define the caret at start of selection. The goal is that to allow the user to continue the selection later with the shortcut Shift + .

The main problem is when I defined a new range, the "direction" of selection is lost.

var selection = window.getSelection();
var range = document.createRange();
range.setStart(selection.anchorNode, selection.anchorOffset);
range.setEnd(selection.focusNode, selection.focusOffset);
selection.removeAllRanges();
selection.addRange(range);
FZs
  • 16,581
  • 13
  • 41
  • 50
Freddy
  • 137
  • 8
  • Does this answer help? https://stackoverflow.com/questions/3972014/get-contenteditable-caret-index-position – DaCurse Feb 15 '20 at 12:30

0 Answers0