mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
Cherry-pick of #66906 to preview ---- ## 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. Co-authored-by: sandroid <88739791+sandr01d@users.noreply.github.com>
This commit is contained in:
+29
-14
@@ -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);
|
||||
|
||||
@@ -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(
|
||||
|
||||
+2
-11
@@ -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<char>,
|
||||
@@ -922,7 +913,7 @@ impl VimGlobals {
|
||||
cx: &mut App,
|
||||
) -> Option<Register> {
|
||||
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) => {
|
||||
|
||||
@@ -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::<VimAddon>().unwrap().entity.read(cx).mode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user