From fa142d096761f64dfa9148b96b3296121d4c824b Mon Sep 17 00:00:00 2001 From: Hector Date: Fri, 17 Jan 2025 12:43:49 +0000 Subject: [PATCH 1/2] Refactor undo/redo methods for improved flexibility --- packages/quill/src/modules/history.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/quill/src/modules/history.ts b/packages/quill/src/modules/history.ts index 7bc5cdb689..fbb4a72620 100644 --- a/packages/quill/src/modules/history.ts +++ b/packages/quill/src/modules/history.ts @@ -1,7 +1,7 @@ import { Scope } from 'parchment'; import type Delta from 'quill-delta'; import Module from '../core/module.js'; -import Quill from '../core/quill.js'; +import Quill, { EmitterSource } from '../core/quill.js'; import type Scroll from '../blots/scroll.js'; import type { Range } from '../core/selection.js'; @@ -82,13 +82,13 @@ class History extends Module { }); } - change(source: 'undo' | 'redo', dest: 'redo' | 'undo') { - if (this.stack[source].length === 0) return; - const item = this.stack[source].pop(); + change(sourceStack: 'undo' | 'redo', destStack: 'redo' | 'undo', source: EmitterSource) { + if (this.stack[sourceStack].length === 0) return; + const item = this.stack[sourceStack].pop(); if (!item) return; const base = this.quill.getContents(); const inverseDelta = item.delta.invert(base); - this.stack[dest].push({ + this.stack[destStack].push({ delta: inverseDelta, range: transformRange(item.range, inverseDelta), }); @@ -135,8 +135,8 @@ class History extends Module { } } - redo() { - this.change('redo', 'undo'); + redo(source: EmitterSource = Quill.sources.USER) { + this.change('redo', 'undo', source); } transform(delta: Delta) { @@ -144,8 +144,8 @@ class History extends Module { transformStack(this.stack.redo, delta); } - undo() { - this.change('undo', 'redo'); + undo(source: EmitterSource = Quill.sources.USER) { + this.change('undo', 'redo', source); } protected restoreSelection(stackItem: StackItem) { From 64cc94b0ebead6a4ea363524effc10b3e4ff0233 Mon Sep 17 00:00:00 2001 From: Hector Date: Fri, 17 Jan 2025 12:59:19 +0000 Subject: [PATCH 2/2] Correctly implemented the source param in change --- packages/quill/src/modules/history.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/quill/src/modules/history.ts b/packages/quill/src/modules/history.ts index fbb4a72620..c74238dea0 100644 --- a/packages/quill/src/modules/history.ts +++ b/packages/quill/src/modules/history.ts @@ -94,7 +94,7 @@ class History extends Module { }); this.lastRecorded = 0; this.ignoreChange = true; - this.quill.updateContents(item.delta, Quill.sources.USER); + this.quill.updateContents(item.delta, source); this.ignoreChange = false; this.restoreSelection(item);