Merge pull request #14183 from atom/ns-fix-focus-when-toggling-docks

Properly restore focus to center when hiding dock via toggle
This commit is contained in:
Max Brunsfeld
2017-04-12 10:24:16 -07:00
committed by GitHub
2 changed files with 9 additions and 1 deletions

View File

@@ -25,6 +25,12 @@ describe('Dock', () => {
dock.hide()
expect(document.activeElement).toBe(atom.workspace.getCenter().getActivePane().getElement())
dock.activate()
expect(document.activeElement).toBe(dock.getActivePane().getElement())
dock.toggle()
expect(document.activeElement).toBe(atom.workspace.getCenter().getActivePane().getElement())
})
})

View File

@@ -112,7 +112,6 @@ module.exports = class Dock {
// was previously focused.
hide () {
this.setState({visible: false})
this.didHide()
}
// Extended: Toggle the dock's visiblity without changing the {Workspace}'s
@@ -133,12 +132,14 @@ module.exports = class Dock {
setState (newState) {
const prevState = this.state
const nextState = Object.assign({}, prevState, newState)
let didHide = false
// Update the `shouldAnimate` state. This needs to be written to the DOM before updating the
// class that changes the animated property. Normally we'd have to defer the class change a
// frame to ensure the property is animated (or not) appropriately, however we luck out in this
// case because the drag start always happens before the item is dragged into the toggle button.
if (nextState.visible !== prevState.visible) {
didHide = !nextState.visible
// Never animate toggling visiblity...
nextState.shouldAnimate = false
} else if (!nextState.visible && nextState.draggingItem && !prevState.draggingItem) {
@@ -148,6 +149,7 @@ module.exports = class Dock {
this.state = nextState
this.render(this.state)
if (didHide) this.didHide()
}
render (state) {