How to change the position of cursor to particular para in medium editor. I am able to fetch node of the target para but unable to relocate cursor. Tried focus() but its not working. Also tried Editor. selectElement() but it highlights the whole para, didn't move the cursor. Any help on this? Just a beginner to editor
MediumEditor.selection has method moveCursor(doc, node, offset) - https://github.com/yabwe/medium-editor/blob/5.16.0/src/js/selection.js#L653
So you can move cursor to the beginning of element this way:
MediumEditor.selection.moveCursor(document, element, 0);
Doesn't work if editor is on blur state. I am providing ownerDocument also as the firstArgument but still not working on blur state.
If focus is already on editor then works well.
Then try to focus on the editor first. You can try simple click() on the editor first and see if it helps.
The ideal case to set focus would be to do what @orthes recommended.
If you needed a programatic way to set focus, you can also use editor.selectElement() (like you mentioned in your original message). That will indeed highlight an entire element, but it also forces all the normal focus behavior to happen, so you could call selectElement() and then immediately use MediumEditor.select.moveCursor() to simulate the whole flow.
Most helpful comment
Then try to focus on the editor first. You can try simple
click()on the editor first and see if it helps.