In vue-quill-editor, how to insert text in the cursor by clicking the button?

according to the needs of the project, when editing rich text, there is a corresponding button on the side that can be clicked to add fixed-format text at the cursor.
such as:
in "111111" when the cursor clicks the button at the end, the text in the rich text will become "111111222" if the light changes after the first "1", it will become "122211111" this form
I directly in the click when the trigger function, directly at the end of the text in a fixed format, okay, I think too much.

<template>
  <div>
    <quill-editor
      ref="myTextEditor"
      v-model="content"
      :config="editorOption"
      @blur="onEditorBlur($event)"
      @focus="onEditorFocus($event)"
      @ready="onEditorReady($event)"
    >
    </quill-editor>
    <el-button
      type="primary"
      @click="demo"
    >demo</el-button>
  </div>
</template>

<script>
import { quillEditor } from "vue-quill-editor";
export default {
  components: {
    quillEditor
  },
  data() {
    return {
      content: "I am Example",
      str: "",
      editorOption: {
        // something config
      }
    };
  },
  mounted() {
    console.log("this is my editor", this.content);
  },
  computed: {
    editor() {
      return this.$refs.myTextEditor.quillEditor;
    }
  },
  methods: {
    //
    onEditorBlur(editor) {
      console.log("editor blur!", editor);
    },
    //
    onEditorFocus(editor) {
      console.log("editor focus!", editor);
    },
    // 
    onEditorReady(editor) {
      console.log("editor ready!", editor);
    },
    //
    onEditorChange({ editor, html, text }) {
      // console.log("editor change!", editor, html, text)
      this.content = html;
    },
    demo() {
      let acc = "123456";
      this.content = this.content + acc;
    }
  }
};
</script>

is about a form like this

Mar.28,2022


    onEditorChange(editor) {
      //
      var selection = getSelection();
      // 
      this.lastEditRange = selection.getRangeAt(0);
      console.log(this.lastEditRange);
    },
    onEditorFocus(editor) {
      //
      console.log("");
      var selection = getSelection();
      // 
      this.lastEditRange = selection.getRangeAt(0);
      console.log(this.lastEditRange);
    },
    addFormattingText(e) {
      let edit = $(".ql-editor")[0];
      console.log(edit);
      let options = e;
      console.log(options);
      edit.focus();
      let selection = getSelection();
      console.log(selection);
      console.log(this.lastEditRange);
      if (this.lastEditRange) {
        console.log(this.lastEditRange);
        console.log("");
        // 
        selection.removeAllRanges();
        selection.addRange(this.lastEditRange);
      }
      if (selection.anchorNode.nodeName != "-sharptext") {
        // 
        var emojiText = e;
        // var range = document.createRange()
        // console.log(emojiText)
        console.log(edit.childNodes);
        console.log(selection.anchorOffset);
        if (edit.childNodes.length > 0) {
          // 0
          for (var i = 0; i < edit.childNodes.length; iPP) {
            if (i == selection.anchorOffset && selection.anchorOffset != 0) {
              console.log("");
              edit.insertBefore(emojiText, edit.childNodes[i]);
            } else {
              console.log("");
              console.log(edit.children[0]);
              edit.children[0].appendChild(document.createTextNode(emojiText));
            }
          }
        } else {
          // 
          edit.appendChild(emojiText);
        }
        if (window.getSelection) {
          //ie11 10 9 ff safari
          edit.focus(); //ff
          var range = window.getSelection(); //range
          range.selectAllChildren(edit); //range obj
          range.collapseToEnd(); //
        } else if (document.selection) {
          //ie10 9 8 7 6 5
          var range = document.selection.createRange(); //
          //var range = document.body.createTextRange();
          range.moveToElementText(edit); //rangeobj
          range.collapse(false); //
          range.select();
        }
        // 
        // edit.focus();
        // var range = document.createRange();
        // console.log(range);

        // // 
        // range.selectNodeContents(emojiText);
        // // 
        // range.setStart(emojiText, emojiText.length);
        // // 
        // range.collapse(true);
        // // 
        // selection.removeAllRanges();
        // // 
        // selection.addRange(range);
      } else {
        console.log("");
        // 
        var range = selection.getRangeAt(0);
        // textNode
        var textNode = range.startContainer;
        // 
        var rangeStartOffset = range.startOffset;
        // 
        textNode.insertData(rangeStartOffset, e);
        //                    textNode.insertData(rangeStartOffset, emojiInput.value)
        // 
        range.setStart(textNode, rangeStartOffset + e.length);
        //                    range.setStart(textNode, rangeStartOffset + emojiInput.value.length)
        // 
        range.collapse(true);
        // 
        selection.removeAllRanges();
        // 
        selection.addRange(range);
      }
      // 
      this.lastEditRange = selection.getRangeAt(0);
    }

first check whether insertText is provided in the official document. If you don't use document.execCommand to implement

.
//
getCursorPosition:function(){
  _this.curTxtPoint  = this.$refs.myQuillEditor.quill.selection.savedRange.index;
},
//
setCharacter:function(str,index){
  _this.curTxtPoint = '';
  this.$refs.myQuillEditor.quill.insertText(index,str);
},
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb23ba-23c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb23ba-23c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?