mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-28 12:42:09 +03:00
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>
This commit is contained in:
parent
254d558907
commit
7711db3a3a
@ -198,26 +198,26 @@ pub fn textobject_paragraph(
|
|||||||
Range::new(anchor, head)
|
Range::new(anchor, head)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn textobject_surround(
|
pub fn textobject_pair_surround(
|
||||||
slice: RopeSlice,
|
slice: RopeSlice,
|
||||||
range: Range,
|
range: Range,
|
||||||
textobject: TextObject,
|
textobject: TextObject,
|
||||||
ch: char,
|
ch: char,
|
||||||
count: usize,
|
count: usize,
|
||||||
) -> Range {
|
) -> Range {
|
||||||
textobject_surround_impl(slice, range, textobject, Some(ch), count)
|
textobject_pair_surround_impl(slice, range, textobject, Some(ch), count)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn textobject_surround_closest(
|
pub fn textobject_pair_surround_closest(
|
||||||
slice: RopeSlice,
|
slice: RopeSlice,
|
||||||
range: Range,
|
range: Range,
|
||||||
textobject: TextObject,
|
textobject: TextObject,
|
||||||
count: usize,
|
count: usize,
|
||||||
) -> Range {
|
) -> Range {
|
||||||
textobject_surround_impl(slice, range, textobject, None, count)
|
textobject_pair_surround_impl(slice, range, textobject, None, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn textobject_surround_impl(
|
fn textobject_pair_surround_impl(
|
||||||
slice: RopeSlice,
|
slice: RopeSlice,
|
||||||
range: Range,
|
range: Range,
|
||||||
textobject: TextObject,
|
textobject: TextObject,
|
||||||
@ -562,7 +562,7 @@ mod test {
|
|||||||
let slice = doc.slice(..);
|
let slice = doc.slice(..);
|
||||||
for &case in scenario {
|
for &case in scenario {
|
||||||
let (pos, objtype, expected_range, ch, count) = case;
|
let (pos, objtype, expected_range, ch, count) = case;
|
||||||
let result = textobject_surround(slice, Range::point(pos), objtype, ch, count);
|
let result = textobject_pair_surround(slice, Range::point(pos), objtype, ch, count);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
expected_range.into(),
|
expected_range.into(),
|
||||||
|
@ -4332,10 +4332,12 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
|||||||
'o' => textobject_treesitter("comment", range),
|
'o' => textobject_treesitter("comment", range),
|
||||||
't' => textobject_treesitter("test", range),
|
't' => textobject_treesitter("test", range),
|
||||||
'p' => textobject::textobject_paragraph(text, range, objtype, count),
|
'p' => textobject::textobject_paragraph(text, range, objtype, count),
|
||||||
'm' => textobject::textobject_surround_closest(text, range, objtype, count),
|
'm' => textobject::textobject_pair_surround_closest(
|
||||||
|
text, range, objtype, count,
|
||||||
|
),
|
||||||
// TODO: cancel new ranges if inconsistent surround matches across lines
|
// TODO: cancel new ranges if inconsistent surround matches across lines
|
||||||
ch if !ch.is_ascii_alphanumeric() => {
|
ch if !ch.is_ascii_alphanumeric() => {
|
||||||
textobject::textobject_surround(text, range, objtype, ch, count)
|
textobject::textobject_pair_surround(text, range, objtype, ch, count)
|
||||||
}
|
}
|
||||||
_ => range,
|
_ => range,
|
||||||
}
|
}
|
||||||
@ -4361,7 +4363,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
|||||||
("a", "Argument/parameter (tree-sitter)"),
|
("a", "Argument/parameter (tree-sitter)"),
|
||||||
("o", "Comment (tree-sitter)"),
|
("o", "Comment (tree-sitter)"),
|
||||||
("t", "Test (tree-sitter)"),
|
("t", "Test (tree-sitter)"),
|
||||||
("m", "Matching delimiter under cursor"),
|
("m", "Closest surrounding pair to cursor"),
|
||||||
(" ", "... or any character acting as a pair"),
|
(" ", "... or any character acting as a pair"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user