diff --git a/book/src/configuration.md b/book/src/configuration.md index affd497c7580..85b72d98ce6a 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -47,6 +47,7 @@ You may also specify a file to use for configuration with the `-c` or | `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` | | `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` | | `auto-info` | Whether to display infoboxes | `true` | +| `tmux-system-clipboard` | Sync with the system clipboard when running in tmux. | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index ac9f06fc6144..d03ee419f089 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -5,6 +5,7 @@ use crossterm::{ use helix_core::config::{default_syntax_loader, user_syntax_loader}; use helix_loader::grammar::load_runtime_file; use helix_view::clipboard::get_clipboard_provider; +use helix_view::editor::Config; use std::io::Write; #[derive(Copy, Clone)] @@ -53,7 +54,7 @@ pub fn general() -> std::io::Result<()> { let lang_file = helix_loader::lang_config_file(); let log_file = helix_loader::log_file(); let rt_dir = helix_loader::runtime_dir(); - let clipboard_provider = get_clipboard_provider(); + let clipboard_provider = get_clipboard_provider(&Config::default()); if config_file.exists() { writeln!(stdout, "Config file: {}", config_file.display())?; @@ -87,7 +88,7 @@ pub fn clipboard() -> std::io::Result<()> { let stdout = std::io::stdout(); let mut stdout = stdout.lock(); - let board = get_clipboard_provider(); + let board = get_clipboard_provider(&Config::default()); match board.name().as_ref() { "none" => { writeln!( diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs index f3d947346979..72954b3a2da1 100644 --- a/helix-view/src/clipboard.rs +++ b/helix-view/src/clipboard.rs @@ -3,6 +3,8 @@ use anyhow::Result; use std::borrow::Cow; +use crate::editor::Config; + pub enum ClipboardType { Clipboard, Selection, @@ -66,12 +68,12 @@ macro_rules! command_provider { } #[cfg(windows)] -pub fn get_clipboard_provider() -> Box { +pub fn get_clipboard_provider(_: &Config) -> Box { Box::new(provider::WindowsProvider::default()) } #[cfg(target_os = "macos")] -pub fn get_clipboard_provider() -> Box { +pub fn get_clipboard_provider(_: &Config) -> Box { use provider::command::exists; if exists("pbcopy") && exists("pbpaste") { @@ -85,13 +87,13 @@ pub fn get_clipboard_provider() -> Box { } #[cfg(target_os = "wasm32")] -pub fn get_clipboard_provider() -> Box { +pub fn get_clipboard_provider(_: &Config) -> Box { // TODO: Box::new(provider::NopProvider::new()) } #[cfg(not(any(windows, target_os = "wasm32", target_os = "macos")))] -pub fn get_clipboard_provider() -> Box { +pub fn get_clipboard_provider(config: &Config) -> Box { use provider::command::{env_var_is_set, exists, is_exit_success}; // TODO: support for user-defined provider, probably when we have plugin support by setting a // variable? @@ -130,9 +132,17 @@ pub fn get_clipboard_provider() -> Box { copy => "termux-clipboard-set"; } } else if env_var_is_set("TMUX") && exists("tmux") { - command_provider! { - paste => "tmux", "save-buffer", "-"; - copy => "tmux", "load-buffer", "-"; + if config.tmux_system_clipboard { + command_provider! { + // Refresh tmux clipboard, wait a bit for it to be updated and paste it + paste => "sh", "-c", "tmux refresh-client -l; sleep 0.1; tmux save-buffer -"; + copy => "tmux", "load-buffer", "-w", "-"; + } + } else { + command_provider! { + paste => "tmux", "save-buffer", "-"; + copy => "tmux", "load-buffer", "-"; + } } } else { Box::new(provider::NopProvider::new()) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index ed1813b35f5d..d020cf7dc44b 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -151,6 +151,8 @@ pub struct Config { pub statusline: StatusLineConfig, /// Shape for cursor in each mode pub cursor_shape: CursorShapeConfig, + /// Sync with the system clipboard when running in tmux. Defaults to `true`. + pub tmux_system_clipboard: bool, /// Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`. pub true_color: bool, /// Search configuration. @@ -548,6 +550,7 @@ impl Default for Config { file_picker: FilePickerConfig::default(), statusline: StatusLineConfig::default(), cursor_shape: CursorShapeConfig::default(), + tmux_system_clipboard: true, true_color: false, search: SearchConfig::default(), lsp: LspConfig::default(), @@ -697,7 +700,7 @@ impl Editor { theme_loader, last_theme: None, registers: Registers::default(), - clipboard_provider: get_clipboard_provider(), + clipboard_provider: get_clipboard_provider(&*conf), status_msg: None, autoinfo: None, idle_timer: Box::pin(sleep(conf.idle_timeout)),