Skip to content

Commit

Permalink
Fix bug in viewport tracking for edit contexts
Browse files Browse the repository at this point in the history
FIX: Fix a bug where EditContext-based editing could corrupt the document
in some situations.

Issue codemirror/dev#1396
  • Loading branch information
marijnh committed Jul 3, 2024
1 parent 6dcaa68 commit 1f939c0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/domobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f939c0

Please sign in to comment.