Skip to content

Commit

Permalink
Reimplement resize code (#1990)
Browse files Browse the repository at this point in the history
* server/floating_panes: Start removing `unwrap`s

* server/panes: Remove more `unwrap`s

in floating panes code.

* utils/data: Unify `Direction` type

which was previously present in multiple locations.
Also start working on a new Resize Method (type `ResizeStrategy`), to
remove code duplication in the resize code.

* server: Implement new resize handling

with the `ResizeStrategy` type. Add a new action with the ability to
invoke it from the CLI. Take care to maintain backwards-compatibility in
terms of configuring the new resize mode.

* utils/layout: Add conversion for SplitDirection

from `data::Direction`.

* utils/data: Add impl for `Direction`

* server/panes: Rework tiled pane resizing

but it's currently still broken in a few regards and misses ability to
perform "regular" increase/decrease.

* server/panes/tiled_panes: Add debug assertion

to catch if the total area of all panes (in percent) is different from
100.0 at some point.

* server/panes/tiled/grid: Fix resize bug

caused by the fact that neighboring plugin panes previously weren't
filtered from resize operations, even though they cannot be resized at
all.

* utils/data: Add `invert` for `Resize`

* utils/data: Add member to `ResizeStrategy`

that controls whether we invert resize behavior when increasing size
towards a bounadry. This maintains current behavior.

* server/screen: Handle new attribute

in `ResizeStrategy`

* server/panes/resizer: Return `anyhow::Error`

* server/panes/tiled: Implement resize increase/decrease

without specifying a direction (towards all possible directions).
Currently broken in some cases.

* server/pane/tiled/grid: Don't return early

to preserve resize debug assertions.

* server/pane/tiled/grid: Fix resize bug

caused by checking for the wrong alignments in some cases. Also refactor
the code for looking up aligned panes.

* server/panes/tiled/grid: Cleanup code

and remove log statements and unused functions.

* server/panes/float/grid: Invert resize

if the floating pane is hitting a boundary already.

* plugins/status-bar: Add hints for new resize

* server: Use new resize method

* server: Fix tests

with new functions and result types.

* apply rustfmt

* utils: Apply rustfmt

* server/panes/floating: Fix resize increase

behavior which would previously, upon hitting a boundary, cause the pane
to invert the resize operation, which is wrong. Instead, it now does not
resize floating panes on an undirected resize "increase" in directions
where it hits boundaries.

* server/panes/tiled: Use correct resize increments

The values for the resize increments were previously wrong, causing many
of the tests to fail.

* server/panes/tiled: Fix resize checks

to correctly consider fixed-size panes.

* utils/assets/config: Update default config

with new keybindings for resize mode.

* server/panes/tiled: Fix resize check

* server/panes/tiled: Use shortener for `Direction`

type in `change_pane_size` function.

* server/panes/tiled: Restore resize behavior

for undirected resizes, to the way it was before this PR.

* server/panes/floating: Fix resize increment

for undirected resizes

* utils/data: Fix doctest

* utils: Fix test snapshots

for tests working with the default config

* changelog: Add PR #1990
  • Loading branch information
har7an authored Dec 8, 2022
1 parent 420c7c3 commit 62eaea1
Show file tree
Hide file tree
Showing 31 changed files with 2,206 additions and 2,416 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* refactor(messaging): reduce extraneous cross-thread messaging (https://github.com/zellij-org/zellij/pull/1996)
* errors: preserve caller location in `to_log` (https://github.com/zellij-org/zellij/pull/1994)
* feat: show loading screen on startup (https://github.com/zellij-org/zellij/pull/1997)
* feat: Allow "reducing" resizes, refactor resizing code (https://github.com/zellij-org/zellij/pull/1990)

## [0.33.0] - 2022-11-10

Expand Down
2 changes: 2 additions & 0 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ pub fn action_key_group(keymap: &[(Key, Vec<Action>)], actions: &[&[Action]]) ->
/// separator between them:
///
/// - "hjkl"
/// - "HJKL"
/// - "←↓↑→"
/// - "←→"
/// - "↓↑"
Expand Down Expand Up @@ -423,6 +424,7 @@ pub fn style_key_with_modifier(keyvec: &[Key], palette: &Palette) -> Vec<ANSIStr
// Special handling of some pre-defined keygroups
let key_string = key.join("");
let key_separator = match &key_string[..] {
"HJKL" => "",
"hjkl" => "",
"←↓↑→" => "",
"←→" => "",
Expand Down
65 changes: 29 additions & 36 deletions default-plugins/status-bar/src/second_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ fn full_shortcut_list_nonstandard_mode(help: &ModeInfo) -> LinePart {
fn get_keys_and_hints(mi: &ModeInfo) -> Vec<(String, String, Vec<Key>)> {
use Action as A;
use InputMode as IM;
use actions::Direction as Dir;
use actions::ResizeDirection as RDir;
use Direction as Dir;
use actions::SearchDirection as SDir;
use actions::SearchOption as SOpt;

Expand Down Expand Up @@ -188,11 +187,23 @@ fn get_keys_and_hints(mi: &ModeInfo) -> Vec<(String, String, Vec<Key>)> {
(s("Toggle"), s("Toggle"), action_key(&km, &[A::ToggleTab])),
(s("Select pane"), s("Select"), to_normal_key),
]} else if mi.mode == IM::Resize { vec![
(s("Resize"), s("Resize"), action_key_group(&km, &[
&[A::Resize(RDir::Left)], &[A::Resize(RDir::Down)],
&[A::Resize(RDir::Up)], &[A::Resize(RDir::Right)]])),
(s("Increase to"), s("Increase"), action_key_group(&km, &[
&[A::Resize(Resize::Increase, Some(Dir::Left))],
&[A::Resize(Resize::Increase, Some(Dir::Down))],
&[A::Resize(Resize::Increase, Some(Dir::Up))],
&[A::Resize(Resize::Increase, Some(Dir::Right))]
])),
(s("Decrease from"), s("Decrease"), action_key_group(&km, &[
&[A::Resize(Resize::Decrease, Some(Dir::Left))],
&[A::Resize(Resize::Decrease, Some(Dir::Down))],
&[A::Resize(Resize::Decrease, Some(Dir::Up))],
&[A::Resize(Resize::Decrease, Some(Dir::Right))]
])),
(s("Increase/Decrease size"), s("Increase/Decrease"),
action_key_group(&km, &[&[A::Resize(RDir::Increase)], &[A::Resize(RDir::Decrease)]])),
action_key_group(&km, &[
&[A::Resize(Resize::Increase, None)],
&[A::Resize(Resize::Decrease, None)]
])),
(s("Select pane"), s("Select"), to_normal_key),
]} else if mi.mode == IM::Move { vec![
(s("Move"), s("Move"), action_key_group(&km, &[
Expand Down Expand Up @@ -666,13 +677,10 @@ mod tests {
keybinds: vec![(
InputMode::Pane,
vec![
(Key::Left, vec![Action::MoveFocus(actions::Direction::Left)]),
(Key::Down, vec![Action::MoveFocus(actions::Direction::Down)]),
(Key::Up, vec![Action::MoveFocus(actions::Direction::Up)]),
(
Key::Right,
vec![Action::MoveFocus(actions::Direction::Right)],
),
(Key::Left, vec![Action::MoveFocus(Direction::Left)]),
(Key::Down, vec![Action::MoveFocus(Direction::Down)]),
(Key::Up, vec![Action::MoveFocus(Direction::Up)]),
(Key::Right, vec![Action::MoveFocus(Direction::Right)]),
(Key::Char('n'), vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Char('x'), vec![Action::CloseFocus, TO_NORMAL]),
(
Expand Down Expand Up @@ -701,13 +709,10 @@ mod tests {
keybinds: vec![(
InputMode::Pane,
vec![
(Key::Left, vec![Action::MoveFocus(actions::Direction::Left)]),
(Key::Down, vec![Action::MoveFocus(actions::Direction::Down)]),
(Key::Up, vec![Action::MoveFocus(actions::Direction::Up)]),
(
Key::Right,
vec![Action::MoveFocus(actions::Direction::Right)],
),
(Key::Left, vec![Action::MoveFocus(Direction::Left)]),
(Key::Down, vec![Action::MoveFocus(Direction::Down)]),
(Key::Up, vec![Action::MoveFocus(Direction::Up)]),
(Key::Right, vec![Action::MoveFocus(Direction::Right)]),
(Key::Char('n'), vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Char('x'), vec![Action::CloseFocus, TO_NORMAL]),
(
Expand All @@ -732,22 +737,10 @@ mod tests {
keybinds: vec![(
InputMode::Pane,
vec![
(
Key::Ctrl('a'),
vec![Action::MoveFocus(actions::Direction::Left)],
),
(
Key::Ctrl('\n'),
vec![Action::MoveFocus(actions::Direction::Down)],
),
(
Key::Ctrl('1'),
vec![Action::MoveFocus(actions::Direction::Up)],
),
(
Key::Ctrl(' '),
vec![Action::MoveFocus(actions::Direction::Right)],
),
(Key::Ctrl('a'), vec![Action::MoveFocus(Direction::Left)]),
(Key::Ctrl('\n'), vec![Action::MoveFocus(Direction::Down)]),
(Key::Ctrl('1'), vec![Action::MoveFocus(Direction::Up)]),
(Key::Ctrl(' '), vec![Action::MoveFocus(Direction::Right)]),
(Key::Backspace, vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Esc, vec![Action::CloseFocus, TO_NORMAL]),
(Key::End, vec![Action::ToggleFocusFullscreen, TO_NORMAL]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use ansi_term::{unstyled_len, ANSIString, ANSIStrings, Style};

use crate::{action_key_group, style_key_with_modifier, LinePart};
use zellij_tile::prelude::{
actions::{Action, Direction},
*,
};
use zellij_tile::prelude::{actions::Action, *};

macro_rules! strings {
($ANSIStrings:expr) => {{
Expand Down
9 changes: 3 additions & 6 deletions default-plugins/status-bar/src/tip/data/quicknav.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use ansi_term::{unstyled_len, ANSIString, ANSIStrings, Style};

use crate::{action_key, action_key_group, style_key_with_modifier, LinePart};
use zellij_tile::prelude::{
actions::{Action, Direction, ResizeDirection},
*,
};
use zellij_tile::prelude::{actions::Action, *};

macro_rules! strings {
($ANSIStrings:expr) => {{
Expand Down Expand Up @@ -75,8 +72,8 @@ fn add_keybinds(help: &ModeInfo) -> Keygroups {
let mut resize_keys = action_key_group(
&normal_keymap,
&[
&[Action::Resize(ResizeDirection::Increase)],
&[Action::Resize(ResizeDirection::Decrease)],
&[Action::Resize(Resize::Increase, None)],
&[Action::Resize(Resize::Decrease, None)],
],
);
if resize_keys.contains(&Key::Alt(CharOrArrow::Char('=')))
Expand Down
4 changes: 2 additions & 2 deletions zellij-client/src/unit/stdin_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::input_loop;
use crate::stdin_ansi_parser::StdinAnsiParser;
use crate::stdin_loop;
use zellij_utils::anyhow::Result;
use zellij_utils::data::{InputMode, Palette};
use zellij_utils::input::actions::{Action, Direction};
use zellij_utils::data::{Direction, InputMode, Palette};
use zellij_utils::input::actions::Action;
use zellij_utils::input::config::Config;
use zellij_utils::input::options::Options;
use zellij_utils::nix;
Expand Down
Loading

0 comments on commit 62eaea1

Please sign in to comment.