diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json index 417916db4d6ca3..c11a474c68f0b5 100644 --- a/assets/keymaps/vim.json +++ b/assets/keymaps/vim.json @@ -259,7 +259,7 @@ "shift-d": "vim::VisualDeleteLine", "shift-x": "vim::VisualDeleteLine", "y": "vim::VisualYank", - "shift-y": "vim::VisualYank", + "shift-y": "vim::VisualYankLine", "p": "vim::Paste", "shift-p": ["vim::Paste", { "preserveClipboard": true }], "s": "vim::Substitute", diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs index d7d34febf8b7ee..12d9337dfe5bad 100644 --- a/crates/vim/src/visual.rs +++ b/crates/vim/src/visual.rs @@ -65,7 +65,12 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext) { vim.record_current_action(cx); vim.visual_delete(true, cx); }); - Vim::action(editor, cx, |vim, _: &VisualYank, cx| vim.visual_yank(cx)); + Vim::action(editor, cx, |vim, _: &VisualYank, cx| { + vim.visual_yank(false, cx) + }); + Vim::action(editor, cx, |vim, _: &VisualYankLine, cx| { + vim.visual_yank(true, cx) + }); Vim::action(editor, cx, Vim::select_next); Vim::action(editor, cx, Vim::select_previous); @@ -506,10 +511,11 @@ impl Vim { self.switch_mode(Mode::Normal, true, cx); } - pub fn visual_yank(&mut self, cx: &mut ViewContext) { + pub fn visual_yank(&mut self, line_mode: bool, cx: &mut ViewContext) { self.store_visual_marks(cx); self.update_editor(cx, |vim, editor, cx| { - let line_mode = editor.selections.line_mode; + let line_mode = line_mode || editor.selections.line_mode; + editor.selections.line_mode = line_mode; vim.yank_selections_content(editor, line_mode, cx); editor.change_selections(None, cx, |s| { s.move_with(|map, selection| { @@ -670,7 +676,7 @@ impl Vim { self.stop_recording(cx); self.visual_delete(false, cx) } - Some(Operator::Yank) => self.visual_yank(cx), + Some(Operator::Yank) => self.visual_yank(false, cx), _ => {} // Ignoring other operators } } @@ -1386,6 +1392,20 @@ mod test { }); } + #[gpui::test] + async fn test_shift_y(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + + cx.set_shared_state(indoc! { + "The ˇquick brown\n" + }) + .await; + cx.simulate_shared_keystrokes("v i w shift-y").await; + cx.shared_clipboard().await.assert_eq(indoc! { + "The quick brown\n" + }); + } + #[gpui::test] async fn test_gv(cx: &mut gpui::TestAppContext) { let mut cx = NeovimBackedTestContext::new(cx).await; diff --git a/crates/vim/test_data/test_shift_y.json b/crates/vim/test_data/test_shift_y.json new file mode 100644 index 00000000000000..f68f1df18d688d --- /dev/null +++ b/crates/vim/test_data/test_shift_y.json @@ -0,0 +1,7 @@ +{"Put":{"state":"The ˇquick brown\n"}} +{"Key":"v"} +{"Key":"i"} +{"Key":"w"} +{"Key":"shift-y"} +{"Get":{"state":"ˇThe quick brown\n","mode":"Normal"}} +{"ReadRegister":{"name":"\"","value":"The quick brown\n"}}