From ba680fc2eb1b9bcc561eaf4bf5802b509dc1d9f2 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 21 Jul 2025 14:58:00 +0200 Subject: [PATCH] fix(compact-bar): tooltip duplication (#4310) * fix(tooltip): update config name and only launch once * add new stacked pane to tooltip --- .../compact-bar/src/action_types.rs | 3 +++ .../compact-bar/src/keybind_utils.rs | 2 +- default-plugins/compact-bar/src/main.rs | 24 +++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/default-plugins/compact-bar/src/action_types.rs b/default-plugins/compact-bar/src/action_types.rs index 7d1bd979..ddc91ead 100644 --- a/default-plugins/compact-bar/src/action_types.rs +++ b/default-plugins/compact-bar/src/action_types.rs @@ -34,6 +34,7 @@ pub enum ActionType { NewTab, Detach, Quit, + NewStackedPane, Other(String), // Fallback for unhandled actions } @@ -75,6 +76,7 @@ impl ActionType { }, ActionType::SwitchToMode(input_mode) => format!("{:?}", input_mode), ActionType::TogglePaneEmbedOrFloating => "Float or embed".to_string(), + ActionType::NewStackedPane => "New stacked pane".to_string(), ActionType::ToggleFocusFullscreen => "Toggle fullscreen".to_string(), ActionType::ToggleFloatingPanes => "Show/hide floating panes".to_string(), ActionType::CloseFocus => "Close pane".to_string(), @@ -101,6 +103,7 @@ impl ActionType { Action::Search(_) => ActionType::Search, Action::NewPane(Some(_), _, _) => ActionType::NewPaneWithDirection, Action::NewPane(None, _, _) => ActionType::NewPaneWithoutDirection, + Action::NewStackedPane(_, _) => ActionType::NewStackedPane, Action::BreakPaneLeft | Action::BreakPaneRight => ActionType::BreakPaneLeftOrRight, Action::GoToPreviousTab | Action::GoToNextTab => ActionType::GoToAdjacentTab, Action::ScrollUp | Action::ScrollDown => ActionType::Scroll, diff --git a/default-plugins/compact-bar/src/keybind_utils.rs b/default-plugins/compact-bar/src/keybind_utils.rs index 2a86dc88..68014169 100644 --- a/default-plugins/compact-bar/src/keybind_utils.rs +++ b/default-plugins/compact-bar/src/keybind_utils.rs @@ -50,7 +50,6 @@ impl KeybindProcessor { let should_add_brackets_to_keys = mode != InputMode::Normal; // Check if this is switching to normal mode - // let is_switching_to_locked = matches!(first_action, Action::SwitchToMode(InputMode::Normal)); let is_switching_to_locked = matches!(first_action, Action::SwitchToMode(InputMode::Locked)); @@ -334,6 +333,7 @@ impl KeybindProcessor { |action: &Action| matches!(action, Action::ToggleFocusFullscreen), |action: &Action| matches!(action, Action::ToggleFloatingPanes), |action: &Action| matches!(action, Action::TogglePaneEmbedOrFloating), + |action: &Action| matches!(action, Action::NewStackedPane(None, None)), |action: &Action| { matches!(action, Action::NewPane(Some(Direction::Right), None, false)) }, diff --git a/default-plugins/compact-bar/src/main.rs b/default-plugins/compact-bar/src/main.rs index 9dde0e31..ea99ef3a 100644 --- a/default-plugins/compact-bar/src/main.rs +++ b/default-plugins/compact-bar/src/main.rs @@ -58,6 +58,7 @@ struct State { tooltip_is_active: bool, persist: bool, is_first_run: bool, + own_tab_index: Option, } struct TabRenderData { @@ -103,6 +104,14 @@ impl ZellijPlugin for State { } else if message.name == MSG_TOGGLE_TOOLTIP && message.is_private && self.toggle_tooltip_key.is_some() + && self.own_tab_index == Some(self.active_tab_idx.saturating_sub(1)) + // only launch + // tooltip once + // even if there + // are a few + // instances of + // compact-bar + // running { self.toggle_persisted_tooltip(self.mode_info.mode); } @@ -224,7 +233,6 @@ impl State { self.tabs = tabs; should_render } else { - eprintln!("Could not find active tab."); false } } @@ -233,6 +241,7 @@ impl State { if self.toggle_tooltip_key.is_some() { let previous_tooltip_state = self.tooltip_is_active; self.tooltip_is_active = self.detect_tooltip_presence(&pane_manifest); + self.own_tab_index = self.find_own_tab_index(&pane_manifest); previous_tooltip_state != self.tooltip_is_active } else { false @@ -321,6 +330,17 @@ impl State { false } + fn find_own_tab_index(&self, pane_manifest: &PaneManifest) -> Option { + for (tab_index, panes) in &pane_manifest.panes { + for pane in panes { + if pane.is_plugin && Some(pane.id) == self.own_plugin_id { + return Some(*tab_index); + } + } + } + None + } + fn handle_tab_click(&self, col: usize) { if let Some(tab_idx) = get_tab_to_focus(&self.tab_line, self.active_tab_idx, col) { switch_tab_to(tab_idx.try_into().unwrap()); @@ -539,7 +559,7 @@ fn bind_toggle_key_config(toggle_key: &str) -> String { bind "{}" {{ MessagePlugin "compact-bar" {{ name "toggle_tooltip" - toggle_tooltip_key "{}" + tooltip "{}" }} }} }}