From 1f939c00d31a499b3619f2b0d534ffa42cf2e3fc Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 3 Jul 2024 16:17:53 +0200 Subject: [PATCH] Fix bug in viewport tracking for edit contexts FIX: Fix a bug where EditContext-based editing could corrupt the document in some situations. Issue https://github.com/codemirror/dev/issues/1396 --- src/domobserver.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/domobserver.ts b/src/domobserver.ts index baa98ad..fc0341f 100644 --- a/src/domobserver.ts +++ b/src/domobserver.ts @@ -549,7 +549,7 @@ class EditContextManager { if (change.from == this.from && anchor < this.from) change.from = anchor else if (change.to == this.to && anchor > this.to) change.to = anchor - // Edit context sometimes fire empty changes + // Edit contexts sometimes fire empty changes if (change.from == change.to && !change.insert.length) return this.pendingContextChange = change @@ -612,6 +612,7 @@ class EditContextManager { if (pending.from == fromA && pending.to == toA && pending.insert.eq(insert)) { pending = this.pendingContextChange = null // Match off += dLen + this.to += dLen return } else { // Mismatch, revert pending = null