aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorPascal Kuthe2024-01-13 23:00:31 +0000
committerBlaž Hrastnik2024-01-15 06:32:07 +0000
commit2fb7e50b549842999639434dc433f22928678082 (patch)
tree7d57987c532a91f1e689920f7ae39687387bec99 /helix-core
parent3f88a3f4e6f75bf04246a8015652931e640e0821 (diff)
don't crash in plaintext bracket match (mm) on empty file
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/match_brackets.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs
index f6d9885e..e49b408a 100644
--- a/helix-core/src/match_brackets.rs
+++ b/helix-core/src/match_brackets.rs
@@ -141,7 +141,7 @@ fn find_pair(
#[must_use]
pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Option<usize> {
// Don't do anything when the cursor is not on top of a bracket.
- let bracket = doc.char(cursor_pos);
+ let bracket = doc.get_char(cursor_pos)?;
if !is_valid_bracket(bracket) {
return None;
}
@@ -266,6 +266,12 @@ mod tests {
use super::*;
#[test]
+ fn find_matching_bracket_empty_file() {
+ let actual = find_matching_bracket_plaintext("".into(), 0);
+ assert_eq!(actual, None);
+ }
+
+ #[test]
fn test_find_matching_bracket_current_line_plaintext() {
let assert = |input: &str, pos, expected| {
let input = RopeSlice::from(input);