diff options
| author | Aram Drevekenin <aram@poor.dev> | 2024-04-10 15:26:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-10 15:26:54 +0200 |
| commit | 41dbe65e265dc33a62fcf4dbe869c22d2459b38e (patch) | |
| tree | d3d0672d80c90f1aab5856f8f6b0cf51872176e3 /zellij-utils/src | |
| parent | fix(plugins): various pre-release issues (#3246) (diff) | |
| download | sl0ppij-41dbe65e265dc33a62fcf4dbe869c22d2459b38e.tar.gz sl0ppij-41dbe65e265dc33a62fcf4dbe869c22d2459b38e.tar.xz sl0ppij-41dbe65e265dc33a62fcf4dbe869c22d2459b38e.zip | |
fix(layouts): recover from resurrection crash and pick up swap layouts properly (#3249)
* fix(layouts): recover from issues in the constraint system
* fix(keybinds): pick up swap layouts for new tab keybinding
Diffstat (limited to 'zellij-utils/src')
| -rw-r--r-- | zellij-utils/src/input/layout.rs | 23 | ||||
| -rw-r--r-- | zellij-utils/src/kdl/mod.rs | 11 | ||||
| -rw-r--r-- | zellij-utils/src/pane_size.rs | 2 |
3 files changed, 27 insertions, 9 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 1235f3d2..cef7cebf 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -849,6 +849,7 @@ impl TiledPaneLayout { &self, space: &PaneGeom, max_panes: Option<usize>, + ignore_percent_split_sizes: bool, ) -> Result<Vec<(TiledPaneLayout, PaneGeom)>, &'static str> { let layouts = match max_panes { Some(max_panes) => { @@ -874,9 +875,9 @@ impl TiledPaneLayout { layout_to_split.focus_deepest_pane(); } - split_space(space, &layout_to_split, space)? + split_space(space, &layout_to_split, space, ignore_percent_split_sizes)? }, - None => split_space(space, self, space)?, + None => split_space(space, self, space, ignore_percent_split_sizes)?, }; for (_pane_layout, pane_geom) in layouts.iter() { if !pane_geom.is_at_least_minimum_size() { @@ -1426,6 +1427,7 @@ fn split_space( space_to_split: &PaneGeom, layout: &TiledPaneLayout, total_space_to_split: &PaneGeom, + ignore_percent_split_sizes: bool, ) -> Result<Vec<(TiledPaneLayout, PaneGeom)>, &'static str> { 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); @@ -1440,6 +1442,15 @@ fn split_space( *last_size = None; } sizes + } else if ignore_percent_split_sizes { + layout + .children + .iter() + .map(|part| match part.split_size { + Some(SplitSize::Percent(_)) => None, + split_size => split_size, + }) + .collect() } else { layout.children.iter().map(|part| part.split_size).collect() }; @@ -1539,8 +1550,12 @@ fn split_space( for (i, part) in layout.children.iter().enumerate() { let part_position_and_size = split_geom.get(i).unwrap(); if !part.children.is_empty() { - let mut part_positions = - split_space(part_position_and_size, part, total_space_to_split)?; + let mut part_positions = split_space( + part_position_and_size, + part, + total_space_to_split, + ignore_percent_split_sizes, + )?; pane_positions.append(&mut part_positions); } else { let part = part.clone(); diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index d3794d11..37720b2f 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -860,6 +860,9 @@ impl TryFrom<(&KdlNode, &Options)> for Action { ) })?; + let swap_tiled_layouts = Some(layout.swap_tiled_layouts.clone()); + let swap_floating_layouts = Some(layout.swap_floating_layouts.clone()); + let mut tabs = layout.tabs(); if tabs.len() > 1 { return Err(ConfigError::new_kdl_error( @@ -874,8 +877,8 @@ impl TryFrom<(&KdlNode, &Options)> for Action { Ok(Action::NewTab( Some(layout), floating_panes_layout, - None, - None, + swap_tiled_layouts, + swap_floating_layouts, name, )) } else { @@ -884,8 +887,8 @@ impl TryFrom<(&KdlNode, &Options)> for Action { Ok(Action::NewTab( Some(layout), floating_panes_layout, - None, - None, + swap_tiled_layouts, + swap_floating_layouts, name, )) } diff --git a/zellij-utils/src/pane_size.rs b/zellij-utils/src/pane_size.rs index 16c111b2..fe56e720 100644 --- a/zellij-utils/src/pane_size.rs +++ b/zellij-utils/src/pane_size.rs @@ -122,7 +122,7 @@ impl Dimension { self.inner += by; } pub fn decrease_inner(&mut self, by: usize) { - self.inner -= by; + self.inner = self.inner.saturating_sub(by); } pub fn is_fixed(&self) -> bool { |
