From 7bcfcfd143e7a60fadfaa936610b22e8a236a6d5 Mon Sep 17 00:00:00 2001 From: Kalys Osmonov Date: Wed, 5 Jul 2023 07:43:45 +0600 Subject: [PATCH] Pass source for history actions (#3514) * 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 --- modules/history.ts | 2 +- test/unit/modules/history.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/history.ts b/modules/history.ts index cccadb07ec..72a52bd030 100644 --- a/modules/history.ts +++ b/modules/history.ts @@ -74,7 +74,7 @@ class History extends Module { 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() { diff --git a/test/unit/modules/history.js b/test/unit/modules/history.js index 11e9d676de..d961c823c4 100644 --- a/test/unit/modules/history.js +++ b/test/unit/modules/history.js @@ -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();