diff options
| author | Aram Drevekenin <aram@poor.dev> | 2025-02-18 11:11:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-18 11:11:58 +0100 |
| commit | 544982dad4746ab2f264f77a44379d64a7a42aa7 (patch) | |
| tree | 0e7c9cdae0f3a624aa38e1afc4e5575b1e6c41de /default-plugins | |
| parent | docs(changelog): convert old themes (diff) | |
| download | sl0ppij-544982dad4746ab2f264f77a44379d64a7a42aa7.tar.gz sl0ppij-544982dad4746ab2f264f77a44379d64a7a42aa7.tar.xz sl0ppij-544982dad4746ab2f264f77a44379d64a7a42aa7.zip | |
feat(ui): resize shortcuts (#4003)
* feat(ui): show resize and focus shortcuts when relevant
* update serialization and snapshots
* update e2e tests
* style(fmt): rustfmt
Diffstat (limited to 'default-plugins')
| -rw-r--r-- | default-plugins/status-bar/src/one_line_ui.rs | 144 |
1 files changed, 117 insertions, 27 deletions
diff --git a/default-plugins/status-bar/src/one_line_ui.rs b/default-plugins/status-bar/src/one_line_ui.rs index 3b7eec10..b230a25b 100644 --- a/default-plugins/status-bar/src/one_line_ui.rs +++ b/default-plugins/status-bar/src/one_line_ui.rs @@ -682,9 +682,22 @@ fn render_secondary_info( } } +fn should_show_focus_and_resize_shortcuts(tab_info: Option<&TabInfo>) -> bool { + let Some(tab_info) = tab_info else { + return false; + }; + let are_floating_panes_visible = tab_info.are_floating_panes_visible; + if are_floating_panes_visible { + tab_info.selectable_floating_panes_count > 1 + } else { + tab_info.selectable_tiled_panes_count > 1 + } +} + fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usize) -> LinePart { let mut secondary_info = LinePart::default(); let binds = &help.get_mode_keybinds(); + let should_show_focus_and_resize_shortcuts = should_show_focus_and_resize_shortcuts(tab_info); // New Pane let new_pane_action_key = action_key(binds, &[Action::NewPane(None, None, false)]); let mut new_pane_key_to_display = new_pane_action_key @@ -698,6 +711,25 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz vec![] }; + // Resize + let resize_increase_action_key = action_key(binds, &[Action::Resize(Resize::Increase, None)]); + let resize_increase_key = resize_increase_action_key + .iter() + .find(|k| k.bare_key == BareKey::Char('+')) + .or_else(|| resize_increase_action_key.iter().next()); + let resize_decrease_action_key = action_key(binds, &[Action::Resize(Resize::Decrease, None)]); + let resize_decrease_key = resize_decrease_action_key + .iter() + .find(|k| k.bare_key == BareKey::Char('-')) + .or_else(|| resize_increase_action_key.iter().next()); + let mut resize_shortcuts = vec![]; + if let Some(resize_increase_key) = resize_increase_key { + resize_shortcuts.push(resize_increase_key.clone()); + } + if let Some(resize_decrease_key) = resize_decrease_key { + resize_shortcuts.push(resize_decrease_key.clone()); + } + // Move focus let mut move_focus_shortcuts: Vec<KeyWithModifier> = vec![]; @@ -757,6 +789,7 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz [ new_pane_key_to_display.clone(), move_focus_shortcuts.clone(), + resize_shortcuts.clone(), toggle_floating_key_to_display.clone(), ] .iter() @@ -773,13 +806,22 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz false, Some(0), )); - secondary_info.append(&add_shortcut( - help, - "Change Focus", - &move_focus_shortcuts, - false, - Some(0), - )); + if should_show_focus_and_resize_shortcuts { + secondary_info.append(&add_shortcut( + help, + "Change Focus", + &move_focus_shortcuts, + false, + Some(0), + )); + secondary_info.append(&add_shortcut( + help, + "Resize", + &resize_shortcuts, + false, + Some(0), + )); + } secondary_info.append(&add_shortcut( help, "Floating", @@ -808,6 +850,10 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz .iter() .map(|k| k.strip_common_modifiers(&common_modifiers)) .collect(); + let resize_shortcuts: Vec<KeyWithModifier> = resize_shortcuts + .iter() + .map(|k| k.strip_common_modifiers(&common_modifiers)) + .collect(); let toggle_floating_key_to_display: Vec<KeyWithModifier> = toggle_floating_key_to_display .iter() .map(|k| k.strip_common_modifiers(&common_modifiers)) @@ -818,12 +864,20 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz new_pane_key_to_display, false, )); - secondary_info.append(&add_shortcut_with_inline_key( - help, - "Change Focus", - move_focus_shortcuts, - false, - )); + if should_show_focus_and_resize_shortcuts { + secondary_info.append(&add_shortcut_with_inline_key( + help, + "Change Focus", + move_focus_shortcuts, + false, + )); + secondary_info.append(&add_shortcut_with_inline_key( + help, + "Resize", + resize_shortcuts, + false, + )); + } secondary_info.append(&add_shortcut_with_inline_key( help, "Floating", @@ -844,13 +898,22 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz false, Some(0), )); - short_line.append(&add_shortcut( - help, - "Focus", - &move_focus_shortcuts, - false, - Some(0), - )); + if should_show_focus_and_resize_shortcuts { + short_line.append(&add_shortcut( + help, + "Focus", + &move_focus_shortcuts, + false, + Some(0), + )); + short_line.append(&add_shortcut( + help, + "Resize", + &resize_shortcuts, + false, + Some(0), + )); + } short_line.append(&add_shortcut( help, "Floating", @@ -879,6 +942,10 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz .iter() .map(|k| k.strip_common_modifiers(&common_modifiers)) .collect(); + let resize_shortcuts: Vec<KeyWithModifier> = resize_shortcuts + .iter() + .map(|k| k.strip_common_modifiers(&common_modifiers)) + .collect(); let toggle_floating_key_to_display: Vec<KeyWithModifier> = toggle_floating_key_to_display .iter() @@ -890,12 +957,20 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz new_pane_key_to_display, false, )); - short_line.append(&add_shortcut_with_inline_key( - help, - "Focus", - move_focus_shortcuts, - false, - )); + if should_show_focus_and_resize_shortcuts { + short_line.append(&add_shortcut_with_inline_key( + help, + "Focus", + move_focus_shortcuts, + false, + )); + short_line.append(&add_shortcut_with_inline_key( + help, + "Resize", + resize_shortcuts, + false, + )); + } short_line.append(&add_shortcut_with_inline_key( help, "Floating", @@ -903,7 +978,21 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz are_floating_panes_visible, )); } - short_line + if short_line.len <= max_len { + short_line + } else { + let part = serialize_text( + &Text::new(format!( + "{:>width$}", + "...", + width = max_len.saturating_sub(3) + )) + .color_range(0, ..) + .opaque(), + ); + let len = max_len.saturating_sub(3); + LinePart { part, len } + } } } @@ -982,6 +1071,7 @@ fn add_shortcut_with_inline_key( "←→" => "", "↓↑" => "", "[]" => "", + "+-" => "", _ => "|", }; |
