From 27e4d722bfe2b3576fc513d18526c4e6b744f42e Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Fri, 17 Oct 2025 07:56:43 +0200 Subject: [PATCH] Avoid updating the link highlight while the context menu is shown --- src/main.rs | 4 ++-- src/terminal_box.rs | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 22e7290..194b4d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -400,7 +400,7 @@ pub enum Message { TabActivateJump(usize), TabClose(Option), TabContextAction(segmented_button::Entity, Action), - TabContextMenu(pane_grid::Pane, MenuState), + TabContextMenu(pane_grid::Pane, Option), TabNew, TabNewNoProfile, TabNext, @@ -2469,7 +2469,7 @@ impl Application for App { if let Some(terminal) = tab_model.data::>(entity) { // Update context menu position let mut terminal = terminal.lock().unwrap(); - terminal.context_menu = Some(menu_state); + terminal.context_menu = menu_state; } } diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 58a6a3b..f3a72ff 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -56,7 +56,7 @@ pub struct TerminalBox<'a, Message> { show_headerbar: bool, click_timing: Duration, context_menu: Option, - on_context_menu: Option Message + 'a>>, + on_context_menu: Option) -> Message + 'a>>, on_mouse_enter: Option Message + 'a>>, opacity: Option, mouse_inside_boundary: Option, @@ -124,7 +124,10 @@ where self } - pub fn on_context_menu(mut self, on_context_menu: impl Fn(MenuState) -> Message + 'a) -> Self { + pub fn on_context_menu( + mut self, + on_context_menu: impl Fn(Option) -> Message + 'a, + ) -> Self { self.on_context_menu = Some(Box::new(on_context_menu)); self } @@ -1098,10 +1101,7 @@ where // Update context menu state if let Some(on_context_menu) = &self.on_context_menu { shell.publish((on_context_menu)(match self.context_menu { - Some(_) => MenuState { - position: None, - link: None, - }, + Some(_) => None, None => match button { Button::Right => { let x = p.x - self.padding.left; @@ -1120,15 +1120,12 @@ where None, ); let link = get_hyperlink(&terminal, location); - MenuState { + Some(MenuState { position: Some(p), link, - } + }) } - _ => MenuState { - position: None, - link: None, - }, + _ => None, }, })); } @@ -1340,6 +1337,14 @@ fn update_active_regex_match( location: Option, modifiers: Option<&Modifiers>, ) { + //Do not update any highlights if + //there is a context_menu shown + //to the user + if terminal.context_menu.is_some() { + return; + } + + //Require CTRL for keyboard and mouse interaction if let Some(modifiers) = modifiers { if !modifiers.contains(Modifiers::CTRL) { if terminal.active_regex_match.is_some() {