diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-04-03 18:04:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 18:04:06 +0200 |
commit | 3a428effed2327b8f82bd8cd328f385032e5bc06 (patch) | |
tree | b100fa9b9bb49583e8efee7567973ded1e8b87ae /zellij-utils | |
parent | 63d6711a8dad531b3188b32fa19642c76cb7eec6 (diff) |
feat(panes): allow defining an expanded stacked pane (#2343)
* feat(panes): allow defining an expanded stacked pane
* style(fmt): rustfmt
Diffstat (limited to 'zellij-utils')
47 files changed, 507 insertions, 41 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 78db7ce51..a07e1d313 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -394,6 +394,7 @@ pub struct TiledPaneLayout { pub focus: Option<bool>, pub external_children_index: Option<usize>, pub children_are_stacked: bool, + pub is_expanded_in_stack: bool, } impl TiledPaneLayout { @@ -865,12 +866,15 @@ fn split_space( ) -> Result<Vec<(TiledPaneLayout, PaneGeom)>, &'static str> { let mut pane_positions = Vec::new(); let sizes: Vec<Option<SplitSize>> = if layout.children_are_stacked { + let index_of_expanded_pane = layout.children.iter().position(|p| p.is_expanded_in_stack); let mut sizes: Vec<Option<SplitSize>> = layout .children .iter() .map(|_part| Some(SplitSize::Fixed(1))) .collect(); - if let Some(last_size) = sizes.last_mut() { + if let Some(index_of_expanded_pane) = index_of_expanded_pane { + *sizes.get_mut(index_of_expanded_pane).unwrap() = None; + } else if let Some(last_size) = sizes.last_mut() { *last_size = None; } sizes diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index 237cf978c..7ff2567a9 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -1882,6 +1882,21 @@ fn can_define_stacked_children_for_pane_template() { } #[test] +fn can_define_a_stack_with_an_expanded_pane() { + let kdl_layout = r#" + layout { + pane stacked=true { + pane + pane expanded=true + pane + } + } + "#; + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + assert_snapshot!(format!("{:#?}", layout)); +} + +#[test] fn cannot_define_stacked_panes_for_bare_node() { let kdl_layout = r#" layout { @@ -1893,6 +1908,20 @@ fn cannot_define_stacked_panes_for_bare_node() { } #[test] +fn cannot_define_an_expanded_pane_outside_of_a_stack() { + let kdl_layout = r#" + layout { + pane { + pane + pane expanded=true + } + } + "#; + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None); + assert!(layout.is_err(), "error provided for tab name with space"); +} + +#[test] fn cannot_define_stacked_panes_with_vertical_split_direction() { let kdl_layout = r#" layout { 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 799908327..65450c122 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: 1266 +assertion_line: 1322 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -32,6 +32,7 @@ Layout { focus: None, external_children_index: None, children_are_stacked: false, + is_expanded_in_stack: false, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -56,6 +57,7 @@ Layout { focus: None, external_children_index: None, children_are_stacked: false, + is_expanded_in_stack: false, }, ], split_size: None, @@ -64,6 +66,7 @@ Layout { focus: None, external_children_index: None, children_are_stacked: false, + is_expanded_in_stack: false, }, [], ), 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 bb691fe76..5db6198b3 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: 1231 +assertion_line: 1287 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -35,6 +35,7 @@ Layout { focus: None, external_children_index: None, children_are_stacked: false, + is_expanded_in_stack: false, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -59,6 +60,7 @@ Layout { focus: None, external_children_index: None, children_are_stacked: false, + is_expanded_in_stack: false, }, ], split_size: None, @@ -67,6 +69,7 @@ Layout { focus: None, external_children_index: None, children_are_stacked: false, + is_expanded_in_stack: false, }, [], ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__can_define_a_stack_with_an_expanded_pane.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__can_define_a_stack_with_an_expanded_pane.snap new file mode 100644 index 000000000..92e0e4365 --- /dev/null +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__can_define_a_stack_with_an_expanded_pane.snap @@ -0,0 +1,79 @@ +--- +source: zellij-utils/src/input/./unit/layout_test.rs +assertion_line: 1896 +expression: "format!(\"{:#?}\", layout)" +--- +Layout { + tabs: [], + focused_tab_index: None, + template: Some( + ( + TiledPaneLayout { + children_split_direction: Horizontal, + name: None, + children: [ + TiledPaneLayout { + children_split_direction: Horizontal, + name: None, + children: [ + TiledPaneLayout { + children_split_direction: Horizontal, + name: None, + children: [], + split_size: None, + run: None, + borderless: false, + focus: None, + external_children_index: None, + children_are_stacked: false, + is_expanded_in_stack: false, + }, + TiledPaneLayout { + children_split_direction: Horizontal, + name: None, + children: [], + split_size: None, + run: None, + borderless: false, + focus: None, + external_children_index: None, + children_are_stacked: false, + is_expanded_in_stack: true, + }, + TiledPaneLayout { + children_split_direction: Horizontal, + name: None, + children: [], + split_size: None, + run: None, + borderless: false, + focus: None, + external_children_index: None, + children_are_stacked: false, + is_expanded_in_stack: false, + }, + ], + split_size: None, + run: None, + borderless: false, + focus: None, + external_children_index: None, + children_are_stacked: true, + is_expanded_in_stack: false, + }, + ], + split_size: None, + run: None, + borderless: false, + focus: None, + external_children_index: None, + children_are_stacked: false, + is_expanded_in_stack: false, + }, + [], + ), + ), + swap_layouts: [], + swap_tiled_layouts: [], + swap_floating_layouts: [], +} diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__can_define_stacked_children_for_pane_node.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__can_define_stacked_children_for_pane_node.snap index 74a872bcf..c9aa7f872 100644 --- a/ |