Skip to content

Commit e2f9d98

Browse files
committed
fix: editor should no longer crash when highlightlines are unsorted
1 parent 3630d3d commit e2f9d98

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/codemirror/extensions/highlightLineExtension.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ export const lineHighlightField = StateField.define({
4747
const highlights = value
4848
.filter((line) => line <= lines) // one-indexed
4949
.map((line) => lineHighlightMark.range(state.doc.line(line).from))
50-
return Decoration.none.update({
51-
add: highlights,
52-
})
50+
highlights.sort((a, b) => a.from - b.from)
51+
try {
52+
return Decoration.none.update({
53+
add: highlights,
54+
})
55+
} catch (e) {
56+
console.error(e)
57+
return Decoration.none
58+
}
5359
},
5460
provide: (f) => EditorView.decorations.from(f),
5561
})

0 commit comments

Comments
 (0)