Skip to content

Agents: don't shadow Ctrl+N when editor area has focus#319609

Merged
benibenj merged 1 commit into
mainfrom
benibenj/agents/editor-focus-context-ctrl-n-behavior
Jun 2, 2026
Merged

Agents: don't shadow Ctrl+N when editor area has focus#319609
benibenj merged 1 commit into
mainfrom
benibenj/agents/editor-focus-context-ctrl-n-behavior

Conversation

@benibenj
Copy link
Copy Markdown
Contributor

@benibenj benibenj commented Jun 2, 2026

Adds a workbench-wide editorAreaFocus context key bound by the base EditorPart so it evaluates to true whenever keyboard focus is inside any editor part (main, modal, or auxiliary).

The Agents window's Ctrl/Cmd+N keybindings that open a new chat (workbench.action.sessions.newChat and the rebound workbench.action.chat.newChat) are now gated with when: EditorAreaFocusContext.negate(). When focus is inside an editor the keybinding falls through to the standard workbench.action.files.newUntitledFile command, matching the behavior users expect from VS Code.

Changes

  • workbench/common/contextkeys.ts: new EditorAreaFocusContext (editorAreaFocus)
  • workbench/browser/parts/editor/editorPart.ts: bind it in handleContextKeys() on the scoped context key service so it applies to every editor part subclass
  • sessions/contrib/chat/browser/chat.contribution.ts: gate the New Chat keybinding on EditorAreaFocusContext.negate()
  • sessions/contrib/sessions/browser/views/sessionsViewActions.ts: same gating on the second Ctrl+N keybinding rule that targets workbench.action.chat.newChat

Introduces a workbench-wide `editorAreaFocus` context key bound by the
base `EditorPart` so it is set whenever focus is inside any editor part
(main, modal, or auxiliary). The Agents window's Ctrl/Cmd+N keybindings
that open a new chat are now gated on the editor area not having focus,
so pressing Ctrl/Cmd+N inside an editor falls through to the standard
`workbench.action.files.newUntitledFile` command.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 16:08
@benibenj benibenj enabled auto-merge (squash) June 2, 2026 16:11
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

This PR prevents the Agents window’s Ctrl/Cmd+N “New Chat” keybindings from overriding the standard “New Untitled File” behavior when focus is inside any editor area (main, modal, or auxiliary). It does this by introducing a workbench-wide context key (editorAreaFocus) that is true only for the active scoped context of an EditorPart.

Changes:

  • Add a new workbench context key EditorAreaFocusContext (editorAreaFocus).
  • Bind editorAreaFocus on EditorPart’s scoped context key service so it’s active only when focus is within an editor part’s DOM scope.
  • Gate the Agents window Ctrl/Cmd+N bindings for workbench.action.sessions.newChat and workbench.action.chat.newChat with when: EditorAreaFocusContext.negate() so editor-focused Ctrl/Cmd+N falls through to workbench.action.files.newUntitledFile.
Show a summary per file
File Description
src/vs/workbench/common/contextkeys.ts Introduces the new editorAreaFocus RawContextKey.
src/vs/workbench/browser/parts/editor/editorPart.ts Binds editorAreaFocus to the editor part’s scoped context to reflect focus within any editor area.
src/vs/sessions/contrib/chat/browser/chat.contribution.ts Gates the sessions “New Chat” action keybinding to avoid overriding editor shortcuts when editor area has focus.
src/vs/sessions/contrib/sessions/browser/views/sessionsViewActions.ts Gates the workbench.action.chat.newChat Ctrl/Cmd+N rule so it won’t shadow editor-focused Ctrl/Cmd+N.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

@benibenj benibenj merged commit 9596a10 into main Jun 2, 2026
26 checks passed
@benibenj benibenj deleted the benibenj/agents/editor-focus-context-ctrl-n-behavior branch June 2, 2026 16:46
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone Jun 2, 2026
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.

3 participants