jakiestfu / Medium.js

A tiny JavaScript library for making contenteditable beautiful (Like Medium's editor)
http://jakiestfu.github.io/Medium.js/
4.39k stars 403 forks source link

What methods are available to control the Cursor / Caret? #175

Open pixeline opened 9 years ago

pixeline commented 9 years ago

Hi! Could you clarify for me what methods are actually available to control the caret or cursor position?

For instance, I thought i could use medium.cursor.moveCursorToEnd() but that throws errors.

My personal needs are to be able to place the caret at the very beginning or at the very end of the editable zone, after an ajax update of the html content.

netolicak commented 9 years ago

For move cursor to end or beginning you can use this:

var editor = new Medium({ ... });

// move cursor to end
editor.cursor.moveCursorToEnd(editor.element.lastChild);

// for move cursor to beginning
editor.cursor.caretToBeginning(editor.element.firstChild);
pixeline commented 9 years ago

Thanks!