Medium-editor: Change Cursor Position to particular para Medium Editor

Created on 13 Apr 2016  路  4Comments  路  Source: yabwe/medium-editor

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

question

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

entere picture entere  路  6Comments

sPaCeMoNk3yIam picture sPaCeMoNk3yIam  路  5Comments

tyler-johnson picture tyler-johnson  路  5Comments

adriendlph picture adriendlph  路  4Comments

taiji202 picture taiji202  路  6Comments