Skip to content

Commit

Permalink
Update move_floating_pane_to_split to match move_pane_to_new_tab
Browse files Browse the repository at this point in the history
  • Loading branch information
e82eric committed Oct 19, 2024
1 parent 107b353 commit d14d094
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
40 changes: 2 additions & 38 deletions mux/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,8 @@ pub trait Domain: Downcast + Send + Sync {
&self,
tab: TabId,
direction: SplitDirection,
) -> anyhow::Result<()> {
let mux = Mux::get();
let tab = match mux.get_tab(tab) {
Some(t) => t,
None => anyhow::bail!("Invalid tab id {}", tab),
};

let floating_pane = tab.remove_floating_pane(tab.get_active_floating_pane_index())?;

tab.set_floating_pane_visibility(false);

//TODO: Figure out if all floating pane stuff should be removed from tab.get_active_pane
let active_non_floating_pane = tab.iter_panes_ignoring_zoom()
.iter()
.nth(tab.get_active_idx())
.map(|p| Arc::clone(&p.pane))
.ok_or_else(|| anyhow::anyhow!("tab does not have a active non floating pane"))?;

let pane_id = active_non_floating_pane.pane_id();

//TODO: this is duplicated
let pane_index = match tab
.iter_panes_ignoring_zoom()
.iter()
.find(|p| p.pane.pane_id() == pane_id)
{
Some(p) => p.index,
None => anyhow::bail!("invalid pane id {}", pane_id),
};

let split_request = SplitRequest {
direction,
target_is_second: true,
top_level: false,
size: Default::default(),
};
tab.split_and_insert(pane_index, split_request, Arc::clone(&floating_pane))?;
Ok(())
) -> anyhow::Result<bool> {
Ok(false)
}

async fn split_pane(
Expand Down
39 changes: 37 additions & 2 deletions mux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,44 @@ impl Mux {
) -> anyhow::Result<()> {
let (domain, window_id, tab_id) = self.resolve_domain_from_pane_id(pane_id)?;

domain.move_floating_pane_to_split(tab_id, direction).await?;
if domain.move_floating_pane_to_split(tab_id, direction).await? {
return Ok(())
}

let mux = Mux::get();
let tab = match mux.get_tab(tab_id) {
Some(t) => t,
None => anyhow::bail!("Invalid tab id {}", tab_id),
};

let floating_pane = tab.remove_floating_pane(tab.get_active_floating_pane_index())?;

tab.set_floating_pane_visibility(false);

//TODO: why don't I have to do the other stuff in move_pane_to_floating_pane
let active_non_floating_pane = tab.iter_panes_ignoring_zoom()
.iter()
.nth(tab.get_active_idx())
.map(|p| Arc::clone(&p.pane))
.ok_or_else(|| anyhow::anyhow!("tab does not have a active non floating pane"))?;

let pane_id = active_non_floating_pane.pane_id();

let pane_index = match tab
.iter_panes_ignoring_zoom()
.iter()
.find(|p| p.pane.pane_id() == pane_id)
{
Some(p) => p.index,
None => anyhow::bail!("invalid pane id {}", pane_id),
};

let split_request = SplitRequest {
direction,
target_is_second: true,
top_level: false,
size: Default::default(),
};
tab.split_and_insert(pane_index, split_request, Arc::clone(&floating_pane))?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions wezterm-client/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ impl Domain for ClientDomain {
&self,
pane_id: PaneId,
split_direction: SplitDirection,
) -> anyhow::Result<()> {
) -> anyhow::Result<bool> {
let inner = self
.inner()
.ok_or_else(|| anyhow!("domain is not attached"))?;
Expand All @@ -868,7 +868,7 @@ impl Domain for ClientDomain {

self.resync().await?;

Ok(())
Ok(true)
}

/// Forward the request to the remote; we need to translate the local ids
Expand Down

0 comments on commit d14d094

Please sign in to comment.