Inserting Text At Cursor Location With Quill.js

josephmisiti picture josephmisiti · May 14, 2014 · Viewed 8.9k times · Source

I am trying to add a custom piece of functionality ("module") to quill.js and cannot seem to do it. Here is what I need:

If want to add a button that inserts a template replacement variable... say something like {{company}} at the location of the cursor in the editor, is that currently possible with the API - I thought I could do it using insertText but I cant seem to get it to work.

Thanks

Answer

Tikall picture Tikall · Apr 16, 2019

What I ended up doing in a very similar setup:

let mergeFieldText = '{{company}}';
var selection = this._quill.getSelection(true);
this._quill.insertText(selection.index, mergeFieldText);