Rewrite AtomApplication::openPaths() logic to find existing windows

This commit is contained in:
Ash Wilson 2019-04-17 15:56:49 -04:00
parent 9b40488652
commit 87a4213b6a
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A
2 changed files with 30 additions and 19 deletions

View File

@ -66,14 +66,12 @@ describe('AtomApplication', function () {
})
// This is also the case when a user clicks on a file in their file manager
// FIXME
it('opens a file', async function () {
await scenario.open(parseCommandLine(['a/1.md']))
await scenario.assert('[_ 1.md]')
})
// This is also the case when a user clicks on a folder in their file manager
// FIXME
it('opens a directory', async function () {
await scenario.open(parseCommandLine(['a']))
await scenario.assert('[a _]')
@ -118,7 +116,6 @@ describe('AtomApplication', function () {
})
// This is also the case when a user clicks on a file outside the project root in their file manager
// FIXME
it('opens a file outside the project root', async function () {
await scenario.open(parseCommandLine(['b/2.md']))
await scenario.assert('[a 2.md]')
@ -189,7 +186,6 @@ describe('AtomApplication', function () {
})
// This is also the case when a user clicks on a file outside the project root in their file manager
// FIXME
it('opens a file outside the project root', async function () {
await scenario.open(parseCommandLine(['b/2.md']))
await scenario.assert('[a _] [_ 2.md]')
@ -260,14 +256,12 @@ describe('AtomApplication', function () {
})
// This is also the case when a user clicks on a file outside the project root in their file manager
// FIXME
it('opens a file outside the project root', async function () {
await scenario.open(parseCommandLine(['b/2.md']))
await scenario.assert('[_ 2.md] [a _]')
})
// This is also the case when a user clicks on a new folder in their file manager
// FIXME
it('opens a directory other than the project root', async function () {
await scenario.open(parseCommandLine(['b']))
await scenario.assert('[b _] [a _]')

View File

@ -973,23 +973,40 @@ class AtomApplication extends EventEmitter {
let existingWindow
// Explicitly provided AtomWindow has precedence unless a new window is forced.
if (!newWindow) {
// An explicitly provided AtomWindow has precedence.
existingWindow = window
}
// If no window is specified, a new window is not forced, and at least one path is provided, locate
// an existing window that contains all paths.
if (!existingWindow && !newWindow && normalizedPathsToOpen.length > 0) {
existingWindow = this.windowForPaths(normalizedPathsToOpen, devMode)
}
// If no window is specified and at least one path is provided, locate an existing window that contains all
// provided paths.
if (!existingWindow && normalizedPathsToOpen.length > 0) {
existingWindow = this.windowForPaths(normalizedPathsToOpen, devMode)
}
// No window specified, new window not forced, no existing window found, and addition to the last window
// requested. Find the last focused window.
if (!existingWindow && !newWindow && addToLastWindow) {
let lastWindow = window || this.getLastFocusedWindow()
if (lastWindow && lastWindow.devMode === devMode) {
existingWindow = lastWindow
// No window specified, no existing window found, and addition to the last window requested. Find the last
// focused window that matches the requested dev and safe modes.
if (!existingWindow && addToLastWindow) {
existingWindow = this.getLastFocusedWindow(win => {
return win.devMode === devMode && win.safeMode === safeMode
})
}
// Fall back to the last focused window that has no project roots.
if (!existingWindow) {
existingWindow = this.getLastFocusedWindow(win => !win.hasProjectPath())
}
// One last case: if *no* paths are directories, add to the last focused window.
if (!existingWindow) {
const noDirectories =
locationsToOpen.every(location => !location.mustBeDirectory) &&
normalizedPathsToOpen.every(pathToOpen => !fs.isDirectorySync(pathToOpen))
if (noDirectories) {
existingWindow = this.getLastFocusedWindow(win => {
return win.devMode === devMode && win.safeMode === safeMode
})
}
}
}