From a61accf175aa7e52c015ace087279b4dbbd25558 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 2 May 2017 10:34:14 -0700 Subject: [PATCH] Don't change focus when hiding an unfocused dock --- spec/dock-spec.js | 15 ++++++++++++++- src/dock.js | 2 +- src/workspace.js | 6 ++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/spec/dock-spec.js b/spec/dock-spec.js index e5e26fd3a..0608980fc 100644 --- a/spec/dock-spec.js +++ b/spec/dock-spec.js @@ -17,7 +17,7 @@ describe('Dock', () => { }) describe('when a dock is hidden', () => { - it('transfers focus back to the active center pane', () => { + it('transfers focus back to the active center pane if the dock had focus', () => { jasmine.attachToDOM(atom.workspace.getElement()) const dock = atom.workspace.getLeftDock() dock.activate() @@ -31,6 +31,19 @@ describe('Dock', () => { dock.toggle() expect(document.activeElement).toBe(atom.workspace.getCenter().getActivePane().getElement()) + + // Don't change focus if the dock was not focused in the first place + const modalElement = document.createElement('div') + modalElement.setAttribute('tabindex', -1) + atom.workspace.addModalPanel({item: modalElement}) + modalElement.focus() + expect(document.activeElement).toBe(modalElement) + + dock.show() + expect(document.activeElement).toBe(modalElement) + + dock.hide() + expect(document.activeElement).toBe(modalElement) }) }) diff --git a/src/dock.js b/src/dock.js index 4d9232a31..0e6d60e4e 100644 --- a/src/dock.js +++ b/src/dock.js @@ -151,7 +151,7 @@ module.exports = class Dock { this.state = nextState this.render(this.state) - if (didHide) this.didHide() + if (didHide) this.didHide(this) } render (state) { diff --git a/src/workspace.js b/src/workspace.js index cbf38602f..59f165c45 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -470,8 +470,10 @@ module.exports = class Workspace extends Model { } } - didHideDock () { - this.getCenter().activate() + didHideDock (dock) { + if (dock === this.activePaneContainer) { + this.getCenter().activate() + } } setDraggingItem (draggingItem) {