Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for lost clipboard contents (#5424) #5426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

3 changes: 3 additions & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,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" }
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!(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")?;
Expand Down