Skip to content

Commit

Permalink
Move active editor to another pane action
Browse files Browse the repository at this point in the history
Analogous to the Sublime's ctrl+shif+*number* shortcut
  • Loading branch information
Igonato committed Dec 14, 2024
1 parent 7e6233d commit e51fcc1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ pub struct ActivatePaneInDirection(pub SplitDirection);
#[derive(Clone, Deserialize, PartialEq)]
pub struct SwapPaneInDirection(pub SplitDirection);

#[derive(Clone, Deserialize, PartialEq)]
pub struct MoveItemToPane(pub usize);

#[derive(Clone, PartialEq, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SaveAll {
Expand Down Expand Up @@ -222,6 +225,7 @@ impl_actions!(
ActivatePaneInDirection,
CloseAllItemsAndPanes,
CloseInactiveTabsAndPanes,
MoveItemToPane,
OpenTerminal,
Reload,
Save,
Expand Down Expand Up @@ -2829,6 +2833,30 @@ impl Workspace {
}
}

fn move_item_to_pane_at_index(&mut self, action: &MoveItemToPane, cx: &mut ViewContext<Self>) {
let panes = self.center.panes();
let source_pane = self.active_pane.clone();
let Some(target_pane) = panes.get(action.0).map(|p| (*p).clone()) else {
return;
};
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 activate_next_pane(&mut self, cx: &mut WindowContext) {
let panes = self.center.panes();
if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
Expand Down Expand Up @@ -4408,6 +4436,7 @@ impl Workspace {
.on_action(cx.listener(Self::follow_next_collaborator))
.on_action(cx.listener(Self::close_window))
.on_action(cx.listener(Self::activate_pane_at_index))
.on_action(cx.listener(Self::move_item_to_pane_at_index))
.on_action(cx.listener(|workspace, _: &Unfollow, cx| {
let pane = workspace.active_pane().clone();
workspace.unfollow_in_pane(&pane, cx);
Expand Down

0 comments on commit e51fcc1

Please sign in to comment.