Skip to content

sessions: fix chat keyboard shortcuts in the agents window - #324404

Open
yashjeswani63 wants to merge 7 commits into
microsoft:mainfrom
yashjeswani63:fix/chat-shortcuts-agents-window
Open

sessions: fix chat keyboard shortcuts in the agents window#324404
yashjeswani63 wants to merge 7 commits into
microsoft:mainfrom
yashjeswani63:fix/chat-shortcuts-agents-window

Conversation

@yashjeswani63

Copy link
Copy Markdown

Chat Keyboard Shortcuts in the Agents Window (Multi-Chat)

Fixes #324363

This PR fixes issues with chat tab management, navigation shortcuts, and context-dependent fallbacks inside multi-chat/Agents window sessions.

Summary

Keyboard shortcuts for managing and navigating chats in an active multi-chat session are now scoped to the Agents window and only fire when there is something to act on. Otherwise, they fall back to the existing session-level or global commands cleanly:

  1. Reopen Last Closed Chat (Cmd/Ctrl+Shift+T):

    • Added the sessionHasClosedChats context key which tracks whether there is a closed chat available to reopen.
    • Updated the ReopenLastClosedChatAction to only fire when sessionHasClosedChats is true. If there are no closed chats, it falls back to the editor's default reopen command (reopenClosedEditor).
  2. Add Chat (Cmd/Ctrl+T):

    • Simplified the when condition of the AddChatToSessionAction keybinding to focus purely on active, created sessions.
    • Handled the session capability and archiving checks programmatically inside the run() method so that pressing Ctrl+T in those cases is intercepted and results in a no-op ("does nothing"), instead of falling back to the global symbol finder.
  3. Go to Chat Picker (Cmd/Ctrl+Shift+O):

    • Gated the ShowChatsPickerAction keybinding on the sessionHasMultipleCommittedChats context key so it correctly falls back to "Go to Symbol in Editor" when a single chat is focused.
  4. Previous/Next Chat (Cmd/Ctrl+Shift+[ / ]):

    • Added KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.BracketLeft / BracketRight secondary keybindings on Windows and Linux to NavigatePreviousSessionAction and NavigateNextSessionAction. If the session has only a single chat tab, these shortcuts now correctly fall back to session-level navigation on all platforms.

Proposed Changes

Sessions

contextkeys.ts

  • Defined SessionHasClosedChatsContext context key.

sessionContextKeys.ts

  • Bound SessionHasClosedChatsContext to the context key service.
  • Updated setActiveSessionContextKeys to dynamically set hasClosedChats to true if the active session has closed chats.

sessionsActions.ts

  • Scoped AddChatToSessionAction (Cmd/Ctrl+T), ReopenLastClosedChatAction (Cmd/Ctrl+Shift+T), and ShowChatsPickerAction (Cmd/Ctrl+Shift+O) with the appropriate context key conditions and runtime checks to handle no-ops and clean fallbacks.

sessionsViewActions.ts

  • Configured secondary keybindings for session navigation on non-macOS platforms.

Verification

Automated Tests

  • Created a new test file src/vs/sessions/services/sessions/test/browser/sessionContextKeys.test.ts to assert that context keys correctly reflect open and closed chat states.
  • Ran the browser test suite successfully:
    node test/unit/browser/index.js --run src/vs/sessions/services/sessions/test/browser/sessionContextKeys.test.ts

Copilot AI review requested due to automatic review settings July 5, 2026 20:25
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@sandy081

Matched files:

  • src/vs/sessions/services/sessions/common/sessionContextKeys.ts
  • src/vs/sessions/services/sessions/test/browser/sessionContextKeys.test.ts

@lszomoru

Matched files:

  • src/vs/sessions/services/sessions/common/sessionContextKeys.ts
  • src/vs/sessions/services/sessions/test/browser/sessionContextKeys.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes chat keyboard shortcuts in the Agents window (multi-chat sessions) so that chords like Cmd/Ctrl+T, Cmd/Ctrl+Shift+T, Cmd/Ctrl+Shift+O, and Cmd/Ctrl+Shift+[/] are scoped to the Agents window and only fire when there is something to act on, otherwise falling back cleanly to session-level or global commands. It introduces a new sessionHasClosedChats context key and refines the when conditions and runtime checks of the relevant actions.

Changes:

  • Added SessionHasClosedChatsContext context key and wired it into setActiveSessionContextKeys, gating ReopenLastClosedChatAction on it.
  • Simplified AddChatToSessionAction's keybinding when and moved the multiple-chats/archived checks into run() as a no-op; gated ShowChatsPickerAction on SessionHasMultipleCommittedChatsContext.
  • Added Ctrl/Cmd+Shift+[ / ] as secondary keybindings for session navigation on Windows/Linux (matching the existing mac bindings), and added a new context-key unit test.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/vs/sessions/common/contextkeys.ts Declares the new SessionHasClosedChatsContext raw context key.
src/vs/sessions/services/sessions/common/sessionContextKeys.ts Binds and sets hasClosedChats from the active session's closedChats.
src/vs/sessions/contrib/sessions/browser/sessionsActions.ts Scopes Add/Reopen/Go-to-Chat actions with context keys and runtime no-op checks.
src/vs/sessions/contrib/sessions/browser/views/sessionsViewActions.ts Adds Ctrl/Cmd+Shift+[/] secondary session-navigation bindings on non-mac.
src/vs/sessions/services/sessions/test/browser/sessionContextKeys.test.ts New unit test asserting closed/open chat context keys; the makeSession stub does not conform to ISession.

Comment on lines +41 to +62
function makeSession(id: string, chats: IChat[]): ISession {
return {
sessionId: id,
resource: URI.parse(`test:///session/${id}`),
providerId: 'test-provider',
sessionType: 'test-type',
icon: { id: 'test-icon' },
createdAt: new Date(),
workspace: constObservable(undefined),
isQuickChat: constObservable(false),
title: constObservable(id),
status: constObservable(SessionStatus.Completed),
isArchived: constObservable(false),
isRead: constObservable(true),
capabilities: constObservable({ supportsMultipleChats: true }),
chats: constObservable(chats),
mainChat: constObservable(chats[0]),
changesets: constObservable([]),
changes: constObservable([]),
workingSet: constObservable(undefined),
};
}
@yashjeswani63

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Test: Chat keyboard shortcuts in the Agents window

4 participants