Skip to content

Restore the active canvas after a folder location swap - #350127

Merged
Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
agents/canvas-restores-active
Nov 24, 2026
Merged

Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
agents/canvas-restores-active

Conversation

@sandy081

Copy link
Copy Markdown
Member

Fixes #349766

In a single-folder editor window with worktrees, a canvas that was the active tab came back as a background tab after switching Folder Location to a worktree and back. The editor window closes canvases while it applies a folder location working set and reopens them afterwards, but only the Agents window path recorded whether a canvas was the active tab.

Changes

  • CanvasService remembers, per folder location, whether each canvas was the active tab when the window leaves that location.
    • On return to a location, the canvas is restored as it was there (active or background).
    • On a first visit, it keeps the state from the location just left.
    • A canvas that a failed apply already closed keeps its restore state through the 'empty' fallback.
  • The memory is in memory only, bounded to 20 locations per canvas (least recently left dropped), and cleared when the canvas closes.
  • The Agents window path is unchanged.

How to test

  1. Single-folder window with chat.editorWindow.enableWorktree on and a worktree.
  2. Open a text file and a canvas; make the canvas the active tab.
  3. Switch Folder Location to the worktree and back: the canvas is the active tab.
  4. With the text file active instead, switch and back: the text file stays active.

Validation:

  • ./scripts/test.sh --runGlob "**/canvases/test/**/*.test.js": 282 passing (new tests: issue round trip, neighbor, first visit, same location, failed apply then empty fallback, 20-location limit, closed while shown elsewhere; the failed-apply and neighbor tests fail without the fix).
  • ./scripts/test.sh --runGlob "**/contrib/workspaces/test/**/*.test.js": 87 passing.
  • ./scripts/test.sh --run src/vs/workbench/test/browser/parts/editor/editorPartsWorkingSet.test.ts: 4 passing.
  • pnpm run oxlint <changed files> and pnpm run typecheck-client: passed.
  • Live check in a throwaway Code OSS profile: the issue, neighbor and first-visit scenarios behave as above.

Written by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)

@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.149.0 milestone Nov 24, 2026
Copilot AI balanced review requested due to automatic review settings November 24, 2026 11:57

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.

🟡 Changes recommended

Canvas state handling can overwrite the wrong location’s saved activation during queued or failed folder changes and ignore destination activation preferences when a canvas remains suspended.

2 open issues
What changed in this PR

Addresses #349766 by remembering canvas tab activation across Folder Location switches in single-folder editor windows. The Agents window restoration path remains unchanged.

Changes:

  • Tracks activation per canvas and folder location, retaining up to 20 locations.
  • Adds restoration handling for first visits and failed-apply fallbacks, and clears remembered state when a canvas closes.
  • Adds regression tests and updates test harness dependencies.
File Description
src/​vs/​workbench/​contrib/​canvases/​test/​electron-browser/​canvasService.test.ts Tests activation restoration, fallbacks, retention limits, and close/reopen behavior.
src/​vs/​workbench/​contrib/​canvases/​electron-browser/​canvasService.ts Records and restores per-location canvas activation.
src/​vs/​sessions/​contrib/​canvases/​test/​electron-browser/​sessionCanvasService.test.ts Supplies the new constructor dependencies in the Agents window test harness.

Review effort: Balanced

A window without working sets of its own (the editor window) closes a canvas while it applies a folder location working set, then reopens it once the swap is done. Only the Agents window path recorded whether the canvas was the active tab, so the editor window always brought it back as a background tab.

Remember, per folder location, whether each canvas was the active tab when the window leaves that location. On return, restore the state recorded for it; on a first visit, carry over the state from the location just left. The memory is bounded and dropped when the canvas closes.

Fixes #349766

Co-authored-by: Copilot <[email protected]>
A canvas that is not open during a folder location swap, because its owner is hidden, records nothing but is now restored as the location being entered remembers it.

Co-authored-by: Copilot <[email protected]>

@connor4312 Connor Peet (connor4312) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No blocking findings. Two P2 correctness issues are noted inline.

Written by Connor's agent running GPT-6.1 Sol

…older location change

Source control working sets apply without changing the folder location; a canvas must not take over the editor they restore as the active one.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 2603744 Nov 24, 2026
37 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the agents/canvas-restores-active branch November 24, 2026 22:47
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.

Folder Location restores the previously selected canvas as a background tab

8 participants