diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 6caca6f2e9..58954c96a4 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -530,6 +530,7 @@ impl EditorElement { cx.stop_propagation(); } + #[cfg(target_os = "linux")] fn mouse_middle_down( editor: &mut Editor, event: &MouseDownEvent, @@ -3240,6 +3241,7 @@ impl EditorElement { MouseButton::Right => editor.update(cx, |editor, cx| { Self::mouse_right_down(editor, event, &position_map, &text_hitbox, cx); }), + #[cfg(target_os = "linux")] MouseButton::Middle => editor.update(cx, |editor, cx| { Self::mouse_middle_down(editor, event, &position_map, &text_hitbox, cx); }), diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 2f573915e0..0a234e4359 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -547,6 +547,7 @@ impl AppContext { /// Writes data to the primary selection buffer. /// Only available on Linux. + #[cfg(target_os = "linux")] pub fn write_to_primary(&self, item: ClipboardItem) { self.platform.write_to_primary(item) } @@ -558,6 +559,7 @@ impl AppContext { /// Reads data from the primary selection buffer. /// Only available on Linux. + #[cfg(target_os = "linux")] pub fn read_from_primary(&self) -> Option { self.platform.read_from_primary() } diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 0d311f1e32..bd0170d622 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -147,8 +147,10 @@ pub(crate) trait Platform: 'static { fn set_cursor_style(&self, style: CursorStyle); fn should_auto_hide_scrollbars(&self) -> bool; + #[cfg(target_os = "linux")] fn write_to_primary(&self, item: ClipboardItem); fn write_to_clipboard(&self, item: ClipboardItem); + #[cfg(target_os = "linux")] fn read_from_primary(&self) -> Option; fn read_from_clipboard(&self) -> Option; diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index f7754687ea..ca93260b54 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -817,8 +817,6 @@ impl Platform for MacPlatform { } } - fn write_to_primary(&self, _item: ClipboardItem) {} - fn write_to_clipboard(&self, item: ClipboardItem) { let state = self.0.lock(); unsafe { @@ -856,10 +854,6 @@ impl Platform for MacPlatform { } } - fn read_from_primary(&self) -> Option { - None - } - fn read_from_clipboard(&self) -> Option { let state = self.0.lock(); unsafe { diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index 8fa558e435..b60ecba864 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -23,6 +23,7 @@ pub(crate) struct TestPlatform { active_display: Rc, active_cursor: Mutex, current_clipboard_item: Mutex>, + #[cfg(target_os = "linux")] current_primary_item: Mutex>, pub(crate) prompts: RefCell, pub opened_url: RefCell>, @@ -45,6 +46,7 @@ impl TestPlatform { active_display: Rc::new(TestDisplay::new()), active_window: Default::default(), current_clipboard_item: Mutex::new(None), + #[cfg(target_os = "linux")] current_primary_item: Mutex::new(None), weak: weak.clone(), opened_url: Default::default(), @@ -272,6 +274,7 @@ impl Platform for TestPlatform { false } + #[cfg(target_os = "linux")] fn write_to_primary(&self, item: ClipboardItem) { *self.current_primary_item.lock() = Some(item); } @@ -280,6 +283,7 @@ impl Platform for TestPlatform { *self.current_clipboard_item.lock() = Some(item); } + #[cfg(target_os = "linux")] fn read_from_primary(&self) -> Option { self.current_primary_item.lock().clone() } diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 80ee23db7e..e441e68618 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -625,8 +625,6 @@ impl Platform for WindowsPlatform { false } - fn write_to_primary(&self, _item: ClipboardItem) {} - fn write_to_clipboard(&self, item: ClipboardItem) { if item.text.len() > 0 { let mut ctx = ClipboardContext::new().unwrap(); @@ -634,10 +632,6 @@ impl Platform for WindowsPlatform { } } - fn read_from_primary(&self) -> Option { - None - } - fn read_from_clipboard(&self) -> Option { let mut ctx = ClipboardContext::new().unwrap(); let content = ctx.get_contents().ok()?; diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 0d2a811ccd..a84ce0d977 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -1195,7 +1195,7 @@ impl Terminal { &mut self, e: &MouseDownEvent, origin: Point, - cx: &mut ModelContext, + _cx: &mut ModelContext, ) { let position = e.position - origin; let point = grid_point( @@ -1210,33 +1210,40 @@ impl Terminal { { self.pty_tx.notify(bytes); } - } else if e.button == MouseButton::Left { - let position = e.position - origin; - let (point, side) = grid_point_and_side( - position, - self.last_content.size, - self.last_content.display_offset, - ); + } else { + match e.button { + MouseButton::Left => { + let position = e.position - origin; + let (point, side) = grid_point_and_side( + position, + self.last_content.size, + self.last_content.display_offset, + ); - let selection_type = match e.click_count { - 0 => return, //This is a release - 1 => Some(SelectionType::Simple), - 2 => Some(SelectionType::Semantic), - 3 => Some(SelectionType::Lines), - _ => None, - }; + let selection_type = match e.click_count { + 0 => return, //This is a release + 1 => Some(SelectionType::Simple), + 2 => Some(SelectionType::Semantic), + 3 => Some(SelectionType::Lines), + _ => None, + }; - let selection = - selection_type.map(|selection_type| Selection::new(selection_type, point, side)); + let selection = selection_type + .map(|selection_type| Selection::new(selection_type, point, side)); - if let Some(sel) = selection { - self.events - .push_back(InternalEvent::SetSelection(Some((sel, point)))); - } - } else if e.button == MouseButton::Middle { - if let Some(item) = cx.read_from_primary() { - let text = item.text().to_string(); - self.input(text); + if let Some(sel) = selection { + self.events + .push_back(InternalEvent::SetSelection(Some((sel, point)))); + } + } + #[cfg(target_os = "linux")] + MouseButton::Middle => { + if let Some(item) = _cx.read_from_primary() { + let text = item.text().to_string(); + self.input(text); + } + } + _ => {} } } }