Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve untitled files for next time #4985

Closed
1 task done
Tracked by #7371 ...
assayire opened this issue Feb 28, 2023 · 31 comments
Closed
1 task done
Tracked by #7371 ...

Preserve untitled files for next time #4985

assayire opened this issue Feb 28, 2023 · 31 comments
Labels
feature [core label] priority A high priority issue serialization Restoration of the editor state after a restart workspace Feedback for workspace management, layout, interactions, etc

Comments

@assayire
Copy link

Check for existing issues

  • Completed

Describe the feature

As a Zed lover, I want Zed to not ask to save/delete untitled files when quitting the app but preserve them as is, and have them available for me to work on next time I open zed.

PS: Feature can be tried out in Sublime Text and couple of other editors.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

@assayire assayire added feature [core label] triage labels Feb 28, 2023
@JosephTLyons JosephTLyons added workspace Feedback for workspace management, layout, interactions, etc serialization Restoration of the editor state after a restart and removed triage labels Feb 28, 2023
@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@porsager
Copy link

porsager commented Feb 5, 2024

Very much miss this feature, but one super important thing - if it is added - is absolute certainty that you won't loose content in these "unsaved buffers/documents". Once you start relying on this feature it's an extremely great way to keep notes / snippets, etc, but it needs to be something you can trust. I have 9 year old unsaved content in Sublime, which I'd love to move over, but I don't want to risk loosing them (happened a couple of times in the good old textmate days during an upgrade).

@jacksongoode
Copy link

Agree, this is without a doubt a feature I can't migrate to Zed from Sublime without.

@Parithi
Copy link

Parithi commented Mar 26, 2024

+1 Looking forward to having this feature on Zed. This is the one that stops me from migrating from VSCode.

@ddegner
Copy link

ddegner commented Apr 14, 2024

Cat sat on my power button and force quit everything. Lost an hour or so of writing.

Hopefully the feature will save me next time.

@akano-su
Copy link

Just ran into this issue and was very upset. Zed. Please. Since Atom stopped development, I haven't migrated to another text editor but you were SUPPOSED TO BE THE ONE!!

@NicolayD
Copy link

Chiming in on this - this would allow users to use new tabs for notes. It would be immensely helpful.

@ylluminate
Copy link

It looks like this is in progress. Any idea of a timetable we'll see this ready? I also think a lot of us are waiting for this to really kick Zed's tires.

@rgilbert82

This comment has been minimized.

@selfish
Copy link

selfish commented Jun 9, 2024

Chiming in - this is the only thing stopping me from uninstalling Sublime and fully making the switch.

@mileusna
Copy link

I was just about to raise this issue too. All major editors like VS Code and Sublime preserve unsaved files. Zed should do the same, especially considering its frequent updates that require restarts.

@ddegner
Copy link

ddegner commented Jun 15, 2024

Cat sat on my power button and force quit everything. Lost an hour or so of writing.

Hopefully the feature will save me next time.

Bug fixed. The cat has a new home.

@MemeKing
Copy link

I would love for this feature to be added. It's more than just a convenience, it's practically a whole lifestyle.

mrnugget added a commit that referenced this issue Jul 17, 2024
This adds the ability for Zed to restore unsaved buffers on restart. The
user is no longer prompted to save/discard/cancel when trying to close a
Zed window with dirty buffers in it. Instead those dirty buffers are
stored and restored on restart.

It does this by saving the contents of dirty buffers to the internal
SQLite database in which Zed stores other data too. On restart, if there
are dirty buffers in the database, they are restored.

On certain events (buffer changed, file saved, ...) Zed will serialize
these buffers, throttled to a 100ms, so that we don't overload the
machine by saving on every keystroke. When Zed quits, it waits until all
the buffers are serialized.


### Current limitations
- It does not persist undo-history (right now we don't persist/restore
undo-history regardless of dirty buffers or not)
- It does not restore buffers in windows without projects/worktrees.
Example: if you open a new window with `cmd-shift-n` and type something
in a buffer, this will _not_ be stored and you will be asked whether to
save/discard on quit. In the future, we want to fix this by also
restoring windows without projects/worktrees.

### Demo



https://github.com/user-attachments/assets/45c63237-8848-471f-8575-ac05496bba19



### Related tickets

I'm unsure about closing them, without also fixing the 2nd limitation:
restoring of worktree-less windows. So let's wait until that.

- #4985
- #4683

### Note on performance

- Serializing editing buffer (asynchronously on background thread) with
500k lines takes ~200ms on M3 Max. That's an extreme case and that
performance seems acceptable.

Release Notes:

- Added automatic restoring of unsaved buffers. Zed can now be closed
even if there are unsaved changes in buffers. One current limitation is
that this only works when having projects open, not single files or
empty windows with unsaved buffers. The feature can be turned off by
setting `{"session": {"restore_unsaved_buffers": false}}`.

---------

Co-authored-by: Bennet <bennet@zed.dev>
Co-authored-by: Antonio <antonio@zed.dev>
@mrnugget
Copy link
Member

A first version of this has been merged: #13546

It'll go into Preview release this week, on Wednesday. Stable release next week, pending any bug fixes or revision.

Please see the constraints in the pull request description that apply to this version.

@ddegner
Copy link

ddegner commented Jul 22, 2024

The cat will be allowed back inside.

FullSizeRender.mov

mrnugget added a commit that referenced this issue Jul 23, 2024
This adds the ability for Zed to restore multiple windows after
restarting. It's now the default behavior.

Release Notes:

- Added ability to restore all windows that were open when Zed was quit.
Previously only the last used workspace was restored. This is now the
default behavior. To get back the old behavior, add the following to
your settings: `{"restore_on_startup": "last_workspace"}` (Part of
[#4985](#4985) and
[#4683](#4683))

Demo:



https://github.com/user-attachments/assets/57a375ec-0c6a-4724-97c4-3fea8f18bc2d

---------

Co-authored-by: Nathan <nathan@zed.dev>
@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Jul 24, 2024

The following PRs have added quite a bit to the workspace serialization story:

There are a few known missing bits here, but I think its best that we close this issue out, in favor of new issues that describe those missing bit, so that we can get a clear understanding of how important these bits are to you all, now that most of the functionality has landed. Here are the new issues (upvote via 👍):

Killer work @mrnugget!

@selfish
Copy link

selfish commented Jul 24, 2024

Thank you @JosephTLyons!
I understand the decision to close that issue. With that I think it's important to mention that #15098 is actually the main reason this feature is so desired. Open a new buffer, type something in, and just know it won't be lost.

@JosephTLyons
Copy link
Collaborator

Thank you @JosephTLyons! I understand the decision to close that issue. With that I think it's important to mention that #15098 is actually the main reason this feature is so desired. Open a new buffer, type something in, and just know it won't be lost.

Note that this will work right now (in today's preview release) if you are opening an untitled buffer and there's a worktree in your project panel.

Screen.Recording.2024-07-24.at.6.14.16.PM.mov

The only case in which this doesn't work is if you open up a brand new instance of Zed, one that has no projects in it, and then open a new file. I think we definitely want that, but I think a lot of the headache (80 percent or more) has been addressed by @mrnugget's PRs.

CharlesChen0823 pushed a commit to CharlesChen0823/zed that referenced this issue Jul 29, 2024
…ustries#14965)

This adds the ability for Zed to restore multiple windows after
restarting. It's now the default behavior.

Release Notes:

- Added ability to restore all windows that were open when Zed was quit.
Previously only the last used workspace was restored. This is now the
default behavior. To get back the old behavior, add the following to
your settings: `{"restore_on_startup": "last_workspace"}` (Part of
[zed-industries#4985](zed-industries#4985) and
[zed-industries#4683](zed-industries#4683))

Demo:



https://github.com/user-attachments/assets/57a375ec-0c6a-4724-97c4-3fea8f18bc2d

---------

Co-authored-by: Nathan <nathan@zed.dev>
@SimbaNinja917
Copy link

I am on Zed Zed 0.150.4 my MBP M1 froze and restarted, and I had an untitled document with very important info, Zed restarted empty. Any chance I can recover it from somewhere?

@mrnugget
Copy link
Member

mrnugget commented Sep 5, 2024

I am on Zed Zed 0.150.4 my MBP M1 froze and restarted, and I had an untitled document with very important info, Zed restarted empty. Any chance I can recover it from somewhere?

Was that file in a project-less window? i.e. just a single window with unnamed buffers? Because those aren't persisted yet (see above).

But here's what you can do to check whether it's been saved:

sqlite3 ~/Library/Application\ Support/Zed/db/0-stable/db.sqlite 'select contents from editors where contents is not null;'

(That's on macOS, on Linux the path is different.)

This returns the contents of all files where content has been saved.

@SimbaNinja917
Copy link

I am on Zed Zed 0.150.4 my MBP M1 froze and restarted, and I had an untitled document with very important info, Zed restarted empty. Any chance I can recover it from somewhere?

Was that file in a project-less window? i.e. just a single window with unnamed buffers? Because those aren't persisted yet (see above).

But here's what you can do to check whether it's been saved:

sqlite3 ~/Library/Application\ Support/Zed/db/0-stable/db.sqlite 'select contents from editors where contents is not null;'

(That's on macOS, on Linux the path is different.)

This returns the contents of all files where content has been saved.

this returned files saved previously as part of a project.
what i had lost was just an open window not part of a project on which i was taking meeting notes. and then lost it all.

@Timoffey
Copy link

Timoffey commented Oct 6, 2024

When I was in a switching process from sublime to zed, this feature worked.
But now, on Cmd+Q it asks me if I want to save changes, and if I update zed, it quits without saving any changes.
Maybe I need to mark anything explicitly? But I didn't find any options in the settings.

@mrnugget
Copy link
Member

mrnugget commented Oct 7, 2024

Hey @Timoffey, did you see this part in Joseph's comment?

The only case in which this doesn't work is if you open up a brand new instance of Zed, one that has no projects in it, and then open a new file.

Maybe you had an untitled window open?

@Timoffey
Copy link

Timoffey commented Oct 7, 2024

@mrnugget wow, that's true... sorry me. So I'll create a folder zed-drafts as a project to hack it. Thanks!

@ylluminate
Copy link

Fwiw, @mrnugget is going to solve this properly at some point so projects are no longer needed, so some of us are waiting to use Zed until that point.

@ovitrif
Copy link

ovitrif commented Oct 13, 2024

Exactly, another user of Sublime as actual text editor, and without this I can't really use Zed, despite loving it.

So, while I am an user, I am in no way active user and can't be without this.

Thanks and good luck @ devs, maybe once I level up my Rust game, I can help, until then I'll be just an annoying user expecting devs to do the work :D

@ylluminate
Copy link

Hey @mrnugget, any luck so far? I know several people myself in a holding pattern here before really getting into zed on this front.

@mrnugget
Copy link
Member

mrnugget commented Nov 4, 2024

Sorry, haven't had the time to look into this more with our SSH release last week. Hope to take another stab at it before the end of the year.

@ylluminate
Copy link

Thank you very much. So sorry it's such a challenge. I think this is a blocker for a lot of folks - arguably much bigger priority for many of us than the awesome ssh release.

@ylluminate
Copy link

Hi @mrnugget, any luck with your goal of having this done here?

@mrnugget
Copy link
Member

mrnugget commented Jan 7, 2025

No, sorry about that, super super busy with other things and I also don't have any traction on this issue since it requires (I think/fear) refactoring how Zed thinks about workspaces/projects/worktrees.

@ylluminate
Copy link

Very sad to hear this. Seems like Sublime Text is still the anchor editor then until we get this. Thanks and good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature [core label] priority A high priority issue serialization Restoration of the editor state after a restart workspace Feedback for workspace management, layout, interactions, etc
Projects
None yet
Development

No branches or pull requests