Skip to content

Commit e4f445c

Browse files
committed
Fix a bug in incremental changed chunk updates
FIX: Fix a bug where big deletions could corrupt the merge state. Closes codemirror/dev#1326
1 parent 8121e74 commit e4f445c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/chunk.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ function updateChunks(ranges: readonly UpdateRange[], chunks: readonly Chunk[],
154154
result.push(chunk)
155155
offA += range.diffA
156156
offB += range.diffB
157+
while (chunkI < chunks.length) {
158+
let next = chunks[chunkI]
159+
if (next.fromA > toA + offA && next.fromB > toB + offB) break
160+
chunkI++
161+
}
157162
}
158163
while (chunkI < chunks.length)
159164
result.push(chunks[chunkI++].offset(offA, offB))

test/test-chunk.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ describe("chunks", () => {
7777
let tr = sA.update({changes: {from: 0, insert: sB.doc}})
7878
ist(Chunk.updateA(chs, tr.newDoc, sB.doc, tr.changes).length, 0)
7979
})
80+
81+
it("drops old chunks when a doc is cleared", () => {
82+
let sA = EditorState.create({doc: "A\nb\nC\nd\nE"}), sB = EditorState.create({doc: "a\nb\nc\nd\ne"})
83+
let chs = Chunk.build(sA.doc, sB.doc)
84+
let tr = sA.update({changes: {from: 0, to: sA.doc.length}})
85+
let updated = Chunk.updateA(chs, tr.newDoc, sB.doc, tr.changes)
86+
ist(updated.length, 1)
87+
ist(updated[0].toB, sB.doc.length + 1)
88+
})
8089
})

0 commit comments

Comments
 (0)