on master help sign in
Fix for lost clipboard contents (#5424) (#5426)
cce1971gavynriebau
Cargo.lock+1
@@ -1274,6 +1274,7 @@ dependencies = [
1274 "helix-lsp",
1274 "helix-lsp",
1275 "helix-tui",
1275 "helix-tui",
1276 "helix-vcs",
1276 "helix-vcs",
1277+ "libc",
1277 "log",
1278 "log",
1278 "once_cell",
1279 "once_cell",
1279 "serde",
1280 "serde",
helix-view/Cargo.toml+3
@@ -48,5 +48,8 @@ which = "4.2"
48[target.'cfg(windows)'.dependencies]
48[target.'cfg(windows)'.dependencies]
49clipboard-win = { version = "4.5", features = ["std"] }
49clipboard-win = { version = "4.5", features = ["std"] }
50
50
51+[target.'cfg(unix)'.dependencies]
52+libc = "0.2"
53+
51[dev-dependencies]
54[dev-dependencies]
52helix-tui = { path = "../helix-tui" }
55helix-tui = { path = "../helix-tui" }
helix-view/src/clipboard.rs+18−3
@@ -276,12 +276,27 @@ pub mod provider {
276 let stdin = input.map(|_| Stdio::piped()).unwrap_or_else(Stdio::null);
276 let stdin = input.map(|_| Stdio::piped()).unwrap_or_else(Stdio::null);
277 let stdout = pipe_output.then(Stdio::piped).unwrap_or_else(Stdio::null);
277 let stdout = pipe_output.then(Stdio::piped).unwrap_or_else(Stdio::null);
278
278
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
280 .args(self.args)
282 .args(self.args)
281 .stdin(stdin)
283 .stdin(stdin)
282 .stdout(stdout)
284 .stdout(stdout)
283− .stderr(Stdio::null())
285+ .stderr(Stdio::null());
284− .spawn()?;
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()?;
285
300
286 if let Some(input) = input {
301 if let Some(input) = input {
287 let mut stdin = child.stdin.take().context("stdin is missing")?;
302 let mut stdin = child.stdin.take().context("stdin is missing")?;