Inserting a new text at given cursor position

后端 未结 7 2193
夕颜
夕颜 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 18:51

    You want to use the replaceRange function. Even though the name says "replace", it also serves as "insert" depending on the arguments. From the documentation at the time I write this:

    Replace the part of the document between from and to with the given string. from and to must be {line, ch} objects. to can be left off to simply insert the string at position from. When origin is given, it will be passed on to "change" events, and its first letter will be used to determine whether this change can be merged with previous history events, in the way described for selection origins.

提交回复
热议问题