diff --git a/crates/editor/src/highlight_matching_bracket.rs b/crates/editor/src/highlight_matching_bracket.rs index 778f5783e2..e38197283d 100644 --- a/crates/editor/src/highlight_matching_bracket.rs +++ b/crates/editor/src/highlight_matching_bracket.rs @@ -19,6 +19,11 @@ pub fn refresh_matching_bracket_highlights( let snapshot = editor.snapshot(window, cx); let head = newest_selection.head(); + if head > snapshot.buffer_snapshot.len() { + log::error!("bug: cursor offset is out of range while refreshing bracket highlights"); + return; + } + let mut tail = head; if (editor.cursor_shape == CursorShape::Block || editor.cursor_shape == CursorShape::Hollow) && head < snapshot.buffer_snapshot.len()