on master help sign in
Convert byte index to char index for `find`
f76f44cnotoria
helix-core/src/.match_brackets.rs.swpnew file

Binary file not shown.

helix-core/src/match_brackets.rs+5−3
@@ -26,14 +26,16 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
26
26
27 let start_byte = node.start_byte();
27 let start_byte = node.start_byte();
28 let end_byte = node.end_byte() - 1; // it's end exclusive
28 let end_byte = node.end_byte() - 1; // it's end exclusive
29+ let start_char = doc.byte_to_char(start_byte);
30+ let end_char = doc.byte_to_char(end_byte);
29
31
30− if PAIRS.contains(&(doc.char(start_byte), doc.char(end_byte))) {
32+ if PAIRS.contains(&(doc.char(start_char), doc.char(end_char))) {
31 if start_byte == byte_pos {
33 if start_byte == byte_pos {
32− return Some(doc.byte_to_char(end_byte));
34+ return Some(end_char);
33 }
35 }
34
36
35 if end_byte == byte_pos {
37 if end_byte == byte_pos {
36− return Some(doc.byte_to_char(start_byte));
38+ return Some(start_char);
37 }
39 }
38 }
40 }
39
41