Skip to content

Commit

Permalink
feat(ui): resize shortcuts (#4003)
Browse files Browse the repository at this point in the history
* feat(ui): show resize and focus shortcuts when relevant

* update serialization and snapshots

* update e2e tests

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Feb 18, 2025
1 parent 5b6a0e6 commit 544982d
Show file tree
Hide file tree
Showing 52 changed files with 241 additions and 89 deletions.
144 changes: 117 additions & 27 deletions default-plugins/status-bar/src/one_line_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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![];

Expand Down Expand Up @@ -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()
Expand All @@ -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",
Expand Down Expand Up @@ -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))
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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()
Expand All @@ -890,20 +957,42 @@ 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",
toggle_floating_key_to_display,
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 }
}
}
}

Expand Down Expand Up @@ -982,6 +1071,7 @@ fn add_shortcut_with_inline_key(
"←→" => "",
"↓↑" => "",
"[]" => "",
"+-" => "",
_ => "|",
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 1975
assertion_line: 2000
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Expand All @@ -26,4 +26,4 @@ expression: last_snapshot
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 243
assertion_line: 239
expression: last_snapshot
---
Zellij
Expand All @@ -22,4 +22,4 @@ expression: last_snapshot
│ │
│ │
└──────┘
Ctrl +
...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 707
assertion_line: 714
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Expand All @@ -26,4 +26,4 @@ expression: last_snapshot
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 1138
assertion_line: 1154
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Expand All @@ -26,4 +26,4 @@ expression: last_snapshot
│ ││ │
│ ││ │
└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 1352
assertion_line: 1373
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Expand All @@ -26,4 +26,4 @@ expression: last_snapshot
│ ││ │
│ ││ │
└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 2426
assertion_line: 2424
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Expand All @@ -26,4 +26,4 @@ expression: last_snapshot
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl gUNLOCKAlt +  <n> New Pane  <←↓↑→> Change Focus  <f> Floating 
Ctrl gUNLOCK Alt +  <n> New Pane  <f> Floating 
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 1624
assertion_line: 1650
expression: first_runner_snapshot
---
Zellij (mirrored_sessions)  Tab #1  Tab #2
Expand All @@ -26,4 +26,4 @@ expression: first_runner_snapshot
│ ││ │
│ ││ │
└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 558
assertion_line: 562
expression: account_for_races_in_snapshot(last_snapshot)
---
Zellij (e2e-test)  Tab #1  Tab #3  Tab #2
Expand All @@ -26,4 +26,4 @@ expression: account_for_races_in_snapshot(last_snapshot)
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 620
assertion_line: 624
expression: account_for_races_in_snapshot(last_snapshot)
---
Zellij (e2e-test)  Tab #2  Tab #1  Tab #3
Expand All @@ -26,4 +26,4 @@ expression: account_for_races_in_snapshot(last_snapshot)
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 592
assertion_line: 596
expression: account_for_races_in_snapshot(last_snapshot)
---
Zellij (e2e-test)  Tab #1  Tab #3  Tab #2
Expand All @@ -26,4 +26,4 @@ expression: account_for_races_in_snapshot(last_snapshot)
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 644
assertion_line: 648
expression: account_for_races_in_snapshot(last_snapshot)
---
Zellij (e2e-test)  Tab #3  Tab #2  Tab #1
Expand All @@ -26,4 +26,4 @@ expression: account_for_races_in_snapshot(last_snapshot)
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  ...
Loading

0 comments on commit 544982d

Please sign in to comment.