From f76f44c8afa9663337ecb2fcbdee2bb0a4041e66 Mon Sep 17 00:00:00 2001 From: notoria Date: Fri, 4 Jun 2021 02:40:42 +0200 Subject: Convert byte index to char index for `find` --- helix-core/src/.match_brackets.rs.swp | Bin 0 -> 12288 bytes helix-core/src/match_brackets.rs | 8 +++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 helix-core/src/.match_brackets.rs.swp (limited to 'helix-core') diff --git a/helix-core/src/.match_brackets.rs.swp b/helix-core/src/.match_brackets.rs.swp new file mode 100644 index 00000000..ed35b90e Binary files /dev/null and b/helix-core/src/.match_brackets.rs.swp differ diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index 2d2eb4a9..38783c19 100644 --- a/helix-core/src/match_brackets.rs +++ b/helix-core/src/match_brackets.rs @@ -26,14 +26,16 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option { let start_byte = node.start_byte(); let end_byte = node.end_byte() - 1; // it's end exclusive + let start_char = doc.byte_to_char(start_byte); + let end_char = doc.byte_to_char(end_byte); - if PAIRS.contains(&(doc.char(start_byte), doc.char(end_byte))) { + if PAIRS.contains(&(doc.char(start_char), doc.char(end_char))) { if start_byte == byte_pos { - return Some(doc.byte_to_char(end_byte)); + return Some(end_char); } if end_byte == byte_pos { - return Some(doc.byte_to_char(start_byte)); + return Some(start_char); } } -- cgit v1.2.3-70-g09d2