summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-02-27 19:15:45 +0100
committerGitHub <noreply@github.com>2023-02-27 19:15:45 +0100
commitb3b0ddbab82ab74c02dbc991b24f4a3c88f2bcbe (patch)
treedbfb33b8f2a737918a913fc4ef557406708dfa3e
parent4d1b12754363306ecbdcdba52986b7e92fc522c3 (diff)
fix(layouts): do not relayout twice on auto_layout (#2202)
* fix(layouts): do not relayout twice on auto_layout * style(fmt): rustfmt
-rw-r--r--zellij-server/src/panes/tiled_panes/mod.rs38
-rw-r--r--zellij-server/src/tab/layout_applier.rs4
-rw-r--r--zellij-server/src/tab/mod.rs12
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_non_directionally.snap8
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_vertically.snap8
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_non_directionally.snap8
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_vertically.snap8
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__increasing_size_into_main_pane_in_stack_horizontally_does_not_break_stack.snap12
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__move_focus_left_into_stacked_panes.snap12
-rw-r--r--zellij-server/src/tab/unit/tab_integration_tests.rs179
10 files changed, 67 insertions, 222 deletions
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs
index 8ab5cb4f9..28941746e 100644
--- a/zellij-server/src/panes/tiled_panes/mod.rs
+++ b/zellij-server/src/panes/tiled_panes/mod.rs
@@ -160,7 +160,27 @@ impl TiledPanes {
self.move_clients_between_panes(pane_id, with_pane_id);
removed_pane
}
- pub fn insert_pane(&mut self, pane_id: PaneId, mut pane: Box<dyn Pane>) {
+ pub fn insert_pane(&mut self, pane_id: PaneId, pane: Box<dyn Pane>) {
+ let should_relayout = true;
+ self.add_pane(pane_id, pane, should_relayout);
+ }
+ pub fn insert_pane_without_relayout(&mut self, pane_id: PaneId, pane: Box<dyn Pane>) {
+ let should_relayout = false;
+ self.add_pane(pane_id, pane, should_relayout);
+ }
+ pub fn has_room_for_new_pane(&mut self) -> bool {
+ let cursor_height_width_ratio = self.cursor_height_width_ratio();
+ let pane_grid = TiledPaneGrid::new(
+ &mut self.panes,
+ &self.panes_to_hide,
+ *self.display_area.borrow(),
+ *self.viewport.borrow(),
+ );
+ pane_grid
+ .find_room_for_new_pane(cursor_height_width_ratio)
+ .is_some()
+ }
+ fn add_pane(&mut self, pane_id: PaneId, mut pane: Box<dyn Pane>, should_relayout: bool) {
let cursor_height_width_ratio = self.cursor_height_width_ratio();
let pane_grid = TiledPaneGrid::new(
&mut self.panes,
@@ -178,22 +198,12 @@ impl TiledPanes {
pane_to_split.set_geom(first_geom);
pane.set_geom(second_geom);
self.panes.insert(pane_id, pane);
- self.relayout(!split_direction);
+ if should_relayout {
+ self.relayout(!split_direction);
+ }
}
}
}
- pub fn has_room_for_new_pane(&mut self) -> bool {
- let cursor_height_width_ratio = self.cursor_height_width_ratio();
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- &self.panes_to_hide,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid
- .find_room_for_new_pane(cursor_height_width_ratio)
- .is_some()
- }
pub fn fixed_pane_geoms(&self) -> Vec<Viewport> {
self.panes
.values()
diff --git a/zellij-server/src/tab/layout_applier.rs b/zellij-server/src/tab/layout_applier.rs
index eed7f8c86..b2c3817bf 100644
--- a/zellij-server/src/tab/layout_applier.rs
+++ b/zellij-server/src/tab/layout_applier.rs
@@ -609,7 +609,7 @@ impl ExistingTabState {
default_to_closest_position: bool,
) -> Vec<(&PaneId, &Box<dyn Pane>)> {
let mut candidates: Vec<_> = self.existing_panes.iter().collect();
- candidates.sort_by(|(_a_id, a), (_b_id, b)| {
+ candidates.sort_by(|(a_id, a), (b_id, b)| {
let a_invoked_with = a.invoked_with();
let b_invoked_with = b.invoked_with();
if Run::is_same_category(run, a_invoked_with)
@@ -637,7 +637,7 @@ impl ExistingTabState {
let b_y_distance = abs(b.position_and_size().y, position_and_size.y);
(a_x_distance + a_y_distance).cmp(&(b_x_distance + b_y_distance))
} else {
- std::cmp::Ordering::Equal
+ a_id.cmp(&b_id) // just so it's a stable sort
}
}
});
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs
index 9e11fdfdf..bcd549ccc 100644
--- a/zellij-server/src/tab/mod.rs
+++ b/zellij-server/src/tab/mod.rs
@@ -1017,6 +1017,7 @@ impl Tab {
if self.tiled_panes.fullscreen_is_active() {
self.tiled_panes.unset_fullscreen();
}
+ let should_auto_layout = self.auto_layout && !self.swap_layouts.is_tiled_damaged();
if self.tiled_panes.has_room_for_new_pane() {
if let PaneId::Terminal(term_pid) = pid {
let next_terminal_position = self.get_next_terminal_position();
@@ -1035,14 +1036,21 @@ impl Tab {
None,
);
new_terminal.set_active_at(Instant::now());
- self.tiled_panes.insert_pane(pid, Box::new(new_terminal));
+ if should_auto_layout {
+ // no need to relayout here, we'll do it when reapplying the swap layout
+ // below
+ self.tiled_panes
+ .insert_pane_without_relayout(pid, Box::new(new_terminal));
+ } else {
+ self.tiled_panes.insert_pane(pid, Box::new(new_terminal));
+ }
self.should_clear_display_before_rendering = true;
if let Some(client_id) = client_id {
self.tiled_panes.focus_pane(pid, client_id);
}
}
}
- if self.auto_layout && !self.swap_layouts.is_tiled_damaged() {
+ if should_auto_layout {
// only do this if we're already in this layout, otherwise it might be
// confusing and not what the user intends
self.swap_layouts.set_is_tiled_damaged(); // we do this so that we won't skip to the
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_non_directionally.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_non_directionally.snap
index 997af6c2f..bb6bcaab9 100644
--- a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_non_directionally.snap
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_non_directionally.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/tab/./unit/tab_integration_tests.rs
-assertion_line: 4062
+assertion_line: 4299
expression: snapshot
---
00 (C): ┌ Pane #1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -17,8 +17,8 @@ expression: snapshot
11 (C): │ │
12 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
13 (C): ┌ Pane #2 ────────────────────────────────────────────────────────┐┌ Pane #4 ───────────────────────────────────────────┐
-14 (C): │ │┌ Pane #5 ───────────────────────────────────────────┐
-15 (C): │ │┌ Pane #6 ───────────────────────────────────────────┐
+14 (C): │ │┌ Pane #3 ───────────────────────────────────────────┐
+15 (C): │ │┌ Pane #5 ───────────────────────────────────────────┐
16 (C): │ ││ │
17 (C): │ ││ │
18 (C): │ ││ │
@@ -31,7 +31,7 @@ expression: snapshot
25 (C): │ ││ │
26 (C): │ ││ │
27 (C): └─────────────────────────────────────────────────────────────────┘└────────────────────────────────────────────────────┘
-28 (C): ┌ Pane #3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+28 (C): ┌ Pane #6 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
29 (C): │ │
30 (C): │ │
31 (C): │ │
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_vertically.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_vertically.snap
index b800c6344..644233cd1 100644
--- a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_vertically.snap
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_into_pane_stack_vertically.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/tab/./unit/tab_integration_tests.rs
-assertion_line: 4047
+assertion_line: 4237
expression: snapshot
---
00 (C): ┌ Pane #1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -17,8 +17,8 @@ expression: snapshot
11 (C): │ │
12 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
13 (C): ┌ Pane #2 ──────────────────────────────────────────────────┐┌ Pane #4 ─────────────────────────────────────────────────┐
-14 (C): │ │┌ Pane #5 ─────────────────────────────────────────────────┐
-15 (C): │ │┌ Pane #6 ─────────────────────────────────────────────────┐
+14 (C): │ │┌ Pane #3 ─────────────────────────────────────────────────┐
+15 (C): │ │┌ Pane #5 ─────────────────────────────────────────────────┐
16 (C): │ ││ │
17 (C): │ ││ │
18 (C): │ ││ │
@@ -28,7 +28,7 @@ expression: snapshot
22 (C): │ ││ │
23 (C): │ ││ │
24 (C): └───────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
-25 (C): ┌ Pane #3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+25 (C): ┌ Pane #6 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
26 (C): │ │
27 (C): │ │
28 (C): │ │
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_non_directionally.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_non_directionally.snap
index bcd3b4ee9..ac85d9c1a 100644
--- a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_non_directionally.snap
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_non_directionally.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/tab/./unit/tab_integration_tests.rs
-assertion_line: 3823
+assertion_line: 4024
expression: snapshot
---
00 (C): ┌ Pane #1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -17,8 +17,8 @@ expression: snapshot
11 (C): │ │
12 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
13 (C): ┌ Pane #2 ───────────────────────────────────────────┐┌ Pane #4 ────────────────────────────────────────────────────────┐
-14 (C): │ │┌ Pane #5 ────────────────────────────────────────────────────────┐
-15 (C): │ │┌ Pane #6 ────────────────────────────────────────────────────────┐
+14 (C): │ │┌ Pane #3 ────────────────────────────────────────────────────────┐
+15 (C): │ │┌ Pane #5 ────────────────────────────────────────────────────────┐
16 (C): │ ││ │
17 (C): │ ││ │
18 (C): │ ││ │
@@ -31,7 +31,7 @@ expression: snapshot
25 (C): │ ││ │
26 (C): │ ││ │
27 (C): └────────────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────────┘
-28 (C): ┌ Pane #3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+28 (C): ┌ Pane #6 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
29 (C): │ │
30 (C): │ │
31 (C): │ │
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_vertically.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_vertically.snap
index b5dea0aa6..a18772aca 100644
--- a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_vertically.snap
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__can_increase_size_of_main_pane_in_stack_vertically.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/tab/./unit/tab_integration_tests.rs
-assertion_line: 3807
+assertion_line: 3961
expression: snapshot
---
00 (C): ┌ Pane #1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -17,8 +17,8 @@ expression: snapshot
11 (C): │ │
12 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
13 (C): ┌ Pane #2 ──────────────────────────────────────────────────┐┌ Pane #4 ─────────────────────────────────────────────────┐
-14 (C): │ │┌ Pane #5 ─────────────────────────────────────────────────┐
-15 (C): │ │┌ Pane #6 ─────────────────────────────────────────────────┐
+14 (C): │ │┌ Pane #3 ─────────────────────────────────────────────────┐
+15 (C): │ │┌ Pane #5 ─────────────────────────────────────────────────┐
16 (C): │ ││ │
17 (C): │ ││ │
18 (C): │ ││ │
@@ -31,7 +31,7 @@ expression: snapshot
25 (C): │ ││ │
26 (C): │ ││ │
27 (C): └───────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
-28 (C): ┌ Pane #3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+28 (C): ┌ Pane #6 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
29 (C): │ │
30 (C): │ │
31 (C): │ │
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__increasing_size_into_main_pane_in_stack_horizontally_does_not_break_stack.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__increasing_size_into_main_pane_in_stack_horizontally_does_not_break_stack.snap
index 417fe7cdd..2302f121a 100644
--- a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__increasing_size_into_main_pane_in_stack_horizontally_does_not_break_stack.snap
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__increasing_size_into_main_pane_in_stack_horizontally_does_not_break_stack.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/tab/./unit/tab_integration_tests.rs
-assertion_line: 4178
+assertion_line: 4384
expression: snapshot
---
00 (C): ┌ Pane #1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -17,11 +17,11 @@ expression: snapshot
11 (C): │ │
12 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
13 (C): ┌ Pane #2 ────────────────────────────────────────────────────────┐┌ Pane #4 ───────────────────────────────────────────┐
-14 (C): │ │┌ Pane #6 ───────────────────────────────────────────┐
-15 (C): │ │┌ Pane #7 ───────────────────────────────────────────┐
-16 (C): │ │┌ Pane #8 ───────────────────────────────────────────┐
+14 (C): │ │┌ Pane #5 ───────────────────────────────────────────┐
+15 (C): │ │┌ Pane #6 ───────────────────────────────────────────┐
+16 (C): │ │┌ Pane #7 ───────────────────────────────────────────┐
17 (C): │ │┌ Pane #9 ───────────────────────────────────────────┐
-18 (C): │ │┌ Pane #10 ──────────────────────────────────────────┐
+18 (C): │ │┌ Pane #8 ───────────────────────────────────────────┐
19 (C): └─────────────────────────────────────────────────────────────────┘┌ Pane #11 ──────────────────────────────────────────┐
20 (C): ┌ Pane #3 ────────────────────────────────────────────────────────┐│ │
21 (C): │ ││ │
@@ -30,7 +30,7 @@ expression: snapshot
24 (C): │ ││ │
25 (C): │ ││ │
26 (C): └─────────────────────────────