mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-19 23:17:16 +03:00
Rewrite AtomApplication::openPaths() logic to find existing windows
This commit is contained in:
parent
9b40488652
commit
87a4213b6a
@ -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 _]')
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user