yuku / textcomplete

Autocomplete for HTMLTextAreaElement and more.
https://yuku.takahashi.coffee/textcomplete/
MIT License
1.74k stars 303 forks source link

Using replaceRange instead of setValue in CodeMirror #346

Closed phigasui closed 3 years ago

phigasui commented 3 years ago

When executing completion on CodeMirror, full-text are replaced because the contents are updated using CodeMirror#setValue. We want to use CodeMirror#replaceRange so that we only need to update the required range.

When referring to change event, it will cause unnecessarily large change events. This can be a problem if you need to create changelogs or send changes for simultaneous editing, for example.

Here are some suggestions I'm currently considering for that purpose.

  1. Add information to the return value of SearchResult#replace that includes the replace range and the text after replacement.
    • Use the values in @textcomplete/codemirror to replace the required range.
  2. Make the return value of SearchResult#replace only the range of the replacement and the text after the replacement, and adjust it in each packages that are the caller.