Correctly identify pairs when cursor on pair

pull/368/head
Gokul Soumya 3 years ago committed by Blaž Hrastnik
parent b00e9fc227
commit 892c80771a

@ -39,8 +39,9 @@ pub fn find_nth_pairs_pos(
n: usize, n: usize,
) -> Option<(usize, usize)> { ) -> Option<(usize, usize)> {
let (open, close) = get_pair(ch); let (open, close) = get_pair(ch);
let open_pos = search::find_nth_prev(text, open, pos, n, true)?; // find_nth* do not consider current character; +1/-1 to include them
let close_pos = search::find_nth_next(text, close, pos, n, true)?; 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)) Some((open_pos, close_pos))
} }
@ -86,7 +87,7 @@ mod test {
// cursor on so[m]e // cursor on so[m]e
assert_eq!(find_nth_pairs_pos(slice, '(', 2, 1), None); assert_eq!(find_nth_pairs_pos(slice, '(', 2, 1), None);
// cursor on bracket itself // 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] #[test]
@ -134,10 +135,8 @@ mod test {
let doc = Rope::from("[some]\n(chars)xx\n(newline)"); let doc = Rope::from("[some]\n(chars)xx\n(newline)");
let slice = doc.slice(..); let slice = doc.slice(..);
let selection = Selection::new( let selection =
SmallVec::from_slice(&[Range::point(2), Range::point(9)]), Selection::new(SmallVec::from_slice(&[Range::point(2), Range::point(9)]), 0);
0,
);
// cursor on s[o]me, c[h]ars // cursor on s[o]me, c[h]ars
assert_eq!( assert_eq!(
@ -152,7 +151,7 @@ mod test {
// cursor on [x]x, newli[n]e // cursor on [x]x, newli[n]e
assert_eq!( assert_eq!(
get_surround_pos(slice, &selection, '(', 1), get_surround_pos(slice, &selection, '(', 1),
None // overlapping surround chars None // overlapping surround chars
); );
} }
} }

Loading…
Cancel
Save