Skip to content

Commit

Permalink
fix(layouts): do not relayout twice on auto_layout (#2202)
Browse files Browse the repository at this point in the history
* fix(layouts): do not relayout twice on auto_layout

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Feb 27, 2023
1 parent 4d1b127 commit b3b0ddb
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 222 deletions.
38 changes: 24 additions & 14 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions zellij-server/src/tab/layout_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
});
Expand Down
12 changes: 10 additions & 2 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Expand All @@ -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): │ ││ │
Expand All @@ -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): │ │
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Expand All @@ -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): │ ││ │
Expand All @@ -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): │ │
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Expand All @@ -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): │ ││ │
Expand All @@ -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): │ │
Expand Down
Loading

0 comments on commit b3b0ddb

Please sign in to comment.