on master help sign in
Fix for lost clipboard contents (#5424) (#5426)

* Fix for lost clipboard contents (#5424) * PR feedback: Call "setsid" for all unix systems * PR Feedback: Only install libc for unix targets

commitcce19713fb970df1a96be7e76e3217e4e50efc42 authorgavynriebau <gavyn.riebau@gmail.com> dateMon 16 Jan 2023, 15:13 (4 years ago) parentb633139
3 files changed+22−3
Cargo.lock+1 helix-view/Cargo.toml+3 helix-view/src/clipboard.rs+18−3
Cargo.lock+1
@@ -1274,6 +1274,7 @@ dependencies = [
12741274 "helix-lsp",
12751275 "helix-tui",
12761276 "helix-vcs",
1277+ "libc",
12771278 "log",
12781279 "once_cell",
12791280 "serde",
helix-view/Cargo.toml+3
@@ -48,5 +48,8 @@ which = "4.2"
4848[target.'cfg(windows)'.dependencies]
4949clipboard-win = { version = "4.5", features = ["std"] }
5050
51+[target.'cfg(unix)'.dependencies]
52+libc = "0.2"
53+
5154[dev-dependencies]
5255helix-tui = { path = "../helix-tui" }
helix-view/src/clipboard.rs+18−3
@@ -276,12 +276,27 @@ pub mod provider {
276276 let stdin = input.map(|_| Stdio::piped()).unwrap_or_else(Stdio::null);
277277 let stdout = pipe_output.then(Stdio::piped).unwrap_or_else(Stdio::null);
278278
279− let mut child = Command::new(self.prg)
279+ let mut command: Command = Command::new(self.prg);
280+
281+ let mut command_mut: &mut Command = command
280282 .args(self.args)
281283 .stdin(stdin)
282284 .stdout(stdout)
283− .stderr(Stdio::null())
284− .spawn()?;
285+ .stderr(Stdio::null());
286+
287+ // Fix for https://github.com/helix-editor/helix/issues/5424
288+ if cfg!(unix) {
289+ use std::os::unix::process::CommandExt;
290+
291+ unsafe {
292+ command_mut = command_mut.pre_exec(|| match libc::setsid() {
293+ -1 => Err(std::io::Error::last_os_error()),
294+ _ => Ok(()),
295+ });
296+ }
297+ }
298+
299+ let mut child = command_mut.spawn()?;
285300
286301 if let Some(input) = input {
287302 let mut stdin = child.stdin.take().context("stdin is missing")?;