Skip to content

Commit b08ca13

Browse files
committed
Fix a bug that could cause partially reused decorations to become split
1 parent 48842d3 commit b08ca13

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/buildtile.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,10 @@ export class TileUpdate {
457457
this.builder.addLineStart(tile.attrs, this.cache.maybeReuse(tile))
458458
} else {
459459
this.cache.add(tile)
460-
if (tile instanceof MarkTile) activeMarks.unshift(tile.mark)
460+
if (tile instanceof MarkTile) {
461+
activeMarks.unshift(tile.mark)
462+
openMarks++
463+
}
461464
}
462465
this.openWidget = false
463466
},

test/webtest-draw-decoration.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {EditorView, Decoration, BlockWrapper, DecorationSet, WidgetType, ViewPlugin, BlockInfo, BlockType} from "@codemirror/view"
22
import {tempView, requireFocus} from "./tempview.js"
3-
import {EditorSelection, StateEffect, StateField, Range, RangeSet} from "@codemirror/state"
3+
import {EditorSelection, StateEffect, StateField, Range, RangeSet, Text} from "@codemirror/state"
44
import ist from "ist"
55

66
const filterDeco = StateEffect.define<(from: number, to: number, spec: any) => boolean>()
@@ -116,6 +116,19 @@ describe("EditorView decoration", () => {
116116
ist(cm.contentDOM.querySelectorAll(".a").length, 1)
117117
})
118118

119+
it("properly joins decorations when partially reusing them", () => {
120+
let mkDeco = (doc: Text) => {
121+
let deco: Range<Decoration>[] = []
122+
deco.push(Decoration.mark({class: "w"}).range(0, doc.length))
123+
for (let i = 0; i < doc.length - 1; i += 2)
124+
deco.push(Decoration.mark({class: "l"}).range(i, i + 1))
125+
return Decoration.set(deco)
126+
}
127+
let cm = tempView("Start", EditorView.decorations.of(v => mkDeco(v.state.doc)))
128+
cm.dispatch({changes: {from: 3, insert: "x"}})
129+
ist(cm.contentDOM.querySelectorAll(".w").length, 1)
130+
})
131+
119132
it("merges stacked decorations", () => {
120133
let cm = tempView("one", [
121134
decos(Decoration.set([], true)),

0 commit comments

Comments
 (0)