0

I am currently inserting HTML elements into the Rails ActionText/Trix editor,

function insertAttachment (data, trix) {
  const editor = document.getElementById("post_content").editor;
  const length = editor.getDocument().toString().length;
  editor.setSelectedRange(length - 1);
        
  const attachment  = new Trix.Attachment({
    content: data['data']['html'],
    sgid:    data['data']['sgid']
  });
    
  editor.insertAttachment(attachment);
}   

This code successfully inserts the element at the end of the editor, but I'd like to insert element right after the current text cursor. Is there any way to get current position of the text cursors in Trix Editor?

yumado
  • 1
  • 1

0 Answers0