diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-08-02 11:41:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-02 11:41:51 +0200 |
commit | 192e6fd31ece0c73f8962f4af620a2757a2c1a2e (patch) | |
tree | 6ae03596196acf35f6c71cc4dc79c309f2917d8b /zellij-utils | |
parent | 8fb90391c8bb558726c029732ac753318021e144 (diff) |
feat(ui): break pane to new tab and move panes between tabs (#2664)
* prototype
* some tests
* break out floating pane
* break out plugin panes
* add keybind and fix some minor issues
* remove cli
* move pane to left/right tab
* update ui
* adjust ui
* style(fmt): rustfmt
* style(comment): remove commented code
* update snapshots
Diffstat (limited to 'zellij-utils')
57 files changed, 572 insertions, 38 deletions
diff --git a/zellij-utils/assets/config/default.kdl b/zellij-utils/assets/config/default.kdl index 57106681d..32dfb86e0 100644 --- a/zellij-utils/assets/config/default.kdl +++ b/zellij-utils/assets/config/default.kdl @@ -54,6 +54,9 @@ keybinds { bind "n" { NewTab; SwitchToMode "Normal"; } bind "x" { CloseTab; SwitchToMode "Normal"; } bind "s" { ToggleActiveSyncTab; SwitchToMode "Normal"; } + bind "b" { BreakPane; SwitchToMode "Normal"; } + bind "]" { BreakPaneRight; SwitchToMode "Normal"; } + bind "[" { BreakPaneLeft; SwitchToMode "Normal"; } bind "1" { GoToTab 1; SwitchToMode "Normal"; } bind "2" { GoToTab 2; SwitchToMode "Normal"; } bind "3" { GoToTab 3; SwitchToMode "Normal"; } diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index e2e3c244f..df5d02782 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -338,6 +338,9 @@ pub enum ScreenContext { FocusPaneWithId, RenamePane, RenameTab, + BreakPane, + BreakPaneRight, + BreakPaneLeft, } /// Stack call representations corresponding to the different types of [`PtyInstruction`]s. diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index 568c0a2c2..4ed7f029c 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -240,6 +240,9 @@ pub enum Action { RenameTerminalPane(u32, Vec<u8>), RenamePluginPane(u32, Vec<u8>), RenameTab(u32, Vec<u8>), + BreakPane, + BreakPaneRight, + BreakPaneLeft, } impl Action { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 55e5fc69f..39d208e83 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -401,6 +401,7 @@ pub struct FloatingPaneLayout { pub y: Option<PercentOrFixed>, pub run: Option<Run>, pub focus: Option<bool>, + pub already_running: bool, } impl FloatingPaneLayout { @@ -438,6 +439,7 @@ pub struct TiledPaneLayout { pub children_are_stacked: bool, pub is_expanded_in_stack: bool, pub exclude_from_sync: Option<bool>, + pub run_instructions_to_ignore: Vec<Option<Run>>, } impl TiledPaneLayout { @@ -559,8 +561,36 @@ impl TiledPaneLayout { let mut child_run_instructions = child.extract_run_instructions(); run_instructions.append(&mut child_run_instructions); } + let mut successfully_ignored = 0; + for instruction_to_ignore in &self.run_instructions_to_ignore { + if let Some(position) = run_instructions + .iter() + .position(|i| i == instruction_to_ignore) + { + run_instructions.remove(position); + successfully_ignored += 1; + } + } + // we need to do this because if we have an ignored instruction that does not match any + // running instruction, we'll have an extra pane and our state will be messed up and we'll + // crash (this can happen for example when breaking a plugin pane into a new tab that does + // not have room for it but has a terminal instead) + if successfully_ignored < self.run_instructions_to_ignore.len() { + for _ in 0..self + .run_instructions_to_ignore + .len() + .saturating_sub(successfully_ignored) + { + if let Some(position) = run_instructions.iter().position(|i| i == &None) { + run_instructions.remove(position); + } + } + } run_instructions } + pub fn ignore_run_instruction(&mut self, run_instruction: Option<Run>) { + self.run_instructions_to_ignore.push(run_instruction); + } pub fn with_one_pane() -> Self { let mut default_layout = TiledPaneLayout::default(); default_layout.children = vec![TiledPaneLayout::default()]; diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap index d01949514..9d2d9e37e 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1322 +assertion_line: 1352 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -34,6 +34,7 @@ Layout { children_are_stacked: false, is_expanded_in_stack: false, exclude_from_sync: None, + run_instructions_to_ignore: [], }, TiledPaneLayout { children_split_direction: Horizontal, @@ -60,6 +61,7 @@ Layout { children_are_stacked: false, is_expanded_in_stack: false, exclude_from_sync: None, + run_instructions_to_ignore: [], }, ], split_size: None, @@ -70,6 +72,7 @@ Layout { children_are_stacked: false, is_expanded_in_stack: false, exclude_from_sync: None, + run_instructions_to_ignore: [], }, [], ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap index d31f721f0..e8c140421 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1287 +assertion_line: 1317 expression: "format!(\"{:#?} |