Skip to content

Commit

Permalink
vim: Update yank to use target_visual_mode for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
5brian committed Feb 8, 2025
1 parent fe6d180 commit fb9e999
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions crates/vim/src/normal/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,34 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
let target_mode = object.target_visual_mode(self.mode, around);
self.update_editor(window, cx, |vim, editor, window, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let mut original_positions: HashMap<_, _> = Default::default();
let text_layout_details = editor.text_layout_details(window);
editor.change_selections(None, window, cx, |s| {
s.move_with(|map, selection| {
let original_position = (selection.head(), selection.goal);
object.expand_selection(map, selection, around);
// Use the object's target visual mode to determine selection behavior
if target_mode == Mode::VisualLine {
object.expand_selection(map, selection, around);
Motion::CurrentLine.expand_selection(
map,
selection,
None,
false,
&text_layout_details,
);
} else {
object.expand_selection(map, selection, around);
}
original_positions.insert(selection.id, original_position);
});
});
vim.yank_selections_content(editor, false, cx);

vim.yank_selections_content(editor, target_mode == Mode::VisualLine, cx);

editor.change_selections(None, window, cx, |s| {
s.move_with(|_, selection| {
let (head, goal) = original_positions.remove(&selection.id).unwrap();
Expand Down

0 comments on commit fb9e999

Please sign in to comment.