@@ -1,4 +1,3 @@
1−use crate::graphemes::next_grapheme_boundary;
2use crate::{search, Selection};
1use crate::{search, Selection};
3use ropey::RopeSlice;
2use ropey::RopeSlice;
@@ -49,9 +48,9 @@ pub fn find_nth_pairs_pos(
49 if Some(open) == text.get_char(pos) {
48 if Some(open) == text.get_char(pos) {
50 // Special case: cursor is directly on a matching char.
49 // Special case: cursor is directly on a matching char.
51 match pos {
50 match pos {
52− 0 => Some((pos, search::find_nth_next(text, close, pos + 1, n)? + 1)),
51+ 0 => Some((pos, search::find_nth_next(text, close, pos + 1, n)?)),
53 _ if (pos + 1) == text.len_chars() => {
52 _ if (pos + 1) == text.len_chars() => {
54− Some((search::find_nth_prev(text, open, pos, n)?, text.len_chars()))
53+ Some((search::find_nth_prev(text, open, pos, n)?, pos))
56 // We return no match because there's no way to know which
55 // We return no match because there's no way to know which
57 // side of the char we should be searching on.
56 // side of the char we should be searching on.
@@ -60,13 +59,13 @@ pub fn find_nth_pairs_pos(
62 search::find_nth_prev(text, open, pos, n)?,
61 search::find_nth_prev(text, open, pos, n)?,
63− search::find_nth_next(text, close, pos, n)? + 1,
62+ search::find_nth_next(text, close, pos, n)?,
68 find_nth_open_pair(text, open, close, pos, n)?,
67 find_nth_open_pair(text, open, close, pos, n)?,
69− next_grapheme_boundary(text, find_nth_close_pair(text, open, close, pos, n)?),
68+ find_nth_close_pair(text, open, close, pos, n)?,
@@ -185,13 +184,13 @@ mod test {
185 let slice = doc.slice(..);
184 let slice = doc.slice(..);
187 // cursor on [t]ext
186 // cursor on [t]ext
188− assert_eq!(find_nth_pairs_pos(slice, '(', 6, 1), Some((5, 11)));
187+ assert_eq!(find_nth_pairs_pos(slice, '(', 6, 1), Some((5, 10)));
189− assert_eq!(find_nth_pairs_pos(slice, ')', 6, 1), Some((5, 11)));
188+ assert_eq!(find_nth_pairs_pos(slice, ')', 6, 1), Some((5, 10)));
190 // cursor on so[m]e
189 // cursor on so[m]e
191 assert_eq!(find_nth_pairs_pos(slice, '(', 2, 1), None);
190 assert_eq!(find_nth_pairs_pos(slice, '(', 2, 1), None);
192 // cursor on bracket itself
191 // cursor on bracket itself
193− assert_eq!(find_nth_pairs_pos(slice, '(', 5, 1), Some((5, 11)));
192+ assert_eq!(find_nth_pairs_pos(slice, '(', 5, 1), Some((5, 10)));
194− assert_eq!(find_nth_pairs_pos(slice, '(', 10, 1), Some((5, 11)));
193+ assert_eq!(find_nth_pairs_pos(slice, '(', 10, 1), Some((5, 10)));
@@ -200,9 +199,9 @@ mod test {
200 let slice = doc.slice(..);
199 let slice = doc.slice(..);
202 // cursor on go[o]d
201 // cursor on go[o]d
203− assert_eq!(find_nth_pairs_pos(slice, '(', 13, 1), Some((10, 16)));
202+ assert_eq!(find_nth_pairs_pos(slice, '(', 13, 1), Some((10, 15)));
204− assert_eq!(find_nth_pairs_pos(slice, '(', 13, 2), Some((4, 22)));
203+ assert_eq!(find_nth_pairs_pos(slice, '(', 13, 2), Some((4, 21)));
205− assert_eq!(find_nth_pairs_pos(slice, '(', 13, 3), Some((0, 28)));
204+ assert_eq!(find_nth_pairs_pos(slice, '(', 13, 3), Some((0, 27)));
@@ -211,14 +210,14 @@ mod test {
211 let slice = doc.slice(..);
210 let slice = doc.slice(..);
213 // cursor on go[o]d
212 // cursor on go[o]d
214− assert_eq!(find_nth_pairs_pos(slice, '\'', 13, 1), Some((10, 16)));
213+ assert_eq!(find_nth_pairs_pos(slice, '\'', 13, 1), Some((10, 15)));
215− assert_eq!(find_nth_pairs_pos(slice, '\'', 13, 2), Some((4, 22)));
214+ assert_eq!(find_nth_pairs_pos(slice, '\'', 13, 2), Some((4, 21)));
216− assert_eq!(find_nth_pairs_pos(slice, '\'', 13, 3), Some((0, 28)));
215+ assert_eq!(find_nth_pairs_pos(slice, '\'', 13, 3), Some((0, 27)));
217 // cursor on the quotes
216 // cursor on the quotes
218 assert_eq!(find_nth_pairs_pos(slice, '\'', 10, 1), None);
217 assert_eq!(find_nth_pairs_pos(slice, '\'', 10, 1), None);
219 // this is the best we can do since opening and closing pairs are same
218 // this is the best we can do since opening and closing pairs are same
220− assert_eq!(find_nth_pairs_pos(slice, '\'', 0, 1), Some((0, 5)));
219+ assert_eq!(find_nth_pairs_pos(slice, '\'', 0, 1), Some((0, 4)));
221− assert_eq!(find_nth_pairs_pos(slice, '\'', 27, 1), Some((21, 28)));
220+ assert_eq!(find_nth_pairs_pos(slice, '\'', 27, 1), Some((21, 27)));
@@ -227,8 +226,8 @@ mod test {
227 let slice = doc.slice(..);
226 let slice = doc.slice(..);
229 // cursor on go[o]d
228 // cursor on go[o]d
230− assert_eq!(find_nth_pairs_pos(slice, '(', 15, 1), Some((5, 25)));
229+ assert_eq!(find_nth_pairs_pos(slice, '(', 15, 1), Some((5, 24)));
231− assert_eq!(find_nth_pairs_pos(slice, '(', 15, 2), Some((0, 32)));
230+ assert_eq!(find_nth_pairs_pos(slice, '(', 15, 2), Some((0, 31)));
@@ -237,9 +236,9 @@ mod test {
237 let slice = doc.slice(..);
236 let slice = doc.slice(..);
239 // cursor on go[o]d
238 // cursor on go[o]d
240− assert_eq!(find_nth_pairs_pos(slice, '{', 13, 1), Some((10, 16)));
239+ assert_eq!(find_nth_pairs_pos(slice, '{', 13, 1), Some((10, 15)));
241− assert_eq!(find_nth_pairs_pos(slice, '[', 13, 1), Some((4, 22)));
240+ assert_eq!(find_nth_pairs_pos(slice, '[', 13, 1), Some((4, 21)));
242− assert_eq!(find_nth_pairs_pos(slice, '(', 13, 1), Some((0, 28)));
241+ assert_eq!(find_nth_pairs_pos(slice, '(', 13, 1), Some((0, 27)));
@@ -256,7 +255,7 @@ mod test {
256 get_surround_pos(slice, &selection, '(', 1)
255 get_surround_pos(slice, &selection, '(', 1)
257 .unwrap()
256 .unwrap()
258 .as_slice(),
257 .as_slice(),
259− &[0, 6, 7, 14, 15, 24]
258+ &[0, 5, 7, 13, 15, 23]