Skip to content

Commit

Permalink
Move active editor in direction
Browse files Browse the repository at this point in the history
Closes #20205

An action to move the active editor to a pane in a specified direction
  • Loading branch information
Igonato committed Dec 10, 2024
1 parent 500420f commit 0c2340f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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 {
Expand Down Expand Up @@ -230,6 +233,7 @@ impl_actions!(
CloseAllItemsAndPanes,
CloseInactiveTabsAndPanes,
MoveItemToPane,
MoveItemToPaneInDirection,
OpenTerminal,
Reload,
Save,
Expand Down Expand Up @@ -2978,6 +2982,38 @@ 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, false, 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);
}
});
}
}

pub fn bounding_box_for_pane(&self, pane: &View<Pane>) -> Option<Bounds<Pixels>> {
self.center.bounding_box_for_pane(pane)
}
Expand Down Expand Up @@ -4470,6 +4506,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)
}))
Expand Down

0 comments on commit 0c2340f

Please sign in to comment.