mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-02 21:40:41 +01:00
vim: Show yank highlight in characterwise visual mode (#67158)
## Summary Closes #67153 Yanking in characterwise visual mode (`v` + `y`) never showed the yank highlight, while visual line (`V`), visual block (`ctrl-v`) and normal-mode yanks did. The cause was an early return in `Vim::copy_ranges` that only checked `Mode::Visual`, so `Mode::VisualLine` and `Mode::VisualBlock` were highlighted anyway. This remove the `Mode::Visual` check so every yank is highlighted, as long as `vim.highlight_on_yank_duration` is not `0`. This matches Neovim's `vim.highlight.on_yank`, which highlights visual yanks by default (`on_visual = true`). The highlight also confirms that the yank happened, since the selection disappears either way. | Before | After | |-|-| | https://github.com/user-attachments/assets/04aba5a0-3082-4fd1-872d-2968cab88058 | https://github.com/user-attachments/assets/1f243f2e-36bd-489f-87d9-07087fc53f35 | ## Testing - Added `test_highlight_on_yank_in_visual_modes`, which checks the yank highlight in characterwise, linewise and blockwise visual mode, and that the highlight is cleared after `hightlight_on_yank_duration`. The test fails without the fix. - `cargo test -p vim --lib`: all tests pass. - `./script/clippy -p vim`: no warnings. - Manually tested on MacOS (see recordings above). ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - Fixed the vim yank highlight not showing when yanking in characterwise visual mode. --------- Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user