Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setContent function alway remove last new line in insert delta #3025

Closed
Kisama opened this issue Apr 26, 2020 · 2 comments
Closed

setContent function alway remove last new line in insert delta #3025

Kisama opened this issue Apr 26, 2020 · 2 comments

Comments

@Kisama
Copy link

Kisama commented Apr 26, 2020

When I input new line into last of content and add to quill, quill automatically remove last new line

I found setContent function in quill.js alway remove last "\n"

It is add commit id f64a8f2 for fix #1065

I can't understand why quill always last new line?
Is there any one know why quill remove last new line?

@Kisama
Copy link
Author

Kisama commented Jun 1, 2020

when lastOp is newline, setContents remove lastOp.
anyone know why quill remove lastOp? It looks like weird

  setContents(delta, source = Emitter.sources.API) {
    return modify.call(this, () => {
      delta = new Delta(delta);
      let length = this.getLength();
      let deleted = this.editor.deleteText(0, length);
      let applied = this.editor.applyDelta(delta);
      let lastOp = applied.ops[applied.ops.length - 1];
      if (lastOp != null && typeof(lastOp.insert) === 'string' && lastOp.insert[lastOp.insert.length-1] === '\n') {
        this.editor.deleteText(this.getLength() - 1, 1);
        applied.delete(1);
      }
      let ret = deleted.compose(applied);
      return ret;
    }, source);
  }

@quill-bot
Copy link

Quill 2.0 has been released (announcement post) with many changes and fixes. If this is still an issue please create a new issue after reviewing our updated Contributing guide 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants