openLocations() flag to require a path to be an existing directory

This commit is contained in:
Ash Wilson 2019-01-24 10:19:01 -05:00
parent 5a82278b8f
commit f6837d1f97
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A
2 changed files with 17 additions and 2 deletions

View File

@ -669,6 +669,21 @@ describe('AtomEnvironment', () => {
expect(atom.workspace.getTextEditors().map(e => e.getPath())).toEqual([pathToOpen])
expect(atom.project.getPaths()).toEqual([])
})
it('may be required to be an existing directory', async () => {
const nonExistent = path.join(__dirname, 'no')
const existingFile = __filename
const existingDir = path.join(__dirname, 'fixtures')
await atom.openLocations([
{pathToOpen: nonExistent, mustBeDirectory: true},
{pathToOpen: existingFile, mustBeDirectory: true},
{pathToOpen: existingDir, mustBeDirectory: true}
])
expect(atom.workspace.getTextEditors()).toEqual([])
expect(atom.project.getPaths()).toEqual([existingDir])
})
})
describe('when the opened path is handled by a registered directory provider', () => {

View File

@ -1386,7 +1386,7 @@ or use Pane::saveItemAs for programmatic saving.`)
if (stats.isDirectory()) {
// Directory: add as a project folder
foldersToAddToProject.add(this.project.getDirectoryForProjectPath(pathToOpen).getPath())
} else if (stats.isFile()) {
} else if (stats.isFile() && !location.mustBeDirectory) {
// File: add as a file location
fileLocationsToOpen.push(location)
}
@ -1397,7 +1397,7 @@ or use Pane::saveItemAs for programmatic saving.`)
if (directory) {
// Found: add as a project folder
foldersToAddToProject.add(directory.getPath())
} else {
} else if (!location.mustBeDirectory) {
// Not found: open as a new file
fileLocationsToOpen.push(location)
}