Skip to content

Commit

Permalink
Update so that cli move-pane-to-new-tab works with floating panes
Browse files Browse the repository at this point in the history
  • Loading branch information
e82eric committed Oct 18, 2024
1 parent ad6439d commit 435d838
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
12 changes: 8 additions & 4 deletions mux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions mux/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<dyn Pane>> {
pub fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option<(usize, Arc<dyn Pane>)> {
self.inner.lock().get_floating_pane_by_pane_id(pane_id)
}

Expand Down Expand Up @@ -1072,10 +1072,10 @@ impl TabInner {
self.iter_panes_impl(true)
}

fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option<Arc<dyn Pane>> {
for pane in &self.floating_panes {
fn get_floating_pane_by_pane_id(&self, pane_id: PaneId) -> Option<(usize, Arc<dyn Pane>)> {
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
Expand Down
1 change: 1 addition & 0 deletions wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3540,6 +3540,7 @@ impl TermWindow {
.overlay
.as_ref()
.map(|overlay| overlay.pane.clone())
.is_some()
{
return None;
}
Expand Down
10 changes: 10 additions & 0 deletions wezterm/src/cli/move_pane_to_new_tab.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 435d838

Please sign in to comment.