Skip to content

Commit 715b928

Browse files
committed
feedback: limit plain-text scanning to 10k characters at most, to avoid freezes
1 parent f5cb382 commit 715b928

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

helix-core/src/match_brackets.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use tree_sitter::Node;
22

33
use crate::{Rope, Syntax};
44

5+
const MAX_PLAINTEXT_SCAN: usize = 10000;
6+
7+
// Limit matching pairs to only ( ) { } [ ] < > ' ' " "
58
const PAIRS: &[(char, char)] = &[
69
('(', ')'),
710
('{', '}'),
@@ -11,8 +14,6 @@ const PAIRS: &[(char, char)] = &[
1114
('\"', '\"'),
1215
];
1316

14-
// limit matching pairs to only ( ) { } [ ] < > ' ' " "
15-
1617
/// Returns the position of the matching bracket under cursor.
1718
///
1819
/// If the cursor is on the opening bracket, the position of
@@ -104,7 +105,7 @@ pub fn find_matching_bracket_current_line_plaintext(
104105

105106
let mut open_cnt = 1;
106107

107-
for (i, candidate) in chars_iter.enumerate() {
108+
for (i, candidate) in chars_iter.take(MAX_PLAINTEXT_SCAN).enumerate() {
108109
if candidate == bracket {
109110
open_cnt += 1;
110111
} else if is_valid_pair(

0 commit comments

Comments
 (0)