Skip to content

sessions: focus the main window and moved chat after Move to Main Window - #348025

Open
Sandeep Somavarapu (sandy081) wants to merge 8 commits into
mainfrom
agents/fix-347102-move-to-main-focus
Open

Sandeep Somavarapu (sandy081) wants to merge 8 commits into
mainfrom
agents/fix-347102-move-to-main-focus

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #347102

After Move to Main Window, the moved chat was not focused. Two things were wrong:

  1. The main Agents window was never raised, and the active pane's focus was deferred while another window held focus. SessionsChatWindowProvider.moveToMainWindow now, after opening the moved chats and editors, focuses the main window and then the active session. With several chats moved together, the first moved chat is re-opened (without focus) so it is the active one, matching openMovedChats order. Only user-initiated move paths reach this method; close, quit and restore paths are guarded and unchanged.
  2. Root cause of the remaining failure on real focus: the setContext autorun in ChatGroupView swaps the content view when the pane's kind changes (for example new session to chat). That detached the focused input, so focus fell to BODY. ChatGroupView now remembers whether focus was inside the old view and, once the new view is installed, focuses it. This only happens when the old view's own document is the one that has window focus (an injectable _hasWindowFocus predicate, the same pattern ChatGroupsView already uses), so a background or other-window chat never claims focus. Focus elsewhere in the same window, such as another group, the sidebar or the editor, is left untouched.

How to test: open a chat in a new window, use Move to Main Window in the chat window header; the main window comes to front with the moved chat shown and its input focused. Also move two chats of the same session together; the first should be focused.

Tests:

  • Provider tests for the focus calls, with the skip logic unchanged.
  • ChatGroupView tests with a real DOM: focus inside the old view is restored in the new view after a swap; focus elsewhere in the same document is left alone; a stale activeElement in a document that does not have window focus is not restored.
  • sessionsManagementService.test.ts "detaching a chat without dragging creates a pane that survives closing its parent": its retained check used getFocusedSessionView(), which follows DOM focus and only passed by accident (nothing was focused). It now captures the two pane elements before the parent closes and asserts exactly one stays connected and is the sole remaining pane. It no longer depends on focus or on which pane is active, which differs between the Electron and browser runners.

Validation:

  • Electron runner, sessionsManagementService.test.ts: 445 passing
  • Browser runner, node test/unit/browser/index.js --run src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts --browser chromium: 444 passing
  • ./scripts/test.sh --run on sessionsChatWindowProvider.test.ts, chatGroupsView.test.ts: 203 passing (on the fix commits, before the test-only follow-ups)
  • pnpm run typecheck-client and pnpm run oxlint on the changed files: exit 0
  • Live check on a full build in a throwaway profile with real OS focus: PASS for a single chat move (main frontmost, document.hasFocus() true, activeElement in the moved chat's input, stable when sampled every 300 ms for 3 s) and for a normal session switch while typing in main (no unexpected focus jump; weak check). Before the fix activeElement was BODY.
  • NOT RUN live: same-session multi-chat move (two chats of one session could not be created through the UI; covered by the provider and ChatGroupView tests and a reviewer trace), and the drag-out path.

@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.147.0 milestone Nov 12, 2026
Copilot AI balanced review requested due to automatic review settings November 12, 2026 23:08

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.

🟢 Approval recommended

No active review issues remain for the change restoring chat focus after moving to the main window.

No open issues 🎉

What changed in this PR

Fixes #347102 by restoring focus after Move to Main Window in the Agents window, so users can continue typing in the moved chat.

Changes:

  • Focuses the main window and active session after opening moved chats and editors.
  • Reactivates the first moved chat when several chats move together.
  • Updates tests to verify focus ordering and confirm that focus stays unchanged when no chat moves.

No actionable findings remain. Reported live validation does not cover real OS window raising, drag moves, or same-session multi-chat moves.

File Description
src/​vs/​sessions/​contrib/​chatWindow/​test/​browser/​sessionsChatWindowProvider.test.ts Records focus calls and tests successful and no-op moves.
src/​vs/​sessions/​contrib/​chatWindow/​browser/​sessionsChatWindowProvider.ts Adds main-window and session focus, preserves first-chat selection, and extracts moved-editor opening.

Review effort: Balanced

@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as draft November 12, 2026 23:41
The chat group replaces its content view when the chat settles (for example a moved chat resolving), which detached the focused input and dropped focus to the body. Move focus to the new view when the old one held it.

Co-authored-by: Copilot <[email protected]>
A document keeps its last active element while another window is focused, so a background view swap could steal focus. Also require the group's window to have focus.

Co-authored-by: Copilot <[email protected]>
The retained check compared getFocusedSessionView(), which follows DOM focus and was only equal by both being unfocused. Focus now follows a swapped view, so assert the surviving pane through the active pane state instead.

Co-authored-by: Copilot <[email protected]>
The detach test guards that re-detaching the chat of a detached pane keeps that pane. Assert the pane's element identity and attachment instead of the focused view.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as ready for review November 13, 2026 08:30
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

This branch has not been deployed

No deployments
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.

moving a side chat back to the agents window does not give it focus

6 participants