From af2be7a7a453a28ac943f35a23fc8c969ecc1d09 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 3 Feb 2025 09:04:03 +0100 Subject: [PATCH] fix(floating-panes): when changing coordinates, if a pane is not floating - make it floating (#3972) * fix(panes): when changing floating pane coordinates, if the pane is not floating, float it * style(fmt): rustfmt --- zellij-server/src/screen.rs | 5 +++-- zellij-server/src/tab/mod.rs | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 9248f21a..3e45da3d 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -2067,6 +2067,7 @@ impl Screen { plugin_pane_to_move_to_active_tab, pane_id, None, + true, )?; } else { new_active_tab.hide_floating_panes(); @@ -2180,7 +2181,7 @@ impl Screen { let (mut tiled_panes_layout, mut floating_panes_layout) = default_layout.new_tab(); if pane_to_break_is_floating { tab.show_floating_panes(); - tab.add_floating_pane(active_pane, active_pane_id, None)?; + tab.add_floating_pane(active_pane, active_pane_id, None, true)?; if let Some(already_running_layout) = floating_panes_layout .iter_mut() .find(|i| i.run == active_pane_run_instruction) @@ -2304,7 +2305,7 @@ impl Screen { if pane_to_break_is_floating { new_active_tab.show_floating_panes(); - new_active_tab.add_floating_pane(active_pane, active_pane_id, None)?; + new_active_tab.add_floating_pane(active_pane, active_pane_id, None, true)?; } else { new_active_tab.hide_floating_panes(); new_active_tab.add_tiled_pane(active_pane, active_pane_id, Some(client_id))?; diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index 60a2ae98..b1736482 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -1026,7 +1026,7 @@ impl Tab { } if let Some(embedded_pane_to_float) = self.extract_pane(focused_pane_id, true) { self.show_floating_panes(); - self.add_floating_pane(embedded_pane_to_float, focused_pane_id, None)?; + self.add_floating_pane(embedded_pane_to_float, focused_pane_id, None, true)?; } } Ok(()) @@ -1058,7 +1058,7 @@ impl Tab { return Ok(()); } if let Some(embedded_pane_to_float) = self.extract_pane(pane_id, true) { - self.add_floating_pane(embedded_pane_to_float, pane_id, None)?; + self.add_floating_pane(embedded_pane_to_float, pane_id, None, true)?; } } Ok(()) @@ -1203,7 +1203,7 @@ impl Tab { .insert(pid, (is_scrollback_editor, new_pane)); Ok(()) } else if self.floating_panes.panes_are_visible() { - self.add_floating_pane(new_pane, pid, floating_pane_coordinates) + self.add_floating_pane(new_pane, pid, floating_pane_coordinates, true) } else { self.add_tiled_pane(new_pane, pid, client_id) } @@ -4177,7 +4177,7 @@ impl Tab { pane.1.set_selectable(true); if should_float { self.show_floating_panes(); - self.add_floating_pane(pane.1, pane_id, None) + self.add_floating_pane(pane.1, pane_id, None, true) } else { self.hide_floating_panes(); self.add_tiled_pane(pane.1, pane_id, Some(client_id)) @@ -4190,7 +4190,8 @@ impl Tab { match self.suppressed_panes.remove(&pane_id) { Some(pane) => { self.show_floating_panes(); - self.add_floating_pane(pane.1, pane_id, None).non_fatal(); + self.add_floating_pane(pane.1, pane_id, None, true) + .non_fatal(); self.floating_panes.focus_pane_for_all_clients(pane_id); }, None => { @@ -4230,6 +4231,7 @@ impl Tab { mut pane: Box, pane_id: PaneId, floating_pane_coordinates: Option, + should_focus_new_pane: bool, ) -> Result<()> { let err_context = || format!("failed to add floating pane"); if let Some(mut new_pane_geom) = self.floating_panes.find_room_for_new_pane() { @@ -4247,7 +4249,9 @@ impl Tab { resize_pty!(pane, self.os_api, self.senders, self.character_cell_size) .with_context(err_context)?; self.floating_panes.add_pane(pane_id, pane); - self.floating_panes.focus_pane_for_all_clients(pane_id); + if should_focus_new_pane { + self.floating_panes.focus_pane_for_all_clients(pane_id); + } } if self.auto_layout && !self.swap_layouts.is_floating_damaged() { // only do this if we're already in this layout, otherwise it might be @@ -4520,6 +4524,18 @@ impl Tab { pane_id: &PaneId, floating_pane_coordinates: FloatingPaneCoordinates, ) -> Result<()> { + if !self.floating_panes.panes_contain(pane_id) { + // if these panes are not floating, we make them floating (assuming doing so wouldn't + // be removing the last selectable tiled pane in the tab, which would close it) + if (self.tiled_panes.panes_contain(&pane_id) + && self.get_selectable_tiled_panes().count() <= 1) + || self.suppressed_panes.contains_key(pane_id) + { + if let Some(pane) = self.extract_pane(*pane_id, true) { + self.add_floating_pane(pane, *pane_id, None, false)?; + } + } + } self.floating_panes .change_pane_coordinates(*pane_id, floating_pane_coordinates)?; self.set_force_render();