on master help sign in
Adjust `m` textobject description and minor code clarification (#3343)

* Update description of `m` textobject to its actual functionality Sometime recently the functionality of `m` was changed to match the nearest pair to the cursor, rather than the former functionality of matching the pair only if the cursor was on one of the brace characters directly. * Rename surround methods to reflect that they work on pairs The current naming suggests that they may work generally on any textobject, whereas their implementation really focuses on pairs. * Change description of m textobject to match actual functionality The current implementation of `m` no longer merely looks at the pair character the cursor is on, but actually will search for the pair (defined in helix-core/src/surround.rs) that encloses the cursor, and not the entire selection. * Accept suggested wording change Co-authored-by: Michael Davis <mcarsondavis@gmail.com> * Prefix pair surround for consistency Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commit7711db3a3af8f7ca156c8c71ae4b7ea2dd02d96f authorDaniel S Poulin <dan.poulin@digitalsurgeons.com> dateTue 16 Aug 2022, 21:41 (4 years ago) parent254d558
2 files changed+11−9
helix-core/src/textobject.rs+6−6 helix-term/src/commands.rs+5−3
helix-core/src/textobject.rs+6−6
@@ -198,26 +198,26 @@ pub fn textobject_paragraph(
198198 Range::new(anchor, head)
199199}
200200
201−pub fn textobject_surround(
201+pub fn textobject_pair_surround(
202202 slice: RopeSlice,
203203 range: Range,
204204 textobject: TextObject,
205205 ch: char,
206206 count: usize,
207207) -> Range {
208− textobject_surround_impl(slice, range, textobject, Some(ch), count)
208+ textobject_pair_surround_impl(slice, range, textobject, Some(ch), count)
209209}
210210
211−pub fn textobject_surround_closest(
211+pub fn textobject_pair_surround_closest(
212212 slice: RopeSlice,
213213 range: Range,
214214 textobject: TextObject,
215215 count: usize,
216216) -> Range {
217− textobject_surround_impl(slice, range, textobject, None, count)
217+ textobject_pair_surround_impl(slice, range, textobject, None, count)
218218}
219219
220−fn textobject_surround_impl(
220+fn textobject_pair_surround_impl(
221221 slice: RopeSlice,
222222 range: Range,
223223 textobject: TextObject,
@@ -562,7 +562,7 @@ mod test {
562562 let slice = doc.slice(..);
563563 for &case in scenario {
564564 let (pos, objtype, expected_range, ch, count) = case;
565− let result = textobject_surround(slice, Range::point(pos), objtype, ch, count);
565+ let result = textobject_pair_surround(slice, Range::point(pos), objtype, ch, count);
566566 assert_eq!(
567567 result,
568568 expected_range.into(),
helix-term/src/commands.rs+5−3
@@ -4332,10 +4332,12 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
43324332 'o' => textobject_treesitter("comment", range),
43334333 't' => textobject_treesitter("test", range),
43344334 'p' => textobject::textobject_paragraph(text, range, objtype, count),
4335− 'm' => textobject::textobject_surround_closest(text, range, objtype, count),
4335+ 'm' => textobject::textobject_pair_surround_closest(
4336+ text, range, objtype, count,
4337+ ),
43364338 // TODO: cancel new ranges if inconsistent surround matches across lines
43374339 ch if !ch.is_ascii_alphanumeric() => {
4338− textobject::textobject_surround(text, range, objtype, ch, count)
4340+ textobject::textobject_pair_surround(text, range, objtype, ch, count)
43394341 }
43404342 _ => range,
43414343 }
@@ -4361,7 +4363,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
43614363 ("a", "Argument/parameter (tree-sitter)"),
43624364 ("o", "Comment (tree-sitter)"),
43634365 ("t", "Test (tree-sitter)"),
4364− ("m", "Matching delimiter under cursor"),
4366+ ("m", "Closest surrounding pair to cursor"),
43654367 (" ", "... or any character acting as a pair"),
43664368 ];
43674369