Visual Studio Code never reopens previous file or folder

后端 未结 7 1406
走了就别回头了
走了就别回头了 2020-12-10 00:08

I have the exact opposite Problem of this question: Visual Studio Code always reopens previous file or folder

VSCode never seems to remembery my previously opened fi

7条回答
  •  Happy的楠姐
    2020-12-10 00:49

    This will also work in case of unintended shutdown (like an OS restart for OS updates, or anything where VSCode is forcefully killed) with VSCode 1.42 (Q1 2020).

    See vscode/issue 12058 ("Save UI state periodically to prevent loss on shutdown") and PR 87158 with commit 54ab792, which includes the comment:

        // In some environments we do not get enough time to persist state on shutdown.
        // In other cases, VSCode might crash, so we periodically save state to reduce
        // the chance of loosing any state.
        // The window loosing focus is a good indication that the user has stopped working
        // in that window so we pick that at a time to collect state.
    

    bpasero adds in the issue:

    Pushed a change (#87158) that will:

    • save state every 60s
    • save state when the window looses focus

    The real fix is for Electron to provide API to detect the system shutdown case on Windows (e.g. what electron/electron#15620 suggests).

    These changes will probably not help when VSCode has focus and windows restarts, though in my testing it works when any non-vscode UI is popping up (e.g. some prompt from Windows to apply updates).
    I think this is the best we can do for now.


    Regarding the window.reopenFolders=all mentioned in issue 15949, the last (Sept 2020) comment illustrates it is not solved yet.

    Update Nov. 2020 for issue 15949 in VSCode 1.52:

    The sum of options in window.restoreWindows would then be:

    • preserve (new): all windows are restored, independent of how VSCode was started
    • all: all windows are restored, but not when you start VSCode on a file or folder
    • folders: only folders are restored, but not when you start VSCode on a file or folder
    • one: only a single window is restored, but not when you start VSCode on a file or folder
    • none: no window is ever restored

    I have pushed window.restoreWindows: preserve as new choice.
    all is still the default.

    See:

    New setting to restore previous session windows

    A new setting value preserve for the existing window.restoreWindows setting allows to enforce that every window you had opened before closing VSCode is restored when you start VSCode, even if VSCode is explicitly asked to open a specific folder or file.

    A common example is double-clicking on a file to open it in VSCode or using the terminal to open a specific file or folder.
    Without window.restoreWindows: preserve in that case, VSCode will only open the file or folder as instructed, but not restore any other window.

提交回复
热议问题