mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-19 23:17:16 +03:00
Fix unloading serialization test
This commit is contained in:
parent
57e6927f2a
commit
351b624487
@ -258,7 +258,7 @@ describe('AtomEnvironment', () => {
|
||||
atomEnv.destroy()
|
||||
})
|
||||
|
||||
it('ignores mousedown/keydown events happening after calling unloadEditorWindow', () => {
|
||||
it('ignores mousedown/keydown events happening after calling prepareToUnloadEditorWindow', async () => {
|
||||
const atomEnv = new AtomEnvironment({
|
||||
applicationDelegate: global.atom.applicationDelegate
|
||||
})
|
||||
@ -276,18 +276,19 @@ describe('AtomEnvironment', () => {
|
||||
|
||||
let mousedown = new MouseEvent('mousedown')
|
||||
atomEnv.document.dispatchEvent(mousedown)
|
||||
atomEnv.unloadEditorWindow()
|
||||
expect(atomEnv.saveState).not.toHaveBeenCalled()
|
||||
await atomEnv.prepareToUnloadEditorWindow()
|
||||
expect(atomEnv.saveState).toHaveBeenCalledWith({isUnloading: true})
|
||||
|
||||
advanceClock(atomEnv.saveStateDebounceInterval)
|
||||
idleCallbacks.shift()()
|
||||
expect(atomEnv.saveState).not.toHaveBeenCalled()
|
||||
expect(atomEnv.saveState.calls.length).toBe(1)
|
||||
|
||||
mousedown = new MouseEvent('mousedown')
|
||||
atomEnv.document.dispatchEvent(mousedown)
|
||||
advanceClock(atomEnv.saveStateDebounceInterval)
|
||||
idleCallbacks.shift()()
|
||||
expect(atomEnv.saveState).not.toHaveBeenCalled()
|
||||
expect(atomEnv.saveState.calls.length).toBe(1)
|
||||
|
||||
atomEnv.destroy()
|
||||
})
|
||||
|
@ -800,24 +800,7 @@ class AtomEnvironment {
|
||||
this.disposables.add(this.applicationDelegate.onApplicationMenuCommand(this.dispatchApplicationMenuCommand.bind(this)))
|
||||
this.disposables.add(this.applicationDelegate.onContextMenuCommand(this.dispatchContextMenuCommand.bind(this)))
|
||||
this.disposables.add(this.applicationDelegate.onURIMessage(this.dispatchURIMessage.bind(this)))
|
||||
this.disposables.add(this.applicationDelegate.onDidRequestUnload(async () => {
|
||||
try {
|
||||
await this.saveState({isUnloading: true})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
const closing = !this.workspace || await this.workspace.confirmClose({
|
||||
windowCloseRequested: true,
|
||||
projectHasPaths: this.project.getPaths().length > 0
|
||||
})
|
||||
|
||||
if (closing) {
|
||||
this.unloading = true
|
||||
await this.packages.deactivatePackages()
|
||||
}
|
||||
return closing
|
||||
}))
|
||||
this.disposables.add(this.applicationDelegate.onDidRequestUnload(this.prepareToUnloadEditorWindow.bind(this)))
|
||||
|
||||
this.listenForUpdates()
|
||||
|
||||
@ -896,6 +879,25 @@ class AtomEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
async prepareToUnloadEditorWindow () {
|
||||
try {
|
||||
await this.saveState({isUnloading: true})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
const closing = !this.workspace || await this.workspace.confirmClose({
|
||||
windowCloseRequested: true,
|
||||
projectHasPaths: this.project.getPaths().length > 0
|
||||
})
|
||||
|
||||
if (closing) {
|
||||
this.unloading = true
|
||||
await this.packages.deactivatePackages()
|
||||
}
|
||||
return closing
|
||||
}
|
||||
|
||||
unloadEditorWindow () {
|
||||
if (!this.project) return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user