Quill: How to find current cursor position

Created on 23 Jun 2015  路  3Comments  路  Source: quilljs/quill

Hi there,

I need use the insertText method to insert template variables in the text in the editor at the position of the users cursor. To use this method I need to provide the correct index to insert it as.

Doing this within a text-change or selection-change event works for the first line of text in the editor...

      var sel = editor.root.ownerDocument.getSelection();
      cursorPosition = sel.baseOffset;

But when you hit return into the next paragraph it no longer works.

How would I do this to get the current cursor position in the whole editor for use in the insertText method?

Most helpful comment

Take a look at Quill's getSelection.

All 3 comments

Take a look at Quill's getSelection.

Just discovered that! Should have read in more detail... thanks very much.

@jhchen
How to know what content of text I insert in, I should compare with the old text and current text?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lustoykov picture lustoykov  路  3Comments

DaniilVeriga picture DaniilVeriga  路  3Comments

lastmjs picture lastmjs  路  3Comments

visore picture visore  路  3Comments

splacentino picture splacentino  路  3Comments