From 25f78a2ed14b8fbb9e3ddfaa6d1327dcdc43d3c7 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Fri, 19 Jan 2024 15:02:10 -0800 Subject: [PATCH] Fix terminal selection firing when dragging anywhere --- crates/terminal/src/terminal.rs | 4 ++++ crates/terminal_view/src/terminal_element.rs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 502706eb5b..d9bdc17744 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -599,6 +599,10 @@ impl Terminal { } } + pub fn selection_started(&self) -> bool { + self.selection_phase == SelectionPhase::Selecting + } + /// Updates the cached process info, returns whether the Zed-relevant info has changed fn update_process_info(&mut self) -> bool { let mut pid = unsafe { libc::tcgetpgrp(self.shell_fd as i32) }; diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 78235c3579..29944b54d7 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -621,9 +621,17 @@ impl TerminalElement { } if e.pressed_button.is_some() && !cx.has_active_drag() { + let visibly_contains = interactive_bounds.visibly_contains(&e.position, cx); terminal.update(cx, |terminal, cx| { - terminal.mouse_drag(e, origin, bounds); - cx.notify(); + if !terminal.selection_started() { + if visibly_contains { + terminal.mouse_drag(e, origin, bounds); + cx.notify(); + } + } else { + terminal.mouse_drag(e, origin, bounds); + cx.notify(); + } }) }