From 435d83899834c97d07905ceec963ba5f5c255d8f Mon Sep 17 00:00:00 2001 From: Eric Nelson Date: Thu, 17 Oct 2024 23:41:28 -0700 Subject: [PATCH] Update so that cli move-pane-to-new-tab works with floating panes --- mux/src/lib.rs | 12 ++++++++---- mux/src/tab.rs | 8 ++++---- wezterm-gui/src/termwindow/mod.rs | 1 + wezterm/src/cli/move_pane_to_new_tab.rs | 10 ++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 8be21655be1..baece0acd72 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -1075,7 +1075,7 @@ impl Mux { pub fn resolve_pane_id(&self, pane_id: PaneId) -> Option<(DomainId, WindowId, TabId)> { let mut ids = None; for tab in self.tabs.read().values() { - if let Some(floating_pane) = tab.get_floating_pane_by_pane_id(pane_id){ + if let Some((index, floating_pane)) = tab.get_floating_pane_by_pane_id(pane_id){ ids = Some((tab.tab_id(), floating_pane.domain_id())); break; } @@ -1376,9 +1376,13 @@ impl Mux { (*window_builder, src_tab.get_size()) }; - let pane = src_tab - .remove_pane(pane_id) - .ok_or_else(|| anyhow::anyhow!("pane {} wasn't in its containing tab!?", pane_id))?; + let pane = if let Some((i, _)) = src_tab.get_floating_pane_by_pane_id(pane_id) { + src_tab.remove_floating_pane(i)? + } else { + src_tab + .remove_pane(pane_id) + .ok_or_else(|| anyhow::anyhow!("pane {} wasn't in its containing tab!?", pane_id))? + }; let tab = Arc::new(Tab::new(&size)); tab.assign_pane(&pane); diff --git a/mux/src/tab.rs b/mux/src/tab.rs index 1f23dd6b3e6..737c792d2c5 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -587,7 +587,7 @@ impl Tab { self.inner.lock().floating_pane_is_visible() } - pub fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option> { + pub fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option<(usize, Arc)> { self.inner.lock().get_floating_pane_by_pane_id(pane_id) } @@ -1072,10 +1072,10 @@ impl TabInner { self.iter_panes_impl(true) } - fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option> { - for pane in &self.floating_panes { + fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option<(usize, Arc)> { + for (i, pane) in self.floating_panes.iter().enumerate() { if pane.pane_id() == pane_id { - return Some(Arc::clone(&pane)) + return Some((i, Arc::clone(&pane))) } } return None diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 92db5535497..c574bac8c12 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -3540,6 +3540,7 @@ impl TermWindow { .overlay .as_ref() .map(|overlay| overlay.pane.clone()) + .is_some() { return None; } diff --git a/wezterm/src/cli/move_pane_to_new_tab.rs b/wezterm/src/cli/move_pane_to_new_tab.rs index e03faf6e952..dddbeb664f4 100644 --- a/wezterm/src/cli/move_pane_to_new_tab.rs +++ b/wezterm/src/cli/move_pane_to_new_tab.rs @@ -1,5 +1,6 @@ use clap::Parser; use mux::pane::PaneId; +use mux::tab::PaneNode::Leaf; use mux::window::WindowId; use wezterm_client::client::Client; @@ -41,6 +42,15 @@ impl MovePaneToNewTab { let panes = client.list_panes().await?; let mut window_id = None; 'outer_move: for tabroot in panes.tabs { + for floating_pane in tabroot.floating_panes { + if let Leaf(floating_pane) = floating_pane { + if floating_pane.pane_id == pane_id { + window_id.replace(floating_pane.window_id); + break 'outer_move; + } + } + } + let mut cursor = tabroot.panes.into_tree().cursor(); loop {