|
1 | 1 | import {EditorView, Decoration, BlockWrapper, DecorationSet, WidgetType, ViewPlugin, BlockInfo, BlockType} from "@codemirror/view" |
2 | 2 | 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" |
4 | 4 | import ist from "ist" |
5 | 5 |
|
6 | 6 | const filterDeco = StateEffect.define<(from: number, to: number, spec: any) => boolean>() |
@@ -116,6 +116,19 @@ describe("EditorView decoration", () => { |
116 | 116 | ist(cm.contentDOM.querySelectorAll(".a").length, 1) |
117 | 117 | }) |
118 | 118 |
|
| 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 | + |
119 | 132 | it("merges stacked decorations", () => { |
120 | 133 | let cm = tempView("one", [ |
121 | 134 | decos(Decoration.set([], true)), |
|
0 commit comments