Skip to content

Agents app: keybindings to switch between sessions (Ctrl+1..9)#310994

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-keybindings-to-switch-sessions
Open

Agents app: keybindings to switch between sessions (Ctrl+1..9)#310994
Copilot wants to merge 4 commits intomainfrom
copilot/add-keybindings-to-switch-sessions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Adds Ctrl+1..Ctrl+9 to switch between sessions in the Agents window, mirroring the familiar tab-switching pattern.

  • Ctrl+1..Ctrl+8 open the Nth visible session
  • Ctrl+9 opens the last visible session (Chrome/Slack convention)
  • Uses Ctrl on all platforms (including macOS) to avoid conflicting with Cmd+N view-focus shortcuts in VS Code
  • Gated by IsSessionsWindowContext so regular VS Code shortcuts are unaffected

Changes

  • sessionsList.ts: added getVisibleSessions(): readonly ISession[] to ISessionsList / SessionsList. The visible list (in display order, after filters/sorting/grouping; excludes items hidden behind workspace-group "show more" capping) is captured during update().
  • sessionsViewActions.ts: registered sessionsViewPane.openSessionAtIndex plus 9 keybinding rules. Handler resolves the active SessionsView, indexes into getVisibleSessions(), and calls ISessionsManagementService.openSession(). The keybinding weight is WorkbenchContrib + 1 so it overrides the built-in workbench.action.openEditorAtIndexN which also binds Ctrl+N on macOS.
for (let visibleIndex = 1; visibleIndex <= 9; visibleIndex++) {
    const sessionIndex = visibleIndex === 9 ? -1 : visibleIndex - 1; // 9 = last
    KeybindingsRegistry.registerCommandAndKeybindingRule({
        id: OPEN_SESSION_AT_INDEX_COMMAND_ID + visibleIndex,
        // Higher than WorkbenchContrib to override `workbench.action.openEditorAtIndexN` (Ctrl+N on macOS)
        weight: KeybindingWeight.WorkbenchContrib + 1,
        when: IsSessionsWindowContext,
        // Always use Ctrl (not Cmd on macOS) to avoid conflicting with Cmd+N view focus shortcuts
        primary: KeyMod.CtrlCmd | digitToKeyCode(visibleIndex),
        mac: { primary: KeyMod.WinCtrl | digitToKeyCode(visibleIndex) },
        handler: accessor => openSessionAtIndex(accessor, sessionIndex)
    });
}

Copilot AI requested review from Copilot and removed request for Copilot April 17, 2026 13:03
Copilot AI requested review from Copilot and removed request for Copilot April 17, 2026 13:11
Copilot AI changed the title [WIP] Add keybindings to switch between sessions in Agents app Agents app: keybindings to switch between sessions (Ctrl/Cmd+1..9) Apr 17, 2026
Copilot AI requested a review from ulugbekna April 17, 2026 13:12
@ulugbekna
Copy link
Copy Markdown
Contributor

@copilot Cmd+N is used for focusing various views in vscode, so I think it should use Ctrl regardless of OS

Copilot AI requested review from Copilot and removed request for Copilot April 17, 2026 13:31
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot Cmd+N is used for focusing various views in vscode, so I think it should use Ctrl regardless of OS

Good catch — switched to Ctrl+1..9 on macOS as well by adding mac: { primary: KeyMod.WinCtrl | ... } (which maps to Ctrl on macOS). 621a1a2

Copilot AI changed the title Agents app: keybindings to switch between sessions (Ctrl/Cmd+1..9) Agents app: keybindings to switch between sessions (Ctrl+1..9) Apr 17, 2026
@ulugbekna
Copy link
Copy Markdown
Contributor

@copilot it doesn't work because another command is being invoked:

2026-04-17 16:06:21.839 [info] [Window] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
2026-04-17 16:06:21.840 [info] [Window] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
2026-04-17 16:06:21.840 [info] [Window] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2026-04-17 16:06:22.006 [info] [Window] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: Digit1, keyCode: 49, key: 1
2026-04-17 16:06:22.006 [info] [Window] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: Digit1, keyCode: 22 ('1')
2026-04-17 16:06:22.006 [info] [Window] [KeybindingService]: | Resolving ctrl+[Digit1]
2026-04-17 16:06:22.006 [info] [Window] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.openEditorAtIndex1, when: no when condition, source: built-in.
2026-04-17 16:06:22.006 [info] [Window] [KeybindingService]: + Invoking command workbench.action.openEditorAtIndex1.

Copilot AI requested review from Copilot and removed request for Copilot April 17, 2026 14:13
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot it doesn't work because another command is being invoked:

...

The conflict is with workbench.action.openEditorAtIndexN, which also binds Ctrl+N on macOS at the same WorkbenchContrib weight. Bumped the sessions binding weight to WorkbenchContrib + 1 so it wins (matches the pattern already used for the other sessions keybindings in this file). 5d0ab12

@ulugbekna
Copy link
Copy Markdown
Contributor

@copilot update PR description. mentioned also that fixes #310992

@ulugbekna ulugbekna marked this pull request as ready for review April 17, 2026 14:37
Copilot AI review requested due to automatic review settings April 17, 2026 14:37
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot update PR description. mentioned also that fixes #310992

Updated the PR description to include Fixes #310992.

Copilot AI requested a review from ulugbekna April 17, 2026 14:41
@github-actions
Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 57d9b714 Current: 35910227

Changed (2)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after
editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds session-switching keybindings (Ctrl+1..9) to the Agents (sessions) window to quickly open the Nth/last visible session, mirroring common “tab index” navigation patterns while being gated to the sessions window context.

Changes:

  • Added getVisibleSessions(): readonly ISession[] to ISessionsList/SessionsList, capturing a “visible sessions” list during update().
  • Registered sessionsViewPane.openSessionAtIndex plus Ctrl+1..9 keybindings that resolve the active SessionsView and open the corresponding session via ISessionsManagementService.
Show a summary per file
File Description
src/vs/sessions/contrib/sessions/browser/views/sessionsViewActions.ts Registers command + keybindings and dispatches to openSession(...) based on visible-session index.
src/vs/sessions/contrib/sessions/browser/views/sessionsList.ts Introduces getVisibleSessions() and tracks “visible” sessions during list updates.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines 890 to 892
const children: IObjectTreeElement<SessionListItem>[] = [];
const visibleSessions: ISession[] = [];

Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

getVisibleSessions() is populated from the section/session data before it’s applied to the tree, so it can include sessions that aren’t actually visible in the UI (e.g. sessions inside collapsed sections, or sessions hidden by the tree’s Find-widget filtering). This will make Ctrl+1..9 open “invisible” sessions and misalign indices with what the user sees.

Consider deriving the visible session list from the tree model after setChildren() (e.g. traverse this.tree.getNode() in render order and collect only nodes where node.visible is true and the element is an ISession, skipping section/show-more nodes).

Copilot uses AI. Check for mistakes.
}

getVisibleSessions(): readonly ISession[] {
return this._visibleSessions;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This new getVisibleSessions() API is now used to drive keyboard navigation (Ctrl+1..9). Since there are already tests covering other logic exported from this file, it would be good to add coverage for getVisibleSessions()—especially cases like workspace-group capping ("show more"), collapsed sections, and Find-widget filtering—to ensure index-to-session mapping matches the UI.

Suggested change
return this._visibleSessions;
const sessions = new Set(this.sessions);
const visibleSessions: ISession[] = [];
const collectVisibleSessions = (node: ITreeNode<SessionListItem, FuzzyScore | undefined>): void => {
if (sessions.has(node.element as ISession)) {
visibleSessions.push(node.element as ISession);
}
if (node.collapsed) {
return;
}
for (const child of node.children) {
collectVisibleSessions(child);
}
};
const root = this.tree.getNode();
for (const child of root.children) {
collectVisibleSessions(child);
}
return visibleSessions;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents app: keybindings to switch between sessions (e.g. Ctrl+1, Ctrl+2)

3 participants