From 58849026ec30fb225dc5d07cccf37e8408b85555 Mon Sep 17 00:00:00 2001 From: sandroid <88739791+sandr01d@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:48:24 +0000 Subject: [PATCH] helix: Honor `use_system_clipboard` (#66906) ## Summary ## What problem does this solve, how, and why does this change matter? Ensures helix mode honors the the configured `use_system_clipboard` instead of always ignoring it and acting as if the value was `UseSystemClipboard::Never`. To be honest, I'm a bit confused why #55455 decided that Helix mode should deliberately ignore the configured setting, when the desired behavior ("not clobbering the system clipboard") is already available with `Never`, maybe @SrGaabriel can shed some light on this? I find the feature to always copy/paste to/from the system clipboard super handy, especially when using in combination with a clipboard manager. closes #66782 ## Testing Enable helix mode. When `use_system_clipboard` is set to `Always` or `OnYank`, `y` and `p` yank and paste from/to the system clipboard. When `use_system_clipboard` is set to `Never`, `y` and `p` yank and paste from/to the internal register. I mostly duplicated the tests added in #55455 and run them against the two different scenarios: `Always` and `Never`. For the tests targeting the specific registers, I removed the assumption about the system clipboard because IMO this is not what these tests should test. Let me know if that's fine or if I should iterate on that. ## 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 Helix mode ignoring the `vim.use_system_clipboard` setting. Yank, delete and paste in Helix mode use the system clipboard by default again, as they did before 1.28 . If you wish to keep the 1.28 behavior, set `"vim": { "use_system_clipboard": "never" }` to keep using the internal register. --- crates/vim/src/helix.rs | 43 +++++++++++++++++-------- crates/vim/src/helix/paste.rs | 29 ++++++++++++++++- crates/vim/src/state.rs | 13 ++------ crates/vim/src/test/vim_test_context.rs | 10 ++++++ 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs index 545441677c0..0bc9f9fa7dc 100644 --- a/crates/vim/src/helix.rs +++ b/crates/vim/src/helix.rs @@ -1949,7 +1949,7 @@ mod test { use project::FakeFs; use search::{ProjectSearchView, project_search}; use serde_json::json; - use settings::{SettingsStore, ThemeColorsContent, ThemeStyleContent}; + use settings::{SettingsStore, ThemeColorsContent, ThemeStyleContent, UseSystemClipboard}; use theme::ActiveTheme as _; use util::path; use workspace::{DeploySearch, MultiWorkspace}; @@ -2847,13 +2847,36 @@ mod test { } #[gpui::test] - async fn test_helix_yank(cx: &mut gpui::TestAppContext) { + async fn test_helix_yank_default(cx: &mut gpui::TestAppContext) { let mut cx = VimTestContext::new(cx, true).await; cx.enable_helix(); cx.write_to_clipboard(gpui::ClipboardItem::new_string("external".into())); - // Test yanking a single character (no explicit selection) should not clobber the system clipboard + // Test yanking a single character (no explicit selection) should use the system clipboard + cx.set_state("hello ˇworld", Mode::HelixNormal); + cx.simulate_keystrokes("y"); + cx.assert_state("hello ˇworld", Mode::HelixNormal); + cx.shared_clipboard().assert_eq("w"); + cx.simulate_keystrokes("l p"); + cx.assert_state("hello wo«wˇ»rld", Mode::HelixNormal); + + // Test yanking a multi-char selection + cx.set_state("hello «worlˇ»d", Mode::HelixNormal); + cx.simulate_keystrokes("y"); + cx.shared_clipboard().assert_eq("worl"); + cx.assert_state("hello «worlˇ»d", Mode::HelixNormal); + } + + #[gpui::test] + async fn test_helix_yank_system_clipboard_never(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + cx.enable_helix(); + cx.set_use_system_clipboard(UseSystemClipboard::Never); + + cx.write_to_clipboard(gpui::ClipboardItem::new_string("external".into())); + + // Test yanking a single character (no explicit selection) should not use the system clipboard cx.set_state("hello ˇworld", Mode::HelixNormal); cx.simulate_keystrokes("y"); cx.assert_state("hello ˇworld", Mode::HelixNormal); @@ -2920,7 +2943,7 @@ mod test { for action in ["d", "c escape"] { cx.set_state("«deletedˇ»", Mode::HelixNormal); cx.simulate_keystrokes(action); - cx.shared_clipboard().assert_eq("external"); + cx.shared_clipboard().assert_eq("deleted"); cx.set_state("ˇ", Mode::HelixNormal); cx.simulate_keystrokes("\" 0 p"); @@ -2940,11 +2963,11 @@ mod test { cx.set_state("ˇ", Mode::HelixNormal); cx.simulate_keystrokes("\" 2 p"); cx.assert_state("«first\nˇ»", Mode::HelixNormal); - cx.shared_clipboard().assert_eq("external"); + cx.shared_clipboard().assert_eq("second\n"); cx.set_state("ˇ\nsecond line", Mode::HelixNormal); cx.simulate_keystrokes("d"); - cx.shared_clipboard().assert_eq("external"); + cx.shared_clipboard().assert_eq("\n"); } #[gpui::test] @@ -2952,15 +2975,7 @@ mod test { let mut cx = VimTestContext::new(cx, true).await; cx.enable_helix(); cx.write_to_clipboard(gpui::ClipboardItem::new_string("external".into())); - cx.set_state("«internalˇ»", Mode::HelixNormal); - cx.simulate_keystrokes("y"); - for action in ["p", "\" \" p", "shift-r", "\" \" shift-r"] { - cx.set_state("ˇ", Mode::HelixNormal); - cx.simulate_keystrokes(action); - cx.assert_state("«internalˇ»", Mode::HelixNormal); - cx.shared_clipboard().assert_eq("external"); - } cx.set_state("«namedˇ»", Mode::HelixNormal); cx.simulate_keystrokes("\" a y"); cx.set_state("ˇ", Mode::HelixNormal); diff --git a/crates/vim/src/helix/paste.rs b/crates/vim/src/helix/paste.rs index 53545ac2d02..82cd81f43f9 100644 --- a/crates/vim/src/helix/paste.rs +++ b/crates/vim/src/helix/paste.rs @@ -151,11 +151,12 @@ mod test { use indoc::indoc; use gpui::ClipboardItem; + use settings::UseSystemClipboard; use crate::{state::Mode, test::VimTestContext}; #[gpui::test] - async fn test_helix_paste_ignores_system_clipboard(cx: &mut gpui::TestAppContext) { + async fn test_helix_paste_honors_system_clipboard_by_default(cx: &mut gpui::TestAppContext) { let mut cx = VimTestContext::new(cx, true).await; cx.enable_helix(); cx.set_state( @@ -166,6 +167,32 @@ mod test { Mode::HelixNormal, ); + cx.write_to_clipboard(ClipboardItem::new_string("clipboard".to_string())); + cx.simulate_keystrokes("p"); + cx.assert_state( + indoc! {" + The quic«clipboardˇ»k brown + fox jumps over + the lazy dog."}, + Mode::HelixNormal, + ); + } + + #[gpui::test] + async fn test_helix_paste_ignores_system_clipboard_when_disabled( + cx: &mut gpui::TestAppContext, + ) { + let mut cx = VimTestContext::new(cx, true).await; + cx.set_use_system_clipboard(UseSystemClipboard::Never); + cx.enable_helix(); + cx.set_state( + indoc! {" + The quiˇck brown + fox jumps over + the lazy dog."}, + Mode::HelixNormal, + ); + cx.write_to_clipboard(ClipboardItem::new_string("clipboard".to_string())); cx.simulate_keystrokes("p"); cx.assert_state( diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index e5e0130e128..69240118cbf 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -37,7 +37,6 @@ use ui::{ }; use util::ResultExt; use util::rel_path::RelPath; -use vim_mode_setting::HelixModeSetting; use workspace::searchable::Direction; use workspace::{MultiWorkspace, Workspace, WorkspaceDb, WorkspaceId}; @@ -874,7 +873,7 @@ impl VimGlobals { } } } else { - let setting = Self::default_register_clipboard_policy(cx); + let setting = VimSettings::get_global(cx).use_system_clipboard; if setting == UseSystemClipboard::Always || setting == UseSystemClipboard::OnYank && is_yank { @@ -907,14 +906,6 @@ impl VimGlobals { } } - fn default_register_clipboard_policy(cx: &App) -> UseSystemClipboard { - if HelixModeSetting::get_global(cx).0 { - UseSystemClipboard::Never - } else { - VimSettings::get_global(cx).use_system_clipboard - } - } - pub(crate) fn read_register( &self, register: Option, @@ -922,7 +913,7 @@ impl VimGlobals { cx: &mut App, ) -> Option { let Some(register) = register.filter(|reg| *reg != '"') else { - let setting = Self::default_register_clipboard_policy(cx); + let setting = VimSettings::get_global(cx).use_system_clipboard; return match setting { UseSystemClipboard::Always => cx.read_from_clipboard().map(|item| item.into()), UseSystemClipboard::OnYank if self.system_clipboard_is_newer(cx) => { diff --git a/crates/vim/src/test/vim_test_context.rs b/crates/vim/src/test/vim_test_context.rs index 6f15450aa3f..3b4f5c2618d 100644 --- a/crates/vim/src/test/vim_test_context.rs +++ b/crates/vim/src/test/vim_test_context.rs @@ -187,6 +187,16 @@ impl VimTestContext { }) } + pub fn set_use_system_clipboard(&mut self, value: UseSystemClipboard) { + self.cx.update(|_, cx| { + SettingsStore::update_global(cx, |store, cx| { + store.update_user_settings(cx, |s| { + s.vim.get_or_insert_default().use_system_clipboard = Some(value) + }); + }) + }) + } + pub fn mode(&mut self) -> Mode { self.update_editor(|editor, _, cx| editor.addon::().unwrap().entity.read(cx).mode) }