Inserting a new text at given cursor position

后端 未结 7 2141
夕颜
夕颜 2021-01-01 18:35

I am working on customizing the codemirror for my new language mode. As part of this new mode implementation, I am writing a new tool bar where user can select some text and

相关标签:
7条回答
  • 2021-01-01 19:05

    This function is used to insert to the specified position and move the cursor to the end of the inserted text.

      function insertToCodeMirror(text) {
        const doc = codeMirrorInstance.getDoc();
        const cursor = codeMirrorInstance.getCursor();
        doc.replaceRange(text, cursor);
        codeMirrorInstance.focus();
        setTimeout(() => {
          cursor.ch += text.length;
          codeMirrorInstance.setCursor(cursor);
        }, 0);
      }
    
    0 讨论(0)
提交回复
热议问题