diff options
author | gavynriebau | 2023-01-16 07:13:48 +0000 |
---|---|---|
committer | GitHub | 2023-01-16 07:13:48 +0000 |
commit | cce19713fb970df1a96be7e76e3217e4e50efc42 (patch) | |
tree | 0c6b22c0ef42aa44d9f651931eebd83a299fa45e /helix-view/src | |
parent | b6331394a3f341ad21f8fad3e6e0b93becda9ce5 (diff) |
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
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/clipboard.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs index 4f83fb4d..3c620c14 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!(unix) { + 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")?; |