0

我目前正在将 HTML 元素插入到 Rails ActionText/Trix 编辑器中,

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

此代码在编辑器末尾成功插入元素,但我想在当前文本光标之后插入元素。有没有办法在 Trix 编辑器中获取文本光标的当前位置?

4

0 回答 0