diff --git a/crates/vim/src/normal/yank.rs b/crates/vim/src/normal/yank.rs index 6f2abfddd57..5ff3f2a08d2 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -221,7 +221,7 @@ impl Vim { }); let highlight_duration = VimSettings::get_global(cx).highlight_on_yank_duration; - if !is_yank || self.mode == Mode::Visual || highlight_duration == 0 { + if !is_yank || highlight_duration == 0 { return; } diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs index a27d0c2ec2a..97046dedeb3 100644 --- a/crates/vim/src/visual.rs +++ b/crates/vim/src/visual.rs @@ -945,10 +945,15 @@ impl Vim { } #[cfg(test)] mod test { + use std::time::Duration; + + use editor::HighlightKey; use indoc::indoc; + use settings::Settings as _; use workspace::item::Item; use crate::{ + VimSettings, state::Mode, test::{NeovimBackedTestContext, VimTestContext}, }; @@ -1305,6 +1310,59 @@ mod test { cx.shared_clipboard().await.assert_eq("fox jumps over\n"); } + #[gpui::test] + async fn test_visual_yank_highlight(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + let highlight_duration = Duration::from_millis( + cx.read(|cx| VimSettings::get_global(cx).highlight_on_yank_duration), + ); + + cx.set_state( + indoc! {" + The ˇquick brown + fox jumps over + the lazy dog"}, + Mode::Normal, + ); + cx.simulate_keystrokes("v e y"); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + The «quickˇ» brown + fox jumps over + the lazy dog"}, + ); + cx.executor().advance_clock(highlight_duration); + cx.run_until_parked(); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + The quick brown + fox jumps over + the lazy dog"}, + ); + + cx.simulate_keystrokes("V j y"); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + «The quick brown + fox jumps overˇ» + the lazy dog"}, + ); + cx.executor().advance_clock(highlight_duration); + cx.run_until_parked(); + + cx.simulate_keystrokes("ctrl-v j l y"); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + «Thˇ»e quick brown + «foˇ»x jumps over + the lazy dog"}, + ); + } + #[gpui::test] async fn test_visual_block_mode(cx: &mut gpui::TestAppContext) { let mut cx = NeovimBackedTestContext::new(cx).await;