Skip to content

Commit

Permalink
vim: Add textobject e for entire file (#24039)
Browse files Browse the repository at this point in the history
Co-Authored-By: Thomas Heartman <[email protected]>

Release Notes:

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

Co-authored-by: Thomas Heartman <[email protected]>
  • Loading branch information
ConradIrwin and Thomas Heartman authored Feb 1, 2025
1 parent 66e2028 commit a3c7dc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
16 changes: 14 additions & 2 deletions crates/vim/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum Object {
Method,
Class,
Comment,
EntireFile,
}

#[derive(Clone, Deserialize, JsonSchema, PartialEq)]
Expand Down Expand Up @@ -83,7 +84,8 @@ actions!(
Tag,
Method,
Class,
Comment
Comment,
EntireFile
]
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -200,6 +205,7 @@ impl Object {
| Object::Argument
| Object::Method
| Object::Class
| Object::EntireFile
| Object::Comment
| Object::IndentObj { .. } => true,
}
Expand All @@ -225,6 +231,7 @@ impl Object {
| Object::Method
| Object::Class
| Object::Comment
| Object::EntireFile
| Object::CurlyBrackets
| Object::AngleBrackets => true,
}
Expand Down Expand Up @@ -262,7 +269,7 @@ impl Object {
Mode::Visual
}
}
Object::Paragraph => Mode::VisualLine,
Object::Paragraph | Object::EntireFile => Mode::VisualLine,
}
}

Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a3c7dc3

Please sign in to comment.