Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Cursor Position to particular para Medium Editor #1056

Closed
ankur0890 opened this issue Apr 13, 2016 · 4 comments
Closed

Change Cursor Position to particular para Medium Editor #1056

ankur0890 opened this issue Apr 13, 2016 · 4 comments
Labels

Comments

@ankur0890
Copy link

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

@linkesch
Copy link
Member

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);

@ankur0890
Copy link
Author

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.

@linkesch
Copy link
Member

Then try to focus on the editor first. You can try simple click() on the editor first and see if it helps.

@nmielnik
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants