mindroute / quill-autoformat

Module for formatting and transforming text as you type in Quill
MIT License
68 stars 10 forks source link

enter with a cursor between the characters, all the characters after the cursor are selected #7

Open HadesSik opened 1 year ago

HadesSik commented 1 year ago

Kapture 2022-12-07 at 12 10 14

I solved it with the code below

src/modules/autoFormat.js in this.quill.on(Quill.events.TEXT_CHANGE)

if(transformed) {
    setTimeout(() => {
    this.quill.setSelection(this.quill.getLength() - endSelIndex, 'api')
  }, 0);
}

to

if (transformed) {
  const from = this.quill.getLength() - endSelIndex;
  const to = endSelIndex;
  if (isEnter) {
    setTimeout(() => {
      this.quill.setSelection(from, 0, "api");
    }, 0);
  } else {
    setTimeout(() => {
      this.quill.setSelection(from, to, "api");
    }, 0);
  }
}