diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ce0fa278974e64..82379696d54ec2 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -176,6 +176,9 @@ pub struct SwapPaneInDirection(pub SplitDirection); #[derive(Clone, Deserialize, PartialEq)] pub struct MoveItemToPane(pub usize); +#[derive(Clone, Deserialize, PartialEq)] +pub struct MoveItemToPaneInDirection(pub SplitDirection); + #[derive(Clone, PartialEq, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SaveAll { @@ -226,6 +229,7 @@ impl_actions!( CloseAllItemsAndPanes, CloseInactiveTabsAndPanes, MoveItemToPane, + MoveItemToPaneInDirection, OpenTerminal, Reload, Save, @@ -2847,13 +2851,10 @@ impl Workspace { }; source_pane.update(cx, |pane, cx| { let item_id = active_item.item_id(); - pane.remove_item(item_id, false, false, cx); + pane.remove_item(item_id, false, true, cx); target_pane.update(cx, |target_pane, cx| { target_pane.add_item(active_item, true, true, Some(target_pane.items_len()), cx); }); - if pane.items_len() == 0 { - let _ = self.center.remove(&source_pane); - } }); } @@ -2975,6 +2976,35 @@ impl Workspace { } } + pub fn move_item_to_pane_in_direction( + &mut self, + direction: SplitDirection, + cx: &mut WindowContext, + ) { + if let Some(target_pane) = self.find_pane_in_direction(direction, cx) { + let source_pane = self.active_pane.clone(); + if target_pane == source_pane { + return; + } + let Some(active_item) = source_pane.read(cx).active_item() else { + return; + }; + source_pane.update(cx, |pane, cx| { + let item_id = active_item.item_id(); + pane.remove_item(item_id, false, true, cx); + target_pane.update(cx, |target_pane, cx| { + target_pane.add_item( + active_item, + true, + true, + Some(target_pane.items_len()), + cx, + ); + }); + }); + } + } + pub fn bounding_box_for_pane(&self, pane: &View) -> Option> { self.center.bounding_box_for_pane(pane) } @@ -4467,6 +4497,11 @@ impl Workspace { workspace.activate_pane_in_direction(action.0, cx) }), ) + .on_action( + cx.listener(|workspace, action: &MoveItemToPaneInDirection, cx| { + workspace.move_item_to_pane_in_direction(action.0, cx) + }), + ) .on_action(cx.listener(|workspace, action: &SwapPaneInDirection, cx| { workspace.swap_pane_in_direction(action.0, cx) }))