From 6403385468690754a1058e1fec80fd5e0501a69c Mon Sep 17 00:00:00 2001 From: Micah Date: Fri, 30 Aug 2024 02:06:20 -0500 Subject: [PATCH] linux: Add an option to disable middle-click paste (#16572) Release Notes: - Added an editor setting to toggle Linux middle-click pasting (enabled by default) --- assets/settings/default.json | 2 ++ crates/editor/src/editor_settings.rs | 6 ++++++ crates/editor/src/element.rs | 32 +++++++++++++++------------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 9335f86c75a2a8f24267f212ded8f5a629e4e92b..0b7a98dd7cb023a6926be42e396402629fae46ef 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -227,6 +227,8 @@ // Whether to show diagnostic indicators in the scrollbar. "diagnostics": true }, + // Enable middle-click paste on Linux. + "middle_click_paste": true, // What to do when multibuffer is double clicked in some of its excerpts // (parts of singleton buffers). // May take 2 values: diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 37f7e80e65ab4210ab4d8a127dba3a35cf7cbac2..9a63fb0c04510145cd72dbcb2a5aaee51bd98ef6 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -23,6 +23,7 @@ pub struct EditorSettings { pub multi_cursor_modifier: MultiCursorModifier, pub redact_private_values: bool, pub expand_excerpt_lines: u32, + pub middle_click_paste: bool, #[serde(default)] pub double_click_in_multibuffer: DoubleClickInMultibuffer, pub search_wrap: bool, @@ -233,6 +234,11 @@ pub struct EditorSettingsContent { /// Default: 3 pub expand_excerpt_lines: Option, + /// Whether to enable middle-click paste on Linux + /// + /// Default: true + pub middle_click_paste: Option, + /// What to do when multibuffer is double clicked in some of its excerpts /// (parts of singleton buffers). /// diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index ea0378853aad06925c1ced166e977ea1a1207993..12f030602b9891dc7c98d86258b2d9f64781e2f6 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -658,22 +658,24 @@ impl EditorElement { } #[cfg(target_os = "linux")] - if let Some(text) = cx.read_from_primary().and_then(|item| item.text()) { - let point_for_position = - position_map.point_for_position(text_hitbox.bounds, event.position); - let position = point_for_position.previous_valid; - - editor.select( - SelectPhase::Begin { - position, - add: false, - click_count: 1, - }, - cx, - ); - editor.insert(&text, cx); + if EditorSettings::get_global(cx).middle_click_paste { + if let Some(text) = cx.read_from_primary().and_then(|item| item.text()) { + let point_for_position = + position_map.point_for_position(text_hitbox.bounds, event.position); + let position = point_for_position.previous_valid; + + editor.select( + SelectPhase::Begin { + position, + add: false, + click_count: 1, + }, + cx, + ); + editor.insert(&text, cx); + } + cx.stop_propagation() } - cx.stop_propagation() } }