Skip to content

Commit

Permalink
Fix for lost clipboard contents (#5424)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavynriebau committed Jan 6, 2023
1 parent 0dbee95 commit 19f531f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 18 additions & 3 deletions helix-view/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down

0 comments on commit 19f531f

Please sign in to comment.