From 82a75360612330099e5e590d5cc1399f8889b703 Mon Sep 17 00:00:00 2001 From: Elijah Koulaxis Date: Sat, 4 Apr 2026 00:27:04 +0300 Subject: [PATCH 1/3] feat: toggle menus on click --- crates/edit/src/tui.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/edit/src/tui.rs b/crates/edit/src/tui.rs index 314cdc30cc6..3b763dce080 100644 --- a/crates/edit/src/tui.rs +++ b/crates/edit/src/tui.rs @@ -361,6 +361,10 @@ pub struct Tui { /// need to scroll the node into view if it's within a scrollarea. focused_node_for_scrolling: u64, + /// Tracks the node ID of the menubar button that opened the current menu. + /// Used to implement toggle-close: clicking the same button again closes the menu. + menubar_toggle_id: u64, + /// A list of cached text buffers used for [`Context::editline()`]. cached_text_buffers: Vec, @@ -412,6 +416,7 @@ impl Tui { focused_node_path: Vec::with_capacity(16), focused_node_for_scrolling: ROOT_ID, + menubar_toggle_id: 0, cached_text_buffers: Vec::with_capacity(16), @@ -3165,7 +3170,19 @@ impl<'a> Context<'a, '_> { && !contains_focus && self.consume_shortcut(kbmod::ALT | InputKey::new(accelerator as u32)); + let button_id = self.tree.last_node.borrow().id; + if contains_focus && self.tui.menubar_toggle_id == button_id && self.contains_mouse_down() { + self.tui.menubar_toggle_id = 0; + self.tui.pop_focusable_node(1); + + return false; + } + if contains_focus || keyboard_focus { + if self.tui.mouse_state != InputMouseState::Left { + self.tui.menubar_toggle_id = button_id; + } + self.attr_background_rgba(self.tui.floater_default_bg); self.attr_foreground_rgba(self.tui.floater_default_fg); @@ -3278,6 +3295,10 @@ impl<'a> Context<'a, '_> { /// Ends the current menubar. pub fn menubar_end(&mut self) { self.table_end(); + + if !self.contains_focus() { + self.tui.menubar_toggle_id = 0; + } } /// Renders a button label with an optional accelerator character From d4146fd34ab5a4de045c5c7acbbb16efe4fe5b68 Mon Sep 17 00:00:00 2001 From: kx0101 Date: Tue, 14 Jul 2026 15:16:58 +0300 Subject: [PATCH 2/3] fix: preserve menu item clicks when toggling menus --- crates/edit/src/tui.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/edit/src/tui.rs b/crates/edit/src/tui.rs index 3b763dce080..3ba07be090b 100644 --- a/crates/edit/src/tui.rs +++ b/crates/edit/src/tui.rs @@ -3171,13 +3171,19 @@ impl<'a> Context<'a, '_> { && self.consume_shortcut(kbmod::ALT | InputKey::new(accelerator as u32)); let button_id = self.tree.last_node.borrow().id; - if contains_focus && self.tui.menubar_toggle_id == button_id && self.contains_mouse_down() { + let mouse_clicked = self.input_mouse_click != 0 && self.button_activated(); + + if mouse_clicked && self.tui.menubar_toggle_id == button_id { self.tui.menubar_toggle_id = 0; self.tui.pop_focusable_node(1); return false; } + if mouse_clicked { + self.tui.menubar_toggle_id = button_id; + } + if contains_focus || keyboard_focus { if self.tui.mouse_state != InputMouseState::Left { self.tui.menubar_toggle_id = button_id; From 90f2240e6cc2eee4c4cfe48457b400ed8026026f Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 6 Aug 2026 19:01:35 +0200 Subject: [PATCH 3/3] Simplify implementation --- crates/edit/src/tui.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/edit/src/tui.rs b/crates/edit/src/tui.rs index 2dd49bf303a..c28de4b4793 100644 --- a/crates/edit/src/tui.rs +++ b/crates/edit/src/tui.rs @@ -363,8 +363,8 @@ pub struct Tui { /// need to scroll the node into view if it's within a scrollarea. focused_node_for_scrolling: u64, - /// Tracks the node ID of the menubar button that opened the current menu. - /// Used to implement toggle-close: clicking the same button again closes the menu. + /// The menubar button whose menu is open and can be closed by clicking it again. + /// Only set once the press that opened the menu has ended. menubar_toggle_id: u64, /// A list of cached text buffers used for [`Context::editline()`]. @@ -3214,20 +3214,16 @@ impl<'a> Context<'a, '_> { && self.consume_shortcut(kbmod::ALT | InputKey::new(accelerator as u32)); let button_id = self.tree.last_node.borrow().id; - let mouse_clicked = self.input_mouse_click != 0 && self.button_activated(); - if mouse_clicked && self.tui.menubar_toggle_id == button_id { + if self.button_activated() && self.tui.menubar_toggle_id == button_id { self.tui.menubar_toggle_id = 0; - self.tui.pop_focusable_node(1); - + self.toss_focus_up(); return false; } - if mouse_clicked { - self.tui.menubar_toggle_id = button_id; - } - if contains_focus || keyboard_focus { + // Arming this only while no button is held keeps the press + // that opened the menu from closing it again right away. if self.tui.mouse_state != InputMouseState::Left { self.tui.menubar_toggle_id = button_id; }