fix(compact-bar): tooltip duplication (#4310)

* fix(tooltip): update config name and only launch once

* add new stacked pane to tooltip
This commit is contained in:
Aram Drevekenin 2025-07-21 14:58:00 +02:00 committed by GitHub
parent 16d8e6d0ab
commit ba680fc2eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View file

@ -34,6 +34,7 @@ pub enum ActionType {
NewTab, NewTab,
Detach, Detach,
Quit, Quit,
NewStackedPane,
Other(String), // Fallback for unhandled actions Other(String), // Fallback for unhandled actions
} }
@ -75,6 +76,7 @@ impl ActionType {
}, },
ActionType::SwitchToMode(input_mode) => format!("{:?}", input_mode), ActionType::SwitchToMode(input_mode) => format!("{:?}", input_mode),
ActionType::TogglePaneEmbedOrFloating => "Float or embed".to_string(), ActionType::TogglePaneEmbedOrFloating => "Float or embed".to_string(),
ActionType::NewStackedPane => "New stacked pane".to_string(),
ActionType::ToggleFocusFullscreen => "Toggle fullscreen".to_string(), ActionType::ToggleFocusFullscreen => "Toggle fullscreen".to_string(),
ActionType::ToggleFloatingPanes => "Show/hide floating panes".to_string(), ActionType::ToggleFloatingPanes => "Show/hide floating panes".to_string(),
ActionType::CloseFocus => "Close pane".to_string(), ActionType::CloseFocus => "Close pane".to_string(),
@ -101,6 +103,7 @@ impl ActionType {
Action::Search(_) => ActionType::Search, Action::Search(_) => ActionType::Search,
Action::NewPane(Some(_), _, _) => ActionType::NewPaneWithDirection, Action::NewPane(Some(_), _, _) => ActionType::NewPaneWithDirection,
Action::NewPane(None, _, _) => ActionType::NewPaneWithoutDirection, Action::NewPane(None, _, _) => ActionType::NewPaneWithoutDirection,
Action::NewStackedPane(_, _) => ActionType::NewStackedPane,
Action::BreakPaneLeft | Action::BreakPaneRight => ActionType::BreakPaneLeftOrRight, Action::BreakPaneLeft | Action::BreakPaneRight => ActionType::BreakPaneLeftOrRight,
Action::GoToPreviousTab | Action::GoToNextTab => ActionType::GoToAdjacentTab, Action::GoToPreviousTab | Action::GoToNextTab => ActionType::GoToAdjacentTab,
Action::ScrollUp | Action::ScrollDown => ActionType::Scroll, Action::ScrollUp | Action::ScrollDown => ActionType::Scroll,

View file

@ -50,7 +50,6 @@ impl KeybindProcessor {
let should_add_brackets_to_keys = mode != InputMode::Normal; let should_add_brackets_to_keys = mode != InputMode::Normal;
// Check if this is switching to normal mode // 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 = let is_switching_to_locked =
matches!(first_action, Action::SwitchToMode(InputMode::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::ToggleFocusFullscreen),
|action: &Action| matches!(action, Action::ToggleFloatingPanes), |action: &Action| matches!(action, Action::ToggleFloatingPanes),
|action: &Action| matches!(action, Action::TogglePaneEmbedOrFloating), |action: &Action| matches!(action, Action::TogglePaneEmbedOrFloating),
|action: &Action| matches!(action, Action::NewStackedPane(None, None)),
|action: &Action| { |action: &Action| {
matches!(action, Action::NewPane(Some(Direction::Right), None, false)) matches!(action, Action::NewPane(Some(Direction::Right), None, false))
}, },

View file

@ -58,6 +58,7 @@ struct State {
tooltip_is_active: bool, tooltip_is_active: bool,
persist: bool, persist: bool,
is_first_run: bool, is_first_run: bool,
own_tab_index: Option<usize>,
} }
struct TabRenderData { struct TabRenderData {
@ -103,6 +104,14 @@ impl ZellijPlugin for State {
} else if message.name == MSG_TOGGLE_TOOLTIP } else if message.name == MSG_TOGGLE_TOOLTIP
&& message.is_private && message.is_private
&& self.toggle_tooltip_key.is_some() && 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); self.toggle_persisted_tooltip(self.mode_info.mode);
} }
@ -224,7 +233,6 @@ impl State {
self.tabs = tabs; self.tabs = tabs;
should_render should_render
} else { } else {
eprintln!("Could not find active tab.");
false false
} }
} }
@ -233,6 +241,7 @@ impl State {
if self.toggle_tooltip_key.is_some() { if self.toggle_tooltip_key.is_some() {
let previous_tooltip_state = self.tooltip_is_active; let previous_tooltip_state = self.tooltip_is_active;
self.tooltip_is_active = self.detect_tooltip_presence(&pane_manifest); 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 previous_tooltip_state != self.tooltip_is_active
} else { } else {
false false
@ -321,6 +330,17 @@ impl State {
false false
} }
fn find_own_tab_index(&self, pane_manifest: &PaneManifest) -> Option<usize> {
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) { fn handle_tab_click(&self, col: usize) {
if let Some(tab_idx) = get_tab_to_focus(&self.tab_line, self.active_tab_idx, col) { 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()); switch_tab_to(tab_idx.try_into().unwrap());
@ -539,7 +559,7 @@ fn bind_toggle_key_config(toggle_key: &str) -> String {
bind "{}" {{ bind "{}" {{
MessagePlugin "compact-bar" {{ MessagePlugin "compact-bar" {{
name "toggle_tooltip" name "toggle_tooltip"
toggle_tooltip_key "{}" tooltip "{}"
}} }}
}} }}
}} }}