vim: Add textobject e for entire file (#24039)

Co-Authored-By: Thomas Heartman <zed@thomasheartman.com>

Release Notes:

- vim: Add `e` for entire file object. `yae` to copy entire file

Co-authored-by: Thomas Heartman <zed@thomasheartman.com>
This commit is contained in:
Conrad Irwin 2025-01-31 21:38:19 -07:00 committed by GitHub
parent 66e2028313
commit a3c7dc3321
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View file

@ -421,7 +421,8 @@
"i": "vim::IndentObj",
"shift-i": ["vim::IndentObj", { "includeBelow": true }],
"f": "vim::Method",
"c": "vim::Class"
"c": "vim::Class",
"e": "vim::EntireFile"
}
},
{

View file

@ -40,6 +40,7 @@ pub enum Object {
Method,
Class,
Comment,
EntireFile,
}
#[derive(Clone, Deserialize, JsonSchema, PartialEq)]
@ -83,7 +84,8 @@ actions!(
Tag,
Method,
Class,
Comment
Comment,
EntireFile
]
);
@ -150,6 +152,9 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, _: &Class, window, cx| {
vim.object(Object::Class, window, cx)
});
Vim::action(editor, cx, |vim, _: &EntireFile, window, cx| {
vim.object(Object::EntireFile, window, cx)
});
Vim::action(editor, cx, |vim, _: &Comment, window, cx| {
if !matches!(vim.active_operator(), Some(Operator::Object { .. })) {
vim.push_operator(Operator::Object { around: true }, window, cx);
@ -200,6 +205,7 @@ impl Object {
| Object::Argument
| Object::Method
| Object::Class
| Object::EntireFile
| Object::Comment
| Object::IndentObj { .. } => true,
}
@ -225,6 +231,7 @@ impl Object {
| Object::Method
| Object::Class
| Object::Comment
| Object::EntireFile
| Object::CurlyBrackets
| Object::AngleBrackets => true,
}
@ -262,7 +269,7 @@ impl Object {
Mode::Visual
}
}
Object::Paragraph => Mode::VisualLine,
Object::Paragraph | Object::EntireFile => Mode::VisualLine,
}
}
@ -386,6 +393,7 @@ impl Object {
),
Object::Argument => argument(map, relative_to, around),
Object::IndentObj { include_below } => indent(map, relative_to, around, include_below),
Object::EntireFile => entire_file(map),
}
}
@ -709,6 +717,10 @@ fn around_next_word(
Some(start..end)
}
fn entire_file(map: &DisplaySnapshot) -> Option<Range<DisplayPoint>> {
Some(DisplayPoint::zero()..map.max_point())
}
fn text_object(
map: &DisplaySnapshot,
relative_to: DisplayPoint,