mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Transfer focus to the root view when the last focused pane is destroyed
This commit is contained in:
@@ -44,3 +44,23 @@ describe "PaneContainerModel", ->
|
||||
expect(pane1.active).toBe true
|
||||
pane1.destroy()
|
||||
expect(container.activePane).toBe null
|
||||
|
||||
# TODO: Remove this behavior when we have a proper workspace model we can explicitly focus
|
||||
describe "when the last pane is removed", ->
|
||||
[container, pane, surrenderedFocusHandler] = []
|
||||
|
||||
beforeEach ->
|
||||
pane = new PaneModel
|
||||
container = new PaneContainerModel(root: pane)
|
||||
container.on 'surrendered-focus', surrenderedFocusHandler = jasmine.createSpy("surrenderedFocusHandler")
|
||||
|
||||
describe "if the pane is focused", ->
|
||||
it "emits a 'surrendered-focus' event", ->
|
||||
pane.focus()
|
||||
pane.destroy()
|
||||
expect(surrenderedFocusHandler).toHaveBeenCalled()
|
||||
|
||||
describe "if the pane is not focused", ->
|
||||
it "does not emit an event", ->
|
||||
expect(pane.focused).toBe false
|
||||
expect(surrenderedFocusHandler).not.toHaveBeenCalled()
|
||||
|
||||
@@ -51,6 +51,7 @@ class PaneContainerModel extends Model
|
||||
panes[nextIndex].focus()
|
||||
true
|
||||
else
|
||||
@emit 'surrendered-focus'
|
||||
false
|
||||
|
||||
focusPreviousPane: ->
|
||||
|
||||
@@ -21,6 +21,7 @@ class PaneContainer extends View
|
||||
@model = new PaneContainerModel({root: params?.root?.model})
|
||||
|
||||
@subscribe @model.$root, 'value', @onRootChanged
|
||||
@subscribe @model, 'surrendered-focus', @onSurrenderedFocus
|
||||
|
||||
@subscribe this, 'pane:attached', (event, pane) =>
|
||||
@triggerActiveItemChange() if @getActivePane() is pane
|
||||
@@ -89,6 +90,9 @@ class PaneContainer extends View
|
||||
@append(view)
|
||||
view.makeActive?()
|
||||
|
||||
onSurrenderedFocus: =>
|
||||
atom?.workspaceView?.focus()
|
||||
|
||||
removeChild: (child) ->
|
||||
throw new Error("Removing non-existant child") unless @getRoot() is child
|
||||
@setRoot(null)
|
||||
|
||||
Reference in New Issue
Block a user