From ea545e9dfe1169490fa1fec53c74a8e891846356 Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Fri, 6 Jan 2023 21:09:41 +0800 Subject: [PATCH 1/3] Fix for lost clipboard contents (#5424) --- Cargo.lock | 1 + helix-view/Cargo.toml | 1 + helix-view/src/clipboard.rs | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69ba84449936..ede4ae0d38d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1274,6 +1274,7 @@ dependencies = [ "helix-lsp", "helix-tui", "helix-vcs", + "libc", "log", "once_cell", "serde", diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index e7a20496d04f..87a69c2b39c4 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -22,6 +22,7 @@ helix-lsp = { version = "0.6", path = "../helix-lsp" } helix-dap = { version = "0.6", path = "../helix-dap" } crossterm = { version = "0.25", optional = true } helix-vcs = { version = "0.6", path = "../helix-vcs" } +libc = "0.2" # Conversion traits once_cell = "1.17" diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs index 4f83fb4dc693..1401e6d64aef 100644 --- a/helix-view/src/clipboard.rs +++ b/helix-view/src/clipboard.rs @@ -276,12 +276,27 @@ pub mod provider { let stdin = input.map(|_| Stdio::piped()).unwrap_or_else(Stdio::null); let stdout = pipe_output.then(Stdio::piped).unwrap_or_else(Stdio::null); - let mut child = Command::new(self.prg) + let mut command: Command = Command::new(self.prg); + + let mut command_mut: &mut Command = command .args(self.args) .stdin(stdin) .stdout(stdout) - .stderr(Stdio::null()) - .spawn()?; + .stderr(Stdio::null()); + + // Fix for https://github.com/helix-editor/helix/issues/5424 + if cfg!(not(any(windows, target_os = "wasm32", target_os = "macos"))) { + use std::os::unix::process::CommandExt; + + unsafe { + command_mut = command_mut.pre_exec(|| match libc::setsid() { + -1 => Err(std::io::Error::last_os_error()), + _ => Ok(()), + }); + } + } + + let mut child = command_mut.spawn()?; if let Some(input) = input { let mut stdin = child.stdin.take().context("stdin is missing")?; From e2b0b33f9a1ae812879afd1182a017bb7d4a5e8d Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Sun, 8 Jan 2023 02:23:18 +0800 Subject: [PATCH 2/3] PR feedback: Call "setsid" for all unix systems --- helix-view/src/clipboard.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs index 1401e6d64aef..3c620c1466ac 100644 --- a/helix-view/src/clipboard.rs +++ b/helix-view/src/clipboard.rs @@ -285,7 +285,7 @@ pub mod provider { .stderr(Stdio::null()); // Fix for https://github.com/helix-editor/helix/issues/5424 - if cfg!(not(any(windows, target_os = "wasm32", target_os = "macos"))) { + if cfg!(unix) { use std::os::unix::process::CommandExt; unsafe { From 569aac246a0c9b36974c3af2a90fc6df07a73eaf Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Sat, 14 Jan 2023 01:27:20 +0800 Subject: [PATCH 3/3] PR Feedback: Only install libc for unix targets --- helix-view/Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 87a69c2b39c4..7d130317e410 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -22,7 +22,6 @@ helix-lsp = { version = "0.6", path = "../helix-lsp" } helix-dap = { version = "0.6", path = "../helix-dap" } crossterm = { version = "0.25", optional = true } helix-vcs = { version = "0.6", path = "../helix-vcs" } -libc = "0.2" # Conversion traits once_cell = "1.17" @@ -49,5 +48,8 @@ which = "4.2" [target.'cfg(windows)'.dependencies] clipboard-win = { version = "4.5", features = ["std"] } +[target.'cfg(unix)'.dependencies] +libc = "0.2" + [dev-dependencies] helix-tui = { path = "../helix-tui" }