Repository navigation
Deserialize untitled editors - #9968
Conversation
There was a problem hiding this comment.
Based on the comments I read on #942, we now avoid to prompt the user when a window close request is in place. What are your thoughts on this, @atom/feedback? 💭
There was a problem hiding this comment.
Just tested with Notepad++ and it doesn't prompt to save on close. I really don't see any downside to this because even if someone closed Atom accidentally, they can just open it up again?
There was a problem hiding this comment.
When would these buffers be deserialized? Would it only be when atom is opened in the same project context? i.e. What would happen in this case:
- open atom via
atom /somepath - edit untitled buffers
- kill atom
- open atom via
atom /anotherpath
Will the scratch buffers be in this new atom window? Or only if I started it via atom /somepath?
There was a problem hiding this comment.
It will be tied to the workspace state, which is keyed on the project paths. Making it independent of the workspace state is a substantial increase in scope.
There was a problem hiding this comment.
Exactly, so following the above reproduction steps would only reopen the untitled buffers when starting it via atom /somepath.
I feel like this would be a nice byproduct, as it would allow users to have several untitled editors based on the project they're working on. I cannot think of any other drawback in not prompting to save when closing a window, 'cause serializing the state acts a nice safety net in case users want to restore their changes.
I think I should clearly state here that this will affect also editors with a path (i.e. non-untitled), although I think this is actually fine and doesn't change the thoughts I expressed above.
What do you think?
Yessssssss |
I'm unclear on whether either of the concerns you raise can actually happen in a real deserialization scenario. Problems with either would emerge from the workspace getting into an inconsistent state... We ensure we don't duplicate buffers every time we open a path. So long as we only deserialize from workspaces in which that rule was followed for every open, we shouldn't get duplicates. Also, we pretty explicitly guarantee we serializing a workspace that any buffer we reference in panes is present in our overall set of buffers. Unless I'm missing something, I think the code would be simpler if we just went all the way with ids. I do think using a random string is smart to avoid needing to update an incrementing counter after deserializing. |
Exactly, I wasn't sure about which exact guarantees we had for the deserialization path and went down the safe, defensive path instead. Like, one of my concerns was having a scenario like the following:
I am quite sure that the above steps cause I guess it's not the end of the world, but more generally speaking, I was concerned about the potential edge cases such as the one above that we might introduce by changing the logical key we use to refer to buffers. Thoughts? Maybe we should just fix those inconsistencies in Thanks! |
Interesting. I hadn't considered this edge case. I actually think our current behavior is probably wrong, in that we don't fully enforce one buffer per physical file on disk. Fixing this would probably require some weird juggling where we merge two buffers into one when paths get changed... I agree this is a weird case, but presumably having two duplicate buffers after a serialization wouldn't make it any worse, right? It's actually a bit weird that we "fix" this edge case with deserialization at this point. Ideally, deserialization reproduces the state of the workspace as faithfully as possible and we fix this at a different layer. Making a smaller change and leaving the ids in place introduces less risk, but I also think we should consider the total complexity of the system to a minimum. So that leans me toward just using ids. Another thing: Did you consider backwards compatibility? What happens when we deserialize workspaces created with older versions. Conversely, what happens when we fall back a version. Might be nice to make sure that's smooth if it's cheap to do. |
Agreed. Hopefully we're not missing other edge cases similar to the one above but I think using IDs will be just fine.
Good point. Using IDs requires introducing a conditional where we check for id presence first, falling back to path when we don't find it in the serialized state. Other than that, it seems to work just fine across multiple versions. 👍 Please, merge at will after one last 👀. Thank you! |
This made the build fail because we were checking that a TextEditor couldn't have been serialized when the path didn't exist. This is exactly the opposite we want to do for restoring untitled editors, therefore I think it's safe to delete this test. /cc: @nathansobo for extra 👀
|
Thanks for taking this on! |
|
@benogle: 💙 💚 ❤️ @nathansobo: I just noticed an inconsistency in |
# Conflicts: # package.json
654b14b to
769b7bc
Compare
|
Everything is 💚 and this seems to work quite nicely after a test-drive, so I'll go ahead and Thanks everyone for the feedback! 🙏 |
|
I upgraded to 1.4.0-beta0 now. I do not see #942 fixed on Windows 8.1.
In case of Sublime Text 3, the untitled buffer shows up as expected. Do I have to change any settings? |
|
@bhadra does it still not work in safe mode ( |
|
Keep in mind that the untitled buffers are associated with the workspace, which is saved based on the open folders in the current project. |
|
@50Wliu It does not work in safe mode. I have followed the test case as described in my previous message. @nathansobo You are right. As mentioned by @as-cii, untitled buffers are persisted if and only Atom is re-started via atom /somepath. This is significantly limited compared to Sublime Text. In Sublime Text, untitled buffers are not associated with the workspace and are persisted independent of how Sublime Text is re-started. |
|
I know the issue is closed but I just discovered save-session was merged except I don't see any of its behavior in current Atom version... In an open project I create a new tab, type some text and then quit Atom: it asks to save Oo |
|
@schmurfy This is available now in the beta channel and will be available in the next stable release of Atom (1.4.0) |
|
thanks :) |
|
This is a great new feature and I really love it, but I think more work needs to be done when you have not opened a project. A lot of the time when I need to jot down some notes I will open a new atom window (not apart of a project). When I go to close that window or restart my computer, the pop up to save the untitled notes was really great, because a lot of the time I would forget to save a note that I actually needed to keep. Because this was not a part of a project, I just lost all my notes. I think having a feature that only works on projects is a bit of an oversight, it gets you in the mindset that "It's okay if I close this without saving, it will be back when I re-open it." and then when it was not opened as a project it is gone with no prompt warning you of this. I suggest adding the prompt back for untitled tabs that are not apart of a project, or making all non project tabs all be apart of some "no project" project or something. I hope that makes sense, let me know if you have any questions. Edit: |
|
Why does This implicit project and all of its files (tabs) should be opened every time Atom is started, no matter how it is started, but only in the first window. If several windows are opened after that, they should contain their own implicit project that can have files added to them. If Atom is closed with several windows open, all windows should be re-opened the next time Atom is started (no matter how it is started). This will preserve all And lastly, to solve the several |
|
Are you guys fixing
|
Depends on atom/text-buffer#116.
Fixes #942.
Our serialization code already supported saving state for untitled
TextBufferinstances, but the problem was that we used the file's path to identify and search for buffers inTokenizedBufferandatom.project. This PR changes it so that, in addition to paths, we can make use of a uniquely generated id for eachTextBuffer.If the
TokenizedBuffer's state has a buffer path, we deserialize it exactly as before. Otherwise, we try to search by buffer id among all the project's buffers. It might be tempting to use IDs even when we have a path, but it still seems quite reasonable to just use them as a fallback for two potential problems:atom.project, we still want re-open a buffer at that location when deserializing aTokenizedBuffer(I am not sure we have any guarantee that this never happens).Feedback welcome! 🎈
/cc: @nathansobo @maxbrunsfeld @atom/feedback