Skip to content

Commit 64e7e8e

Browse files
committed
Pull count out of FindType
1 parent 1dcbdaa commit 64e7e8e

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

helix-core/src/surround.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ fn find_nth_closest_pairs_plain(
155155
}
156156

157157
pub enum FindType {
158-
Surround(usize),
159-
Next(usize),
160-
Prev(usize),
158+
Surround,
159+
Next,
160+
Prev,
161161
}
162162

163163
/// Find the position of surround pairs of `ch` which can be either a closing
@@ -168,6 +168,7 @@ pub fn find_nth_pairs_pos(
168168
ch: char,
169169
range: Range,
170170
find_type: FindType,
171+
n: usize,
171172
) -> Result<(usize, usize)> {
172173
if text.len_chars() < 2 {
173174
return Err(Error::PairNotFound);
@@ -179,12 +180,12 @@ pub fn find_nth_pairs_pos(
179180
let (open, close) = get_pair(ch);
180181
let pos = range.cursor(text);
181182
let (pos, n) = match find_type {
182-
FindType::Surround(n) => (pos, n),
183-
FindType::Next(n) => match search::find_nth_next(text, open, pos, n) {
183+
FindType::Surround => (pos, n),
184+
FindType::Next => match search::find_nth_next(text, open, pos, n) {
184185
Some(next_pos) => (next_pos + 1, 1),
185186
None => return Err(Error::PairNotFound),
186187
},
187-
FindType::Prev(n) => match search::find_nth_prev(text, close, pos, n) {
188+
FindType::Prev => match search::find_nth_prev(text, close, pos, n) {
188189
Some(next_pos) => (next_pos - 1, 1),
189190
None => return Err(Error::PairNotFound),
190191
},
@@ -315,7 +316,7 @@ pub fn get_surround_pos(
315316
for &range in selection {
316317
let (open_pos, close_pos) = {
317318
let range_raw = match ch {
318-
Some(ch) => find_nth_pairs_pos(text, ch, range, FindType::Surround(skip))?,
319+
Some(ch) => find_nth_pairs_pos(text, ch, range, FindType::Surround, skip)?,
319320
None => find_nth_closest_pairs_pos(syntax, text, range, skip)?,
320321
};
321322
let range = Range::new(range_raw.0, range_raw.1);
@@ -413,7 +414,8 @@ mod test {
413414
doc.slice(..),
414415
'\'',
415416
selection.primary(),
416-
FindType::Surround(1)
417+
FindType::Surround,
418+
1
417419
)
418420
.expect("find should succeed"),
419421
(expectations[0], expectations[1])
@@ -435,7 +437,8 @@ mod test {
435437
doc.slice(..),
436438
'\'',
437439
selection.primary(),
438-
FindType::Surround(2)
440+
FindType::Surround,
441+
2
439442
)
440443
.expect("find should succeed"),
441444
(expectations[0], expectations[1])
@@ -453,7 +456,7 @@ mod test {
453456

454457
assert_eq!(2, expectations.len());
455458
assert_eq!(
456-
find_nth_pairs_pos(doc.slice(..), '\'', selection.primary(), FindType::Next(3))
459+
find_nth_pairs_pos(doc.slice(..), '\'', selection.primary(), FindType::Next, 3)
457460
.expect("find should succeed"),
458461
(expectations[0], expectations[1])
459462
)
@@ -470,7 +473,7 @@ mod test {
470473

471474
assert_eq!(2, expectations.len());
472475
assert_eq!(
473-
find_nth_pairs_pos(doc.slice(..), '\'', selection.primary(), FindType::Prev(1))
476+
find_nth_pairs_pos(doc.slice(..), '\'', selection.primary(), FindType::Prev, 1)
474477
.expect("find should succeed"),
475478
(expectations[0], expectations[1])
476479
)
@@ -490,7 +493,8 @@ mod test {
490493
doc.slice(..),
491494
'\'',
492495
selection.primary(),
493-
FindType::Surround(1)
496+
FindType::Surround,
497+
1
494498
),
495499
Err(Error::CursorOnAmbiguousPair)
496500
)

helix-core/src/textobject.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,14 @@ pub fn textobject_pair_surround(
206206
textobject: TextObject,
207207
ch: char,
208208
find_type: FindType,
209+
count: usize,
209210
) -> Range {
210211
textobject_pair_surround_impl(
211212
syntax,
212213
slice,
213214
range,
214215
textobject,
215-
FindVariant::Char((ch, find_type)),
216+
FindVariant::Char((ch, find_type, count)),
216217
)
217218
}
218219

@@ -233,7 +234,7 @@ pub fn textobject_pair_surround_closest(
233234
}
234235

235236
enum FindVariant {
236-
Char((char, FindType)),
237+
Char((char, FindType, usize)),
237238
Closest(usize),
238239
}
239240

@@ -245,8 +246,8 @@ fn textobject_pair_surround_impl(
245246
find_variant: FindVariant,
246247
) -> Range {
247248
let pair_pos = match find_variant {
248-
FindVariant::Char((ch, find_type)) => {
249-
surround::find_nth_pairs_pos(slice, ch, range, find_type)
249+
FindVariant::Char((ch, find_type, count)) => {
250+
surround::find_nth_pairs_pos(slice, ch, range, find_type, count)
250251
}
251252
FindVariant::Closest(count) => {
252253
surround::find_nth_closest_pairs_pos(syntax, slice, range, count)
@@ -603,7 +604,8 @@ mod test {
603604
Range::point(pos),
604605
objtype,
605606
ch,
606-
FindType::Surround(count),
607+
FindType::Surround,
608+
count,
607609
);
608610
assert_eq!(
609611
result,

helix-term/src/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6055,9 +6055,9 @@ fn textobject_surrounding_pair(
60556055
None => FindType::Surround,
60566056
Some(Direction::Forward) => FindType::Next,
60576057
Some(Direction::Backward) => FindType::Prev,
6058-
}(count);
6058+
};
60596059
let mut range = textobject::textobject_pair_surround(
6060-
syntax, text, range, textobject, pair_char, find_type,
6060+
syntax, text, range, textobject, pair_char, find_type, count,
60616061
);
60626062
if let Some(direction) = direction {
60636063
range = range.with_direction(direction);

0 commit comments

Comments
 (0)