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

logic error in history module when transforming undo/redo against non-user changes #2105

Closed
rhysbrettbowen opened this issue May 8, 2018 · 1 comment

Comments

@rhysbrettbowen
Copy link

rhysbrettbowen commented May 8, 2018

When using history module, if an edit comes in not from the user it goes through the transform. There is an error in the logic where the change that comes in is directly applied to all undos/redos. Issue is that the state between these are different. What it needs to be transformed against is the change after it's been transformed against all previous undos.

Expected behavior:

function quillHistoryTransform(this: any, delta: DeltaStatic) {
  let stackedUndoDelta = delta;
  forEachRight(this.stack.undo, (change: any) => {
    const undo = change.undo;
    change.undo = stackedUndoDelta.transform(undo, true);
    stackedUndoDelta = undo.transform(stackedUndoDelta);
    change.redo = stackedUndoDelta.transform(change.redo, true);
  });
  let stackedRedoDelta = delta;
  forEachRight(this.stack.redo, (change: any) => {
    const redo = change.redo;
    change.redo = stackedUndoDelta.transform(redo, true);
    stackedRedoDelta = redo.transform(stackedRedoDelta);
    change.undo = stackedRedoDelta.transform(change.undo, true);
  });
}

Actual behavior:

    this.stack.undo.forEach(function(change) {
      change.undo = delta.transform(change.undo, true);
      change.redo = delta.transform(change.redo, true);
    });
    this.stack.redo.forEach(function(change) {
      change.undo = delta.transform(change.undo, true);
      change.redo = delta.transform(change.redo, true);
    });

Version:

1.3.6

@rhysbrettbowen
Copy link
Author

Written a test to show this - will make a PR to fix:

      this.quill.history.options.delay = 0;
      this.quill.history.options.userOnly = true;
      this.quill.setText('b\n');
      this.quill.insertText(1, 'd', Quill.sources.USER);
      this.quill.insertText(0, 'a', Quill.sources.USER);
      this.quill.insertText(2, 'c', Quill.sources.API);
      expect(this.quill.getText()).toEqual('abcd\n');
      this.quill.history.undo();
      expect(this.quill.getText()).toEqual('bcd\n');
      this.quill.history.undo();
      expect(this.quill.getText()).toEqual('bc\n');
      this.quill.history.redo();
      expect(this.quill.getText()).toEqual('bcd\n');
      this.quill.history.redo();
      expect(this.quill.getText()).toEqual('abcd\n');
    });```

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

Successfully merging a pull request may close this issue.

1 participant