Vscode: Remember all UI state even when reopening window without workspace

Created on 19 Nov 2015  路  64Comments  路  Source: microsoft/vscode

Currently, reopen files behaviour is slightly weird. If no folders are open, no files are reopened upon restart of VSC. If a folder is open, any files that are opened, inside the opened folder or not, are reopened upon restart of VSC.

I would like to see VSC reopen files, regardless the opened folder count. Should probably be settable in the preferences, I can imagine not everyone is interested in this behaviour.

feature-request on-testplan

Most helpful comment

I love Code but this thing is driving me crazy. All I want to set is when starting Code: restore last state, that is the window as I left it when last exit with groups, tabs (all of them), last caret position for every file, everything ! (no more nor less). Or just at least, if I could save the current state in a session that I could restore when I need it. Both should be possible and it is a legitimate user expectation from such an code editor.

Currently, when I'm just using Code as a daily text editor to open some bunch of code files from miscellaneous places and no folder is open, even with

"window.reopenFolders": "all"
"files.hotExit": "onExit",

only the dirty/unsaved files will be restored. All others are to be opened one by one via the recent files menu.

Very annoying since there is no easy workaround like sessions management.

Please add an command line argument to force to restore last state like --restore then a setting to control the restore last state feature like "window.restorePreviousState" with these options:

  • on : restore only if those command line arguments are not used [-n, -g, _file_, _folder_, -d]
    or if those arguments are used in conjunction with --restore : [-g, _file_, _folder_]
  • off : always off except if launched with --restore
  • force : like if it were launched with --restore

    --restore would be always ignored if [-n, -d] exist.

I hope to see something like that in a very next future.

Current setup: v1.10.2 on Win 10 x64 pro.

All 64 comments

Fair request.

+1

Not sure about the scope of this issue, but I have a related problem. Let me know if I should report it in a separate issue.

If I have multiple projects open in VS Code (e.g. 2 separate windows, each with a folder loaded) and I restart VS Code (e.g. due to an update), only the last project that was opened gets automatically reloaded.

I think it should be on VS Code to completely restore the UI state after a restart. Chrome, for example, does this--it reloads both the correct number of windows, as well as the correct tabs within each window.

I understand from the discussion in #264 that there is some issue with restoring state for standalone files that are opened (as opposed folders), but in my case it was 2 folders that were open.

I'm running Code 0.10.3 on OS X.

@nchammas you can enable restoring of all windows through the window.reopenFolders setting. Set it to all and you should be all set.

Oh snap. Good call--that did the job. :+1:

So if no folders are open, opened files are not reopened after restart VSC? A bit dumb.

Yes, only if you open a folder we remember all UI state.

I've been bit by this already several times, as a reload (from an extension update) loses all my non-workspace-associated open files. It's kind of driving me crazy, as extension updates are very frequent.

I understand the association with workspaces, but I am also using vscode a lot as a "regular" text editor, calling it up from the cmd line to open files all over my filesystem. It's a fantastic general-purpose editor in addition to a project-oriented IDE, but this issue gets in the way of that usage pattern.

Thinking out loud possible solutions: how about having a "mock" workspace, tied to a special internal name (not on the filesystem) that would simply record all open paths as absolute? This would be the "dump bucket" for all other open files, and could be restored as a group. I'd be OK if the restored individual files, on reopen, all get sent to a single window (to avoid the complexities of tracking them per-window).

Just a thought. In any case, great job overall with VSCode, I'm loving it!

@ranjan-ranjan not technically, this however will probably be a pre-requisite to hot-exit (#101) working for empty workspaces https://github.com/Microsoft/vscode/issues/13733

Right now folder workspaces record the state of the editors in local storage under the storage://workspace/<path>/memento/workbench.editors.files.textfileeditor key.

Empty workspaces have a similar prefix in local storage: storage://workspace/__$noWorkspace__memento/, but workbench.editors.files.textfileeditor is not recorded. This is likely the case because there is only a single empty workspace key and multiple windows writing that sort of data to the same key would be very messy. It's also noteworthy to call out there is no slash after __$noWorkspace__, I imagine this was an oversight in the original implementation.

One solution for enabling this is to generate a random hash to be known as the workspace identifier and move the workspace storage to `storage://workspace/__$noWorkspace__/<hash>/. Evicting the entries would be the main difference to folder workspaces as they only need to be retained if there are backups to restore or if "window.reopenFolders": "all" is set.

Making IWorkspace exist for empty workspaces, putting the ID in IWorkspace.uid and making IWorkspace.resource optional could be done to accomplish this, this would probably have a lot of associated changes required that currently rely on IWorkspaceContextService.getWorkspace being falsy to check if it's an empty workspace.

@bpasero is this the approach you would take? Any details I'm missing about the current situation?

/cc @chrmarti (interest)

Well you take workbench.editors.files.textfileeditor as the UI state, but the reality is that there are an unlimited number of more UI state keys that contribute to the overall UI state. One reason for not supporting this is the fact that you can have multiple windows without workspace associated and then you need to start inventing identifiers.

We should also not forget that the majority of users actually likes the fact that the window opens empty. I remember once that I was always restoring the previously opened file (even for empty workspaces) and that caused an outrage by people that hated it.

Since restoring previously opened files when opening on a folder is accepted as the right thing to do, there should be a large number of users who would prefer the same without opening on a folder. Did removal of that not trigger any reactions? I still feel we don't necessarily understand the not-open-on-folder case well, because we tend to not use it that way.

@chrmarti The behavior was never present.

The use case is simple: remember (all) UI state when opening VSC, independent of the open number of folders/workspaces.

@chrmarti all I can say is that we once had a bug where we would always reopen the last used file even in the empty workspace case and I got lots of issues for such behaviour. I agree that it is hard to say if that is the majority. Though I must also say that this does not seem one of the highest voted issues so far, so maybe people got used to it.

My point is about changing the default behaviour we have today should be a decision with great care.

@bpasero reopening the last file and not the rest is a little different to restoring the entire state. Here is how some other editors work for this case:

  • Sublime: _Always_ restore the previous state when a folder is not opened.
  • Atom (1.11.2): When you open a file in Atom the folder is automatically added as a "project folder", so it seems to be a little awkward to get a state where you have a file but not the folder open. When you remove the project folder after opening a file, the state _will not_ be restored.

Regardless, we need to support hot exit on empty workspaces as only having it work on folder workspaces would seem like another bug and lead to some weird behavior when you close multiple windows at once when some have no folder opened (some will hot exit, some will prompt).

@Tyriar this was from a time where we did not have any tabs, so for most users it did not make a big difference if we restored just one file or multiple files because it looked pretty much the same.

I suggest to put the decision to restore an empty workspace with all its UI state behind a setting that is disabled by default. It will be enabled as soon as we detect the case of a hot exit, because that is a requirement to not loose any data.

Once we are more comfortable with the approach we can try to run an experiment on some users to enable this by default and see how it goes.

No matter how we decide, we need a solution that allows to persist UI state per window and not per workspace. There are several scenarios I can think of:

  • you want to persist the UI state for one ore multiple windows without workspace (= empty case)
  • you want to persist the UI state for a window that has multiple workspaces open (popular feature request)
  • you want to persist the UI state for multiple windows that all have the same workspace open (another popular feature request)

Also, the solution needs to support a migration path for our current UI state association per workspace.

Finally it gets a little bit more complicate if you add the fact that there are several ways to open VS Code with a specific path (either folder or files or both). For example, one can right click on a file to open with VS Code, would you then also expect your other windows to restore?

@bpasero For calling vscode with a filename I would expect it to restore all state + open the file outside of any workspaces, unless its part of a project already opened.

@bpasero On your question about opening a single file: I think users who enable the setting would expect their 'state' of open files and windows to be preserved in all cases, including this one. You'd probably want to remember the MRU list of windows, so we can use that to decide in which window to open the file.

Creating one folder named Empty (for example; or named JABOF) which will always be empty. And then opening that folder together with my bunch-of-files-from-all-over-the-place works for me as a workaround.
When I need to open a project folder, with files, I just do that in a new VSC window.

JABOF === Just A Bunch Of Files.
I prefer Empty, because the name Empty will show up in the Title bar.

Hi

Just adding my voice here to find a way to achieve this: now that hot exit is there, I finally got to switch to VSCode as my go-to editor for all random files on my various machines, only to discover that those files would vanish when vscode is exited/restarted.

All editors and IDEs I have used in recent years restore states, just because it is so common to keep working on something after a break, a computer restart, whatever...

Rgds

@weeblr agreed. This should be a feature of any modern powerful text editor. Hopefully they get the chance to add it soon 馃槃

Hot exit doesn't save a history of file changes per file. Dirty or not. A restart, followed by Ctrl+z on a dirty file, brings back nothing.
(Atom does. Ctrl+z restores changes even after multiple restarts. Even when the file was not dirty.)

@BobbyBabes that's tracked here https://github.com/Microsoft/vscode/issues/15135

@Tyriar Thanks I've just subscribed to that issue.
EDIT: Because of your tip.

As said before, this is really weird to see after a relaunch one file still open (because modified and not saved), and the others closed. It feels inconsistant for the user, even if people that come here knows why it's like that.

Starting to wonder if this is a case of an issue getting made too broad. I.e.

"Remember all UI state even when reopening"

(which makes it complex/hard/more work)

When all most people want is a simple
"window.reopenFiles": "all"
option

That is in fact how this issue started ;)

I love Code but this thing is driving me crazy. All I want to set is when starting Code: restore last state, that is the window as I left it when last exit with groups, tabs (all of them), last caret position for every file, everything ! (no more nor less). Or just at least, if I could save the current state in a session that I could restore when I need it. Both should be possible and it is a legitimate user expectation from such an code editor.

Currently, when I'm just using Code as a daily text editor to open some bunch of code files from miscellaneous places and no folder is open, even with

"window.reopenFolders": "all"
"files.hotExit": "onExit",

only the dirty/unsaved files will be restored. All others are to be opened one by one via the recent files menu.

Very annoying since there is no easy workaround like sessions management.

Please add an command line argument to force to restore last state like --restore then a setting to control the restore last state feature like "window.restorePreviousState" with these options:

  • on : restore only if those command line arguments are not used [-n, -g, _file_, _folder_, -d]
    or if those arguments are used in conjunction with --restore : [-g, _file_, _folder_]
  • off : always off except if launched with --restore
  • force : like if it were launched with --restore

    --restore would be always ignored if [-n, -d] exist.

I hope to see something like that in a very next future.

Current setup: v1.10.2 on Win 10 x64 pro.

Really need this - I just discovered this wonderful piece of software and am ready to drop sublime for it, but I rely on this feature of sublime pretty heavily.

I agree, this would be a really nice feature. Please fix this. Thanks!

Same deal - having to open a dummy empty folder just so that it remembers the random bunch of files I always have open is a bit of a dirty workaround. Like @agbernard I use this feature of Sublime, and am looking to switch all my editing to VSCode, but this feature that a lot of other advanced text editors have surely isn't _that_ hard to put into VSCode?

at the moment I'm working on a project that's just a couple of files and an output file. I have them open in split view. unlike other apps on macOS when I restart (or even if I close/reopen Code to refresh a plugin or apply an update) it doesn't reload my UX as it was before ... seems inconsistent with how I expect things to work on Mac

Sometimes I have multiple files from multiple folders open, and probably from different projects. I would like to restore this state when I reopen vscode.

I have been waiting for this feature for over a year and it still hasn't been implemented T_T

Most other code text editors I have used have this functionality. I use NP++ as my primary editor because I absolutely need this functionality. I have attempted to switch to VSC but this missing functionality is a deal breaker. One of the main reasons I wanted to swap to VSC as my primary text editor is because it has better lexers than are available in NP++ (yaml, json, etc).

Maybe there is a complication with this issue that we are not seeing?

But what is the problem with simply remembering all open windows, files and folders?

@cossio
I think how VSC implemented "workspaces" has made making this simple request unworkable. I'm not sure about sublime and all them, but NP++ stores all its cache/temp files etc in %appdata% (or another folder you specify). I think VSC makes a workspace file in the workspace (i.e. folder) that the user opens. If they don't open a folder, there is no workspace :( Why this doesn't just fallback to being stored in %appdata% I really don't know..

Even where reopening workspaces is implemented fully for VSC I don't think its as complete as other editors. i.e. it doesn't retain undos etc. I can close and reopen NP++ and its like I didn't even close it. All my "new 1" through to "new 17" unsaved files restore, all their history, caret positions, line bookmarks, word highlights/marks, for all my tabs restore. Its great for when windows forces you to restart for installing updates.

How about just making a "default workspace folder" in the installation directory?

I started to look into this and have some ideas how to make it work. It would probably involve introducing a new setting window.reopenWindows which deprecates window.reopenFolders that we have today. Possible values could be:

  • none: always start empty (same as window.reopenFolders: none)
  • last: restore last active window (folder or empty window)
  • folders: restore only folder windows (same as window.reopenFolders: all today)
  • all: restore all empty and folder windows

I would probably make window.reopenWindows: all the new default, but that is of course up for debate.

@bpasero I think it's good!

I have a question about the last value. Would that always be the window I close VSC from (with Ctrl+Q on Linux.) ?
Which would mean that I would always have to navigate first to the window I want to be last, before hitting Ctrl+Q ?
I'm not criticising. Just asking for my understanding.

@BobbyBabes yes, last active would be the last window that had focus before closing. If you quit from one window that has focus, that window would be restored.

OK. I was asking because the first time I read its description, I interpreted it as "restore from last time". But that didn't sound meaningful because it would restore the exact same windows and editor tabs time after time.
Thanks!

@snys98 a workspace in the installation directory is a bad idea. Running in a windows environment, to make changes in program files directory you need to be running as administrator. I wouldn't want to have open a text editor in administrator mode just for that purpose. _%appdata%_ would be a much more appropriate place for a magical (fake) workspace.

This will be available in tomorrows insider.

@bpasero Is that a newspaper?

You can give our preview releases a try from: http://code.visualstudio.com/Download#insiders

@bpasero I was just kidding. The last 2 words sound like a newspaper name. Sorry! Should have added a smilie.

:]

@bpasero Should the old setting be honored if it is set? I have "window.reopenFolders": "all" and just 'lost' all windows through a restart which used to preserve them.

@chrmarti great catch, I had a bug in my migration code 馃憤

Hi @bpasero. Just double checking, in the insiders preview looks like the new option is window.restoreWindows right? As I understand it, the value mentioned by @BobbyBabes (last) is probably the new default (now called one) right?

Looks like it is working fine. My only problem with the current version - and I'm not sure if it this is directly related - is that VS Code behavior feels odd when I have unsaved files and open a new folder.

Currently VS Code displays a prompt asking if I want to save new files. If I don't do it the files are gone forever. This happens even with "files.hotExit": "onExitAndWindowClose".

I would expect unsaved files to be "carried forward" and simply be there after I open a new folder.

If I switch between two folders or if I close a folder and open it again everything works as expected (i.e., previous unsaved files are kept - unsaved files are "bound" to the current folder). The problem only manifests itself when no folder is currently open in the editor.

Another problem is that I'm not getting the expected behavior with:

{
    "window.restoreWindows": "all",
    "files.hotExit": "onExitAndWindowClose"
}

Assume that I have two windows open, each pointing to a different folder. If I right click Visual Studio Code Icon and select "Close all windows".

I would expect both windows to be restored the next time I launch vscode, instead I'm getting either an empty window or only one of the two previously open windows.

@aaccioly can you file this as separate issue, it seems unrelated.

Hi @bpasero, ok, will do.

I would argue that "Close All Windows" should not restore the windows because you are actually closing all of them. In the same way if you close a single window we would never restore it.

If you use File > Exit the windows will restore properly and that is the intent of the window.reopenWindows setting.

@bpasero Just wanted to thank you for adding this feature, it was one of my biggest gripes with VS Code before since I work with multiple windows some of which has files from different locations. Hunting them down and re-opening them every time VS Code restarts was a pain!

^^
This!

@bpasero This is more of a question than an issue.

Situation:

Version 1.14.2
Commit cb82febafda0c8c199b9201ad274e25d9a76874e
Date 2017-07-19T23:26:08.116Z
Shell 1.6.6
Renderer 56.0.2924.87
Node 7.4.0
"uname --all" output:
Linux designbox 4.11.9-1-ARCH #1 SMP PREEMPT Wed Jul 5 18:23:08 CEST 2017 x86_64 GNU/Linux`



md5-b6be7fb3c09f425e502e0e54579d8b41



Preferences: `"window.restoreWindows": "all"`



md5-b6be7fb3c09f425e502e0e54579d8b41



One VSC window with a project folder opened. All files saved.
One VSC window with just a bunch of files opened. Some with unsaved changes.
Ctrl+Q to close all VSC windows and quit VSC.

Reopening VSC (as per the title of this issue) works as expected. Both windows are restored with all files.
Ctrl+Q again.

Then double-clicking a source file in the file manager, opens one VSC window with just the double-clicked file.
Ctrl+Q again.
Start VSC from its icon, and one window opened with just the one file (that was double-clicked from the file manager).
I restored the initial 2 windows with Ctrl+N, followed by Open recent.

I had expected that starting VSC from its icon, would first open the 2 VSC windows. And that the source file (double clicked from the file manager) would be added to one of the 2 VSC windows. And that that window would be pushed to the foreground.
Similar to what happens when there are already VSC windows opened, and you then double-click a source file from the file manager.

So my question is : is this intentional, and should I therefore open a request for this behaviour to be added ?

Hi everyone, I'm trying to change from Sublime to VS Code so keep the old files is important for me , but I just install the version: 1.15.0-insider, and I'm not able to find the property "window.reopenWindows".
I do have "window.restoreWindows": "all". And of course, is not restoring all the files previously opened.

@bpasero any suggestions? (tks in advance!)

@BobbyBabes yeah that seems like a separate issue to me, you seem to want to restore your context if you start Code via the icon and ignore sessions where you opened code with a specific file. I think it should be reported as such.

Today we simply restore your last session, no matter how you got there (e.g. by clicking the icon or opening a file).

@Curros the setting is now called "window.restoreWindows": "all". If it does not work please report a new issue with steps how to reproduce.

@bpasero Thanks for clearing that up. I'm opening a new request issue right after.

@bpasero

Today we simply restore your last session, no matter how you got there (e.g. by clicking the icon or opening a file).

Are you saying the current intended behavior is to restore all open editors, both clean and dirty, regardless of whether VS Code is launched by the icon or launched by opening a file? Because it seems to me that the "window.restoreWindows": "all" setting is only applying to the former.

No, when you open a file into a window, then we do not restore the other editors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ozsay picture ozsay  路  247Comments

Tekbr picture Tekbr  路  191Comments

jsftw86 picture jsftw86  路  361Comments

Brakkar picture Brakkar  路  364Comments

mariusa picture mariusa  路  219Comments