Merge pull request #17021 from atom/aw/d-d-d-double-open

Synchronously track URIs in the process of opening
This commit is contained in:
Ash Wilson 2018-03-26 14:08:15 -04:00 committed by GitHub
commit d4185b2b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 165 additions and 109 deletions

View File

@ -274,6 +274,21 @@ describe('Workspace', () => {
})
})
it('discovers existing editors that are still opening', () => {
let editor0 = null
let editor1 = null
waitsForPromise(() => Promise.all([
workspace.open('spartacus.txt').then(o0 => { editor0 = o0 }),
workspace.open('spartacus.txt').then(o1 => { editor1 = o1 }),
]))
runs(() => {
expect(editor0).toEqual(editor1)
expect(workspace.getActivePane().items).toEqual([editor0])
})
})
it("uses the location specified by the model's `getDefaultLocation()` method", () => {
const item = {
getDefaultLocation: jasmine.createSpy().andReturn('right'),
@ -361,6 +376,28 @@ describe('Workspace', () => {
})
})
it('discovers existing editors that are still opening in an inactive pane', () => {
let editor0 = null
let editor1 = null
const pane0 = workspace.getActivePane()
const pane1 = workspace.getActivePane().splitRight()
pane0.activate()
const promise0 = workspace.open('spartacus.txt', {searchAllPanes: true}).then(o0 => { editor0 = o0 })
pane1.activate()
const promise1 = workspace.open('spartacus.txt', {searchAllPanes: true}).then(o1 => { editor1 = o1 })
waitsForPromise(() => Promise.all([promise0, promise1]))
runs(() => {
expect(editor0).toBeDefined()
expect(editor1).toBeDefined()
expect(editor0).toEqual(editor1)
expect(workspace.getActivePane().items).toEqual([editor0])
})
})
it('activates the pane in the dock with the matching item', () => {
const dock = atom.workspace.getRightDock()
const ITEM_URI = 'atom://test'

View File

@ -225,6 +225,8 @@ module.exports = class Workspace extends Model {
modal: new PanelContainer({viewRegistry: this.viewRegistry, location: 'modal'})
}
this.incoming = new Map()
this.subscribeToEvents()
}
@ -921,6 +923,17 @@ module.exports = class Workspace extends Model {
if (typeof item.getURI === 'function') uri = item.getURI()
}
let resolveItem = () => {}
if (uri) {
const incomingItem = this.incoming.get(uri)
if (!incomingItem) {
this.incoming.set(uri, new Promise(resolve => { resolveItem = resolve }))
} else {
await incomingItem
}
}
try {
if (!atom.config.get('core.allowPendingPaneItems')) {
options.pending = false
}
@ -1048,6 +1061,12 @@ module.exports = class Workspace extends Model {
const index = pane.getActiveItemIndex()
this.emitter.emit('did-open', {uri, pane, item, index})
if (uri) {
this.incoming.delete(uri)
}
} finally {
resolveItem()
}
return item
}