workspace: Add ActivateLastPane action#49853
workspace: Add ActivateLastPane action#49853smitbarmase merged 2 commits intozed-industries:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new workspace-level action to focus the last pane, enabling users to bind a shortcut (e.g. cmd-9) similar to existing “last item” navigation.
Changes:
- Added
workspace::ActivateLastPaneto the workspace action set. - Implemented
Workspace::activate_last_pane(...)and wired it into workspace action listeners. - Added
test_activate_last_paneto validate focusing behavior across multiple panes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .on_action(cx.listener(|workspace, _: &ActivateNextPane, window, cx| { | ||
| workspace.activate_next_pane(window, cx) | ||
| })) |
There was a problem hiding this comment.
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.
| .on_action(cx.listener(|workspace, _: &ActivateNextPane, window, cx| { | |
| workspace.activate_next_pane(window, cx) | |
| })) |
crates/workspace/src/workspace.rs
Outdated
| } | ||
|
|
||
| pub fn activate_last_pane(&mut self, window: &mut Window, cx: &mut App) { | ||
| if let Some(last_pane) = self.center.panes().last().cloned() { |
There was a problem hiding this comment.
activate_last_pane currently calls self.center.panes() which allocates a Vec just to get the final pane. Since PaneGroup already exposes last_pane(), prefer using that to avoid allocation and to match the semantic intent more directly.
| if let Some(last_pane) = self.center.panes().last().cloned() { | |
| if let Some(last_pane) = self.center.last_pane() { |
|
Thanks. It's a nice addition. |
## Summary Add `workspace::ActivateLastPane` so users can bind a shortcut (for example `cmd-9`) to focus the last pane. ## Why Today, the closest option is `workspace::ActivatePane` with an index (for example `8`), but that has side effects: when the index does not exist, it creates/splits panes (`activate_pane_at_index` fallback). `ActivateLastPane` gives a stable, no-surprises target: focus the rightmost/last pane in current pane order, never create a new pane. ## Context This capability has been requested by users before: - zed-industries#17503 (comment) ## Prior art VS Code exposes explicit editor-group focus commands and index-based focus patterns (e.g. `workbench.action.focusSecondEditorGroup` ... `focusEighthEditorGroup`) in its workbench commands: - https://github.com/microsoft/vscode/blob/main/src/vs/workbench/browser/parts/editor/editorCommands.ts#L675-L724 Zed already follows numbered pane focus in default keymaps (`ActivatePane` 1..9 on macOS/Linux/Windows), so adding a dedicated "last pane" action is a small, natural extension: - `assets/keymaps/default-macos.json` - `assets/keymaps/default-linux.json` - `assets/keymaps/default-windows.json` ## Change - Added `workspace::ActivateLastPane` - Implemented `Workspace::activate_last_pane(...)` - Wired action handler in workspace listeners - Added `test_activate_last_pane` ## Validation - `cargo test -p workspace test_activate_last_pane -- --nocapture` - `cargo test -p workspace test_pane_navigation -- --nocapture` - `cargo fmt --all -- --check` ## Risk Low: focus-only behavior, no layout/data changes, no default keymap changes. Release Notes: - Added `workspace::ActivateLastPane` action for keybindings that focus the last pane. --------- Co-authored-by: xj <gh-xj@users.noreply.github.com>
Summary
Add
workspace::ActivateLastPaneso users can bind a shortcut (for examplecmd-9) to focus the last pane.Why
Today, the closest option is
workspace::ActivatePanewith an index (for example8), but that has side effects: when the index does not exist, it creates/splits panes (activate_pane_at_indexfallback).ActivateLastPanegives a stable, no-surprises target: focus the rightmost/last pane in current pane order, never create a new pane.Context
This capability has been requested by users before:
Prior art
VS Code exposes explicit editor-group focus commands and index-based focus patterns (e.g.
workbench.action.focusSecondEditorGroup...focusEighthEditorGroup) in its workbench commands:Zed already follows numbered pane focus in default keymaps (
ActivatePane1..9 on macOS/Linux/Windows), so adding a dedicated "last pane" action is a small, natural extension:assets/keymaps/default-macos.jsonassets/keymaps/default-linux.jsonassets/keymaps/default-windows.jsonChange
workspace::ActivateLastPaneWorkspace::activate_last_pane(...)test_activate_last_paneValidation
cargo test -p workspace test_activate_last_pane -- --nocapturecargo test -p workspace test_pane_navigation -- --nocapturecargo fmt --all -- --checkRisk
Low: focus-only behavior, no layout/data changes, no default keymap changes.
Release Notes:
workspace::ActivateLastPaneaction for keybindings that focus the last pane.