I'm trying to move the cursor in react slate-editor.
I tried to do it in 2 ways.
First:
// This code saving key in offset in variables
const nativeSelection = this.getSelectedText();
const nativeRange = nativeSelection.getRangeAt(0);
const range = findRange(nativeRange, this.editor);
const offset = nativeRange.endOffset;
const key = range.anchor.key;
// OnChange is triggered by running the next line and cursor moves back
this.editor.blur();
// Trying to move to the cursor
this.editor.moveTo(key, offset);
Second:
const nativeSelection = this.getSelectedText();
const nativeRange = nativeSelection.getRangeAt(0);
const range = findRange(nativeRange, this.editor);
const clonedRange = _.cloneDeep(range);
// OnChange is triggered by running the next line and cursor moves back
this.editor.blur();
// Trying to move the cursor
this.editor.select(clonedRange);
Unfortunately, select
and moveTo
doesn't seem to affect the cursor position.
Can someone assist ?