Skip to content

VS Code should restore windows to their original spaces when possible #979

Closed

Description

I have "window.reopenFolders": "all" set, and when I restart VS Code it correctly restores all the folders I had open. However, it restores them to the same OS X space, as opposed to the spaces they were originally in.

When VS Code is restarted it should try to restore the windows that were open to the spaces they were originally in.

Activity

  1. added
    bug
    on Dec 4, 2015
  2. bpasero commented on Dec 4, 2015

    @bpasero
    Contributor

    Have to check if there is API in Electron to find out about spaces.

  3. added
    feature-request
    upstream
    and removed
    bug
    on Dec 22, 2015
  4. bpasero commented on Dec 12, 2016

    @bpasero
    Contributor

    From: #16991

    Steps to Reproduce:

    1. Create multiple Spaces for the current User.
    2. Open Visual Studio Code on macOS (any version 10.7+).
    3. Open a Folder (or new window) multiple times: once, at least, in each Space you created in Step 1.
      • Ensure you have the window.reopenFolders setting set to all.
    4. Perform one of the following Sudden Termination actions:
      1. Logout of the current User. Log back into the same user.
      2. Shut Down the computer. Turn the computer back on.
      3. Restart the computer.

    Expected Results:

    Visual Studio Code's windows restore to the Spaces they were in when the action in Step 4 took place.

    Actual Results:

    Visual Studio Code restores all windows to the current Space (typically "Desktop 1") when the user is properly logged back in. They must be manually reassigned to the previous spaces.

    Errata:

    • Compare Visual Studio Code's results with that of Apple's built-in applications: all windows of Apple-built apps correctly restore to the Space they existed in prior to the Sudden Termination event.
    • Apple does offer the ability to Assign apps to Spaces. However, this only adjusts what Space the Windows start in. If a user intentionally moves the windows to different Spaces then all Windows would recollect to that space upon restart instead of the previously assigned Space (as expected). In short, this is not a solution to the problem.
    • Use Case: A developer creates three Spaces and opens a folder in a unique Visual Studio Code window on each Space. These Spaces serve different development contexts for the developer. When restarting (say from OS update), the developer expects the windows to restore to the previously used Space.
    • According to Apple Developer Relations, apps that wish to support this feature must "use NSWindow’s encodeRestorableStateWithCoder: and restoreStateWithCoder:" (those APIs are part of NSResponder). This is also somewhat outlined here.
  5. nchammas commented on Dec 12, 2016

    @nchammas
    Author

    Eric Robinson (@ericdrobinson) - I find that this problem exists even if I restart VS Code normally (i.e. not a sudden termination event). For example, when VS Code restarts to upgrade itself, I have to manually reassign all the windows I had open to their correct Space.

  6. ericdrobinson commented on Dec 12, 2016

    @ericdrobinson

    Nicholas Chammas (@nchammas):

    when VS Code restarts to upgrade itself, I have to manually reassign all the windows I had open to their correct Space.

    This, unfortunately, is not something that is supported by macOS - it is a failing on Apple's side, not Visual Studio Code. It turns out that macOS only supports Spaces restoration on a reboot. You can test this yourself with Apple's built-in applications (e.g. Safari, Text Edit, Terminal, Quicktime, etc.). In simple application-restart scenarios, Apple's application windows do restore the previous visual state (as much as possible), but they do not properly restore previously used Spaces. [I, too, was surprised to find this to be the case when I specifically tested it...]

    With respect to your initial comment:

    Chrome, for example, does this correctly most some of the time.

    This is 100% false. Current versions of Chrome will always restore to the default Space (typically Desktop 1) unless you've specifically assigned it to a Space through the Dock interface. This is a link to the Chromium Bug report that describes this issue for that application. This comment outlines the difference between simple "App Restart" and "System Reboot" in terms of what's supported.

    The thread linked above has a lot of good information about this issue with respect to OS-integration and expectations. If you wish macOS would support Space reassignment on basic Application Restart, I'd suggest filing a bug report with Apple. The more of us that do so, the more likely they will be to enable it.

  7. nchammas commented on Dec 12, 2016

    @nchammas
    Author

    This is 100% false. Current versions of Chrome will always restore to the default Space (typically Desktop 1) unless you've specifically assigned it to a Space through the Dock interface.

    I believe you are correct. I will remove that comment from my original post.

    If you wish macOS would support Space reassignment on basic Application Restart, I'd suggest filing a bug report with Apple. The more of us that do so, the more likely they will be to enable it.

    Is there no existing bug report we can just watch or add a +1 to? Otherwise, yes, I'll file a report assuming that's the appropriate thing to do.

  8. 5 remaining items

  9. added
    electron
    and removed on Nov 16, 2017
  10. removed this from the Backlog milestone on Nov 17, 2017
  11. added
    workbench-window
    and removed
    workbench-electron
    on Aug 6, 2018
  12. bpasero commented on Oct 10, 2019

    @bpasero
    Contributor

    The upstream issue has been closed as wontfix. That means, same here, sorry.

  13. added
    *out-of-scope
    on Oct 10, 2019
  14. vscodebot commented on Oct 10, 2019

    @vscodebot

    This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

    If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

    Thanks for your understanding and happy coding!

  15. ericdrobinson commented on Oct 11, 2019

    @ericdrobinson

    Benjamin Pasero (@bpasero) Hilariously, the über-upstream issue (in Chromium) was actually fixed on September 30th. I've posted in the upstream issue with clarification on whether that fix will affect Electron or not. Fingers are crossed, but this may become feasible once Electron updates to a Chromium version that contains the fix...

  16. anentropic commented on Mar 11, 2022

    @anentropic

    despite whatever issues there may be with the facilities provided by macos, iTerm and Sublime Text seem to manage to do this, as well as Chrome

  17. gavofyork commented on Mar 3, 2023

    @gavofyork

    Then surely this should now be reopened.

  18. ericdrobinson commented on Mar 3, 2023

    @ericdrobinson

    Gavin Wood (@gavofyork) What are you referring to?

    Benjamin Pasero (@bpasero) Can you please consider reopening this issue? It seems awkward to allow #152869 to remain open while this one is closed.

    What's more, while the "upstream" issue (electron/electron#10124) was closed, another Electron maintainer (Samuel Attard (@MarshallOfSound)) has suggested that this feature is something that apps (e.g. VS Code) can directly implement themselves:

    This is something apps can implement (by saving window location on quit and restoring on start)

    As such, the "upstream" issue wouldn't necessarily even be a blocker in the first place.

  19. bpasero commented on Mar 4, 2023

    @bpasero
    Contributor

    We track this still at #123517

  20. ericdrobinson commented on Mar 4, 2023

    @ericdrobinson

    What's more, while the "upstream" issue (electron/electron#10124) was closed, another Electron maintainer (Samuel Attard (@MarshallOfSound)) electron/electron#15211 (comment) that this feature is something that apps (e.g. VS Code) can directly implement themselves:

    This is something apps can implement (by saving window location on quit and restoring on start)

    As such, the "upstream" issue wouldn't necessarily even be a blocker in the first place.

    I dug into this a bit and I now suspect that there is indeed no way for apps to implement this feature without upstream work. As such I have issued a formal feature request in the Electron repository for support for this.

    I will also move future comments to #123517. Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    *out-of-scopeelectronfeature-requestupstreamworkbench-window

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions