aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorGokul Soumya2021-06-22 03:47:44 +0000
committerBlaž Hrastnik2021-06-22 05:27:51 +0000
commit892c80771a4cbad79fcec89c0af8735c81c336e8 (patch)
treef7f03a0bda852309de3b254fa55c38f61cb1b2dc /helix-core/src
parentb00e9fc227dc2ab1070326f29fbe9626702dfa67 (diff)
Correctly identify pairs when cursor on pair
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/surround.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs
index a2703302..d7314609 100644
--- a/helix-core/src/surround.rs
+++ b/helix-core/src/surround.rs
@@ -39,8 +39,9 @@ pub fn find_nth_pairs_pos(
n: usize,
) -> Option<(usize, usize)> {
let (open, close) = get_pair(ch);
- let open_pos = search::find_nth_prev(text, open, pos, n, true)?;
- let close_pos = search::find_nth_next(text, close, pos, n, true)?;
+ // find_nth* do not consider current character; +1/-1 to include them
+ let open_pos = search::find_nth_prev(text, open, pos + 1, n, true)?;
+ let close_pos = search::find_nth_next(text, close, pos - 1, n, true)?;
Some((open_pos, close_pos))
}
@@ -86,7 +87,7 @@ mod test {
// cursor on so[m]e
assert_eq!(find_nth_pairs_pos(slice, '(', 2, 1), None);
// cursor on bracket itself
- // assert_eq!(find_nth_pairs_pos(slice, '(', 5, 1), Some((5, 10)));
+ assert_eq!(find_nth_pairs_pos(slice, '(', 5, 1), Some((5, 10)));
}
#[test]
@@ -134,10 +135,8 @@ mod test {
let doc = Rope::from("[some]\n(chars)xx\n(newline)");
let slice = doc.slice(..);
- let selection = Selection::new(
- SmallVec::from_slice(&[Range::point(2), Range::point(9)]),
- 0,
- );
+ let selection =
+ Selection::new(SmallVec::from_slice(&[Range::point(2), Range::point(9)]), 0);
// cursor on s[o]me, c[h]ars
assert_eq!(
@@ -152,7 +151,7 @@ mod test {
// cursor on [x]x, newli[n]e
assert_eq!(
get_surround_pos(slice, &selection, '(', 1),
- None // overlapping surround chars
+ None // overlapping surround chars
);
}
}