aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authornotoria2021-06-04 00:40:42 +0000
committerBlaž Hrastnik2021-06-04 01:00:22 +0000
commitf76f44c8afa9663337ecb2fcbdee2bb0a4041e66 (patch)
tree264d74ac7012da69eaf5e78ff14911f7928d9145 /helix-core
parentd55419604c7fa3d3b0559cf985760170a3866d87 (diff)
Convert byte index to char index for `find`
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/.match_brackets.rs.swpbin0 -> 12288 bytes
-rw-r--r--helix-core/src/match_brackets.rs8
2 files changed, 5 insertions, 3 deletions
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
--- /dev/null
+++ b/helix-core/src/.match_brackets.rs.swp
Binary files 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<usize> {
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);
}
}