Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit 371c9ba

Browse files
committed
Fix bogus bracket highlighting being generated at end of document
FIX: Fix a crash in `bracketMatching` when composing at end of document. Closes codemirror/dev#1687
1 parent 9531899 commit 371c9ba

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/matchbrackets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ function matchMarkedBrackets(_state: EditorState, _pos: number, dir: -1 | 1, tok
187187

188188
function matchPlainBrackets(state: EditorState, pos: number, dir: number, tree: Tree,
189189
tokenType: NodeType, maxScanDistance: number, brackets: string) {
190+
if (dir < 0 ? !pos : pos == state.doc.length) return null
190191
let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1)
191192
let bracket = brackets.indexOf(startCh)
192193
if (bracket < 0 || (bracket % 2 == 0) != (dir > 0)) return null

0 commit comments

Comments
 (0)