Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ actions!(
ActivateNextPane,
/// Activates the previous pane in the workspace.
ActivatePreviousPane,
/// Activates the last pane in the workspace.
ActivateLastPane,
/// Switches to the next window.
ActivateNextWindow,
/// Switches to the previous window.
Expand Down Expand Up @@ -4325,6 +4327,11 @@ impl Workspace {
}
}

pub fn activate_last_pane(&mut self, window: &mut Window, cx: &mut App) {
let last_pane = self.center.last_pane();
window.focus(&last_pane.focus_handle(cx), cx);
}

pub fn activate_pane_in_direction(
&mut self,
direction: SplitDirection,
Expand Down Expand Up @@ -6373,6 +6380,9 @@ impl Workspace {
.on_action(cx.listener(|workspace, _: &ActivateNextPane, window, cx| {
workspace.activate_next_pane(window, cx)
}))
Comment on lines 6380 to 6382

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActivateNextPane is registered twice in this listener chain (once around line 6381 and again around line 6409). Div::on_action accumulates listeners, so dispatching ActivateNextPane will run both handlers and advance focus twice (skipping a pane). Remove one of these registrations.

Suggested change
.on_action(cx.listener(|workspace, _: &ActivateNextPane, window, cx| {
workspace.activate_next_pane(window, cx)
}))

Copilot uses AI. Check for mistakes.
.on_action(cx.listener(|workspace, _: &ActivateLastPane, window, cx| {
workspace.activate_last_pane(window, cx)
}))
.on_action(
cx.listener(|workspace, _: &ActivateNextWindow, _window, cx| {
workspace.activate_next_window(cx)
Expand All @@ -6395,9 +6405,6 @@ impl Workspace {
.on_action(cx.listener(|workspace, _: &ActivatePaneDown, window, cx| {
workspace.activate_pane_in_direction(SplitDirection::Down, window, cx)
}))
.on_action(cx.listener(|workspace, _: &ActivateNextPane, window, cx| {
workspace.activate_next_pane(window, cx)
}))
.on_action(cx.listener(
|workspace, action: &MoveItemToPaneInDirection, window, cx| {
workspace.move_item_to_pane_in_direction(action, window, cx)
Expand Down Expand Up @@ -10468,6 +10475,57 @@ mod tests {
});
}

#[gpui::test]
async fn test_activate_last_pane(cx: &mut gpui::TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.executor());
let project = Project::test(fs, [], cx).await;
let (workspace, cx) =
cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));

workspace.update_in(cx, |workspace, window, cx| {
let first_item = cx.new(|cx| {
TestItem::new(cx).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
});
workspace.add_item_to_active_pane(Box::new(first_item), None, true, window, cx);
workspace.split_pane(
workspace.active_pane().clone(),
SplitDirection::Right,
window,
cx,
);
workspace.split_pane(
workspace.active_pane().clone(),
SplitDirection::Right,
window,
cx,
);
});

let (first_pane_id, target_last_pane_id) = workspace.update(cx, |workspace, _cx| {
let panes = workspace.center.panes();
assert!(panes.len() >= 2);
(
panes.first().expect("at least one pane").entity_id(),
panes.last().expect("at least one pane").entity_id(),
)
});

workspace.update_in(cx, |workspace, window, cx| {
workspace.activate_pane_at_index(&ActivatePane(0), window, cx);
});
workspace.update(cx, |workspace, _| {
assert_eq!(workspace.active_pane().entity_id(), first_pane_id);
assert_ne!(workspace.active_pane().entity_id(), target_last_pane_id);
});

cx.dispatch_action(ActivateLastPane);

workspace.update(cx, |workspace, _| {
assert_eq!(workspace.active_pane().entity_id(), target_last_pane_id);
});
}

#[gpui::test]
async fn test_toggle_docks_and_panels(cx: &mut gpui::TestAppContext) {
init_test(cx);
Expand Down