Skip to content

Commit

Permalink
fix(stacked-panes): better handling of adding new panes to a stack (#…
Browse files Browse the repository at this point in the history
…4016)

* fix(stacked-panes): better handling of adding new panes to a stack

* style(fmt): rustfmt

* docs(changelog): document
  • Loading branch information
imsnif authored Feb 22, 2025
1 parent 04be264 commit bdfcfb0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* fix(terminal): support setting kitty keyboard protocol with `CSI=` (https://github.com/zellij-org/zellij/pull/3942)
* fix(floating-panes): handle various errors (https://github.com/zellij-org/zellij/pull/3944)
* chore(rust): Update Rust toolchain to 1.84.0 (https://github.com/zellij-org/zellij/pull/3945)
* feat(ux): stacked-resize (https://github.com/zellij-org/zellij/pull/3957, https://github.com/zellij-org/zellij/pull/4003 and https://github.com/zellij-org/zellij/pull/4011)
* feat(ux): stacked-resize (https://github.com/zellij-org/zellij/pull/3957, https://github.com/zellij-org/zellij/pull/4003, https://github.com/zellij-org/zellij/pull/4011 and https://github.com/zellij-org/zellij/pull/4016)
* feat(plugins): API to change the position and size of floating pane, as well as know the viewport size (https://github.com/zellij-org/zellij/pull/3958 and https://github.com/zellij-org/zellij/pull/3972)
* feat(plugins): add `PastedText` event (https://github.com/zellij-org/zellij/pull/3962)
* feat(plugins): APIs to open panes near plugin (https://github.com/zellij-org/zellij/pull/3966)
Expand Down
8 changes: 6 additions & 2 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,12 @@ impl TiledPanes {
self.panes.insert(pane_id, pane); // TODO: is set_geom the right one?
return;
},
Err(e) => {
log::error!("Failed to add pane to stack: {:?}", e);
Err(_e) => {
return self.add_pane_without_stacked_resize(
pane_id,
pane,
should_relayout,
);
},
}
},
Expand Down
9 changes: 6 additions & 3 deletions zellij-server/src/panes/tiled_panes/stacked_panes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{panes::PaneId, tab::Pane};
use crate::{
panes::PaneId,
tab::{Pane, MIN_TERMINAL_HEIGHT},
};
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
Expand Down Expand Up @@ -419,7 +422,7 @@ impl<'a> StackedPanes<'a> {
for stack in all_stacks {
if let Some((id_of_flexible_pane_in_stack, _flexible_pane_in_stack)) = stack
.iter()
.find(|(_p_id, p)| !p.rows.is_fixed() && p.rows.as_usize() > 1)
.find(|(_p_id, p)| !p.rows.is_fixed() && p.rows.as_usize() > MIN_TERMINAL_HEIGHT)
{
self.make_lowest_pane_in_stack_flexible(id_of_flexible_pane_in_stack)?;
let all_stacked_pane_positions =
Expand Down Expand Up @@ -452,7 +455,7 @@ impl<'a> StackedPanes<'a> {
let stack = self.positions_in_stack(pane_id).with_context(err_context)?;
if let Some((id_of_flexible_pane_in_stack, _flexible_pane_in_stack)) = stack
.iter()
.find(|(_p_id, p)| !p.rows.is_fixed() && p.rows.as_usize() > 1)
.find(|(_p_id, p)| !p.rows.is_fixed() && p.rows.as_usize() > MIN_TERMINAL_HEIGHT)
{
self.make_lowest_pane_in_stack_flexible(id_of_flexible_pane_in_stack)?;
let all_stacked_pane_positions =
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ impl<'a> TiledPaneGrid<'a> {
.collect();
flexible_pane_in_stack
.iter()
.any(|(_p_id, p)| p.current_geom().rows.as_usize() > 1)
.any(|(_p_id, p)| p.current_geom().rows.as_usize() > MIN_TERMINAL_HEIGHT)
}
pub fn make_room_in_stack_for_pane(&mut self) -> Result<PaneGeom> {
StackedPanes::new(self.panes.clone()).make_room_for_new_pane()
Expand Down
11 changes: 8 additions & 3 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ impl Tab {
.swap_layouts
.swap_tiled_panes(&self.tiled_panes, search_backwards)
{
LayoutApplier::new(
let application_res = LayoutApplier::new(
&self.viewport,
&self.senders,
&self.sixel_image_store,
Expand All @@ -846,8 +846,13 @@ impl Tab {
self.styled_underlines,
self.explicitly_disable_kitty_keyboard_protocol,
)
.apply_tiled_panes_layout_to_existing_panes(&layout_candidate)
.non_fatal();
.apply_tiled_panes_layout_to_existing_panes(&layout_candidate);
if application_res.is_err() {
self.swap_layouts.set_is_tiled_damaged();
application_res.non_fatal();
}
} else {
self.swap_layouts.set_is_tiled_damaged();
}
self.tiled_panes.reapply_pane_frames();
let display_area = *self.display_area.borrow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 3636
assertion_line: 3649
expression: "format!(\"{}\", snapshot)"
---
00 (C): ┌ pane_to_break_free ──────────────────┐┌ pane_to_stay ────────────────────────┐
00 (C): ┌ pane_to_stay ────────────────────────┐┌ pane_to_break_free ──────────────────┐
01 (C): │ ││ │
02 (C): │ ││ │
03 (C): │ ││ │
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 3587
assertion_line: 3601
expression: "format!(\"{}\", snapshot)"
---
00 (C): ┌ pane_to_break_free ──────────────────┐┌ pane_to_stay ────────────────────────┐
00 (C): ┌ pane_to_stay ────────────────────────┐┌ pane_to_break_free ──────────────────┐
01 (C): │ ││ │
02 (C): │ ││ │
03 (C): │ ││ │
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 2569
assertion_line: 2583
expression: "format!(\"{}\", snapshot)"
---
00 (C): ┌ Pane #1 ─────────────────────────────┐┌ Pane #2 ─────────────────────────────┐
00 (C): ┌ Pane #2 ─────────────────────────────┐┌ Pane #1 ─────────────────────────────┐
01 (C): │ ││ │
02 (C): │ ││ │
03 (C): │ ││ │
Expand Down
4 changes: 4 additions & 0 deletions zellij-utils/src/input/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,10 @@ fn split_space(
} else if let Some(last_size) = sizes.last_mut() {
*last_size = None;
}
if sizes.len() > space_to_split.rows.as_usize().saturating_sub(4) {
// 4 is MIN_TERMINAL_HEIGHT
return Err("Not enough room for stacked panes in this layout");
}
sizes
} else if ignore_percent_split_sizes {
layout
Expand Down

0 comments on commit bdfcfb0

Please sign in to comment.