mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-19 23:17:16 +03:00
Include now-missing project folders in initial state key computation
This commit is contained in:
parent
07dc40362f
commit
88d7c6dbdd
@ -742,6 +742,27 @@ describe('AtomEnvironment', () => {
|
||||
expect(atom.project.getPaths()).toEqual([])
|
||||
})
|
||||
|
||||
it('includes missing mandatory project folders in computation of initial state key', async () => {
|
||||
const existingDir = path.join(__dirname, 'fixtures')
|
||||
const missingDir = path.join(__dirname, 'no')
|
||||
|
||||
atom.loadState.andCallFake(function (key) {
|
||||
if (key === `${existingDir}:${missingDir}`) {
|
||||
return Promise.resolve(state)
|
||||
} else {
|
||||
return Promise.resolve(null)
|
||||
}
|
||||
})
|
||||
|
||||
await atom.openLocations([
|
||||
{pathToOpen: existingDir},
|
||||
{pathToOpen: missingDir, mustBeDirectory: true}
|
||||
])
|
||||
|
||||
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [existingDir], [])
|
||||
expect(atom.project.getPaths(), [existingDir])
|
||||
})
|
||||
|
||||
it('opens the specified files', async () => {
|
||||
await atom.openLocations([{pathToOpen: __dirname}, {pathToOpen: __filename}])
|
||||
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [__dirname], [__filename])
|
||||
|
@ -1404,7 +1404,7 @@ or use Pane::saveItemAs for programmatic saving.`)
|
||||
// Found: add as a project folder
|
||||
foldersToAddToProject.add(directory.getPath())
|
||||
} else if (location.mustBeDirectory) {
|
||||
// Not found and must be a directory: add to missing list
|
||||
// Not found and must be a directory: add to missing list and use to derive state key
|
||||
missingFolders.push(location)
|
||||
} else {
|
||||
// Not found: open as a new file
|
||||
@ -1416,8 +1416,12 @@ or use Pane::saveItemAs for programmatic saving.`)
|
||||
}
|
||||
|
||||
let restoredState = false
|
||||
if (foldersToAddToProject.size > 0) {
|
||||
const state = await this.loadState(this.getStateKey(Array.from(foldersToAddToProject)))
|
||||
if (foldersToAddToProject.size > 0 || missingFolders.length > 0) {
|
||||
// Include missing folders in the state key so that sessions restored with no-longer-present project root folders
|
||||
// don't lose data.
|
||||
const foldersForStateKey = Array.from(foldersToAddToProject)
|
||||
.concat(missingFolders.map(location => location.pathToOpen))
|
||||
const state = await this.loadState(this.getStateKey(Array.from(foldersForStateKey)))
|
||||
|
||||
// only restore state if this is the first path added to the project
|
||||
if (state && needsProjectPaths) {
|
||||
|
Loading…
Reference in New Issue
Block a user