Iterate over keymap then dispatch path when matching keybindings to make precedence more intuitive

Rename action which adds the active tab to the dock to be more intuitive
Add action which moves the active tab out of the dock and bind it to the same keybinding
This commit is contained in:
Kay Simmons 2023-02-18 13:10:01 -08:00
parent dc6f7fd577
commit 04df00b221
3 changed files with 63 additions and 21 deletions

View file

@ -30,7 +30,8 @@ actions!(
AnchorDockRight,
AnchorDockBottom,
ExpandDock,
MoveActiveItemToDock,
AddTabToDock,
RemoveTabFromDock,
]
);
impl_internal_actions!(dock, [MoveDock, AddDefaultItemToDock]);
@ -55,7 +56,8 @@ pub fn init(cx: &mut MutableAppContext) {
},
);
cx.add_action(
|workspace: &mut Workspace, _: &MoveActiveItemToDock, cx: &mut ViewContext<Workspace>| {
|workspace: &mut Workspace, _: &AddTabToDock, cx: &mut ViewContext<Workspace>| {
eprintln!("Add tab to dock");
if let Some(active_item) = workspace.active_item(cx) {
let item_id = active_item.id();
@ -67,6 +69,42 @@ pub fn init(cx: &mut MutableAppContext) {
let destination_index = to.read(cx).items_len() + 1;
Pane::move_item(
workspace,
from.clone(),
to.clone(),
item_id,
destination_index,
cx,
);
}
},
);
cx.add_action(
|workspace: &mut Workspace, _: &RemoveTabFromDock, cx: &mut ViewContext<Workspace>| {
eprintln!("Removing tab from dock");
if let Some(active_item) = workspace.active_item(cx) {
let item_id = active_item.id();
let from = workspace.dock_pane();
let to = workspace
.last_active_center_pane
.as_ref()
.and_then(|pane| pane.upgrade(cx))
.unwrap_or_else(|| {
workspace
.panes
.first()
.expect("There must be a pane")
.clone()
});
if from.id() == to.id() {
return;
}
let destination_index = to.read(cx).items_len() + 1;
Pane::move_item(
workspace,
from.clone(),