Repository navigation
Restore atom environment when adding project folders to a fresh window - #13963
BinaryMuse merged 25 commits into
Conversation
This takes an existing Atom environment and restores a saved state from the IndexDB state storage into it by: 1. Serializing the existing pane items 2. Restoring the saved state 3. Deserializing the saved pane items into the newly restored environment
|
We caught more interesting edge cases.
TODO:
If you repeat steps 2 and 3 again, you'll get an exception: |
|
/cc @nathansobo for 💭 s as we chatted briefly about copying |
…-env-when-adding-folder-to-fresh-window
|
Another option is to do away with the whole idea of trying to "merge" the current session with the saved session. There are four ways in which the user might end up adding a project folder to a window that doesn't have any:
In the case of 1, 2, and 3, it seems like we could detect that the current window is "dirty" (has pane items) and then simply open a new Atom window instead of reusing the current one. In the case of 4, we could notify the user that there is a saved project state, and give them the option of opening that state in a new Atom window, or adding the folder to the current window (which would cause the user to lose that saved state, including any unsaved buffers in that state snapshot). |
Note: "clean window" is defined as 1) having an empty project and 2) having no pane items or only empty unnamed buffers Adding folder(s) * If we have a clean window, restore project state in window * If window is dirty, prompt user to * add folder to the existing window LOSING state * OR open project folder in a new window
Note: "clean window" is defined as 1) having an empty project and 2) having no pane items or only empty unnamed buffers When project is empty and there is saved state associated with the opened/added folders... * Open a file or folder (from command line or Open menu) * If we have a clean window, restore project state in window * If window is dirty, restore saved state in new window
|
So we did away with merging the current session as mentioned in the previous comment. @ungb would you mind doing some testing to help ensure we covered all the edge cases? 🙏 Note: "clean window" is defined as 1) having an empty project and 2) having no pane items or only empty unnamed buffers When project is empty and there is saved state associated with the opened/added folders...
|
…-env-when-adding-folder-to-fresh-window
9e59e2b to
c94b025
Compare
f567d77 to
ed2c399
Compare
|
LGTM! I spend some time testing this on Friday. Only edge case I saw was on mac when there's no windows open and you go to context menu nothing works but that already exist previously. This is a huge improvement for the data loss scenarios. |
|
We've been seeing some intermittent main process test failures on CI that may be caused by this PR. Here's one: |
| let emitted = false | ||
| emitter.once(event, () => { emitted = true }) | ||
| return until(`${event} is emitted`, () => emitted, timeout) | ||
| } |
There was a problem hiding this comment.
I think we could just resolve this promise explicitly when the event is emitted. The current code works but the polling seems unnecessary.
export function emitterEventPromise (emitter, event, timeout = 5000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(reject, timeout)
emitter.once(event, () => {
clearTimeout(timeoutHandle)
resolve()
})
})
}
This PR addresses #13873, where the core issue is that re-opening a project when you have a window open with no project folders simply adds those project folders to the existing window, but adding project folders does not restore state for that set of project folders
The primary bad UX that results from this is that re-opening a project from the "Recent Projects" menu when you have a fresh Atom window doesn't really restore the previous project state; it just adds those folders to the project and any unsaved work that's stored in the project state is lost, making the user a sad panda.
This addresses the problem by simply restoring the project state for a folder or set of folders when:
atomcommand,This results in happier pandas.
Edge Cases
✅ The Atom window has no project folders but already contains pane items
In this case, we serialize all the current pane items, restore the saved state from the snapshot, and then re-add the serialized pane items to the new workspace. We skip unchanged, empty editors (ones with no changes and with no content, like the one you get when "Open Empty Editor On Start" is enabled), so in the case that the user opens a new window and immediately re-opens a previously open project, the right thing should Just Happen™. It's automagical! 🌈
TODO:
❌ The Atom window has pane items that "conflict" with ones in the state snapshot
If the user already has a file open with unsaved changes, and that same file is open in the saved state snapshot, then the result of the operation is that there will be two copies of the file open, each backed by a different buffer.
This is super edge-casey as it's kinda hard to get into this state (since opening a file adds its parent folder to the project automatically), so I'm not sure if it's one we need to address. 💭 s appreciated.
TODO:
❌ Using
project.setPathsorproject.addPathdoes not trigger this behaviorRight now, the code paths for "Application: Add Project Folder" and for opening a file with the "Open" command or with
atomgo through code path thatproject.setPathsandproject.addPathdo not. We opted not to change that behavior since it would be a breaking change.Design Considerations
It turns out that serializing a text editor and then deserializing it into a new
AtomEnvironmentis not very straightforward. The sorta hacky solution implemented here so far is to:@project.buffersAtomEnvironmentstate (minus window size and fullscreen setting)@project.buffersThis feels 🙅 pretty gross 🙅 but we're not quite sure of a better way to handle it. 💭 s from @atom/core highly appreciated!
Fixes #13873
Fixes #13861
Fixes #11293
Fixes #10044