Search code examples
javascriptckeditor

CKEDITOR move cursor to end of selection


I need to move cursor at the end of selection, for example I have:

some |text| abc

where | is selection start and end

and I neet to position cursor here:

some text^ abc

removing the selection

How can I achieve this? I tried editor.getSelection().getRanges()[0] and modifiying startOffset but this doesn't seem to work.


Solution

  • A bit late, but for anyone looking the answer (assuming a CKEditor instance named editor1):

    const range = editor1.getSelection().getRanges()[0];
    const endNode = range.endContainer;
    const endOffset = range.endOffset;
    range.setStart(endNode, endOffset);
    range.setEnd(endNode, endOffset);
    editor1.getSelection().selectRanges([range]);
    editor1.focus();