Skip to content

Commit

Permalink
Add move item actions support to the terminal panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Igonato committed Dec 10, 2024
1 parent 3edee86 commit f8d3f2c
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions crates/terminal_view/src/terminal_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ use workspace::{
move_item, pane,
ui::IconName,
ActivateNextPane, ActivatePane, ActivatePaneInDirection, ActivatePreviousPane, DraggedTab,
ItemId, NewTerminal, Pane, PaneGroup, SplitDirection, SplitDown, SplitLeft, SplitRight,
SplitUp, SwapPaneInDirection, ToggleZoom, Workspace,
ItemId, MoveItemToPane, MoveItemToPaneInDirection, NewTerminal, Pane, PaneGroup,
SplitDirection, SplitDown, SplitLeft, SplitRight, SplitUp, SwapPaneInDirection, ToggleZoom,
Workspace,
};

use anyhow::Result;
Expand Down Expand Up @@ -1124,8 +1125,8 @@ impl Render for TerminalPanel {
.detach();
}
}))
.on_action(cx.listener(
|terminal_panel, action: &SwapPaneInDirection, cx| {
.on_action(
cx.listener(|terminal_panel, action: &SwapPaneInDirection, cx| {
if let Some(to) = terminal_panel
.center
.find_pane_in_direction(&terminal_panel.active_pane, action.0, cx)
Expand All @@ -1136,6 +1137,57 @@ impl Render for TerminalPanel {
.swap(&terminal_panel.active_pane.clone(), &to);
cx.notify();
}
}),
)
.on_action(cx.listener(|terminal_panel, action: &MoveItemToPane, cx| {
let panes = terminal_panel.center.panes();
let Some(target_pane) = panes.get(action.0).map(|p| (*p).clone()) else {
return;
};
let source_pane = terminal_panel.active_pane.clone();
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,
);
});
});
}))
.on_action(cx.listener(
|terminal_panel, action: &MoveItemToPaneInDirection, cx| {
let source_pane = terminal_panel.active_pane.clone();
let Some(target_pane) = terminal_panel
.center
.find_pane_in_direction(&source_pane, action.0, cx)
.cloned()
else {
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,
);
});
});
},
))
})
Expand Down

0 comments on commit f8d3f2c

Please sign in to comment.