Skip to content

Commit

Permalink
Pass source for history actions (slab#3514)
Browse files Browse the repository at this point in the history
* Pass source for history actions

Since undo, redo emitted by user the source should USER.

* Add tests for history.undo()/redo()

---------

Co-authored-by: Zihua Li <i@zihua.li>
  • Loading branch information
kalys and luin committed Aug 7, 2023
1 parent 042c8ef commit e2113db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class History extends Module<HistoryOptions> {
this.quill.updateContents(delta, Quill.sources.USER);
this.ignoreChange = false;
const index = getLastChangeIndex(this.quill.scroll, delta);
this.quill.setSelection(index);
this.quill.setSelection(index, Quill.sources.USER);
}

clear() {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/modules/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ describe('History', function () {
expect(quill.history.stack.undo.length).toEqual(2);
});

it('emits selection changes', function () {
const quill = new Quill(this.container.firstChild, {
modules: {
history: { delay: 0 },
},
});
quill.insertText(0, 'foo');
const change = jasmine.createSpy('change');
quill.on('selection-change', change);
quill.history.undo();

expect(change).toHaveBeenCalledOnceWith(jasmine.anything(), null, 'user');
});

it('user change', function () {
this.quill.root.firstChild.innerHTML = 'The lazy foxes';
this.quill.update();
Expand Down

0 comments on commit e2113db

Please sign in to comment.