diff --git a/spec/pane-container-model-spec.coffee b/spec/pane-container-model-spec.coffee index 5052b2830..7897387b4 100644 --- a/spec/pane-container-model-spec.coffee +++ b/spec/pane-container-model-spec.coffee @@ -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() diff --git a/src/pane-container-model.coffee b/src/pane-container-model.coffee index ebbf250db..70834cc7e 100644 --- a/src/pane-container-model.coffee +++ b/src/pane-container-model.coffee @@ -51,6 +51,7 @@ class PaneContainerModel extends Model panes[nextIndex].focus() true else + @emit 'surrendered-focus' false focusPreviousPane: -> diff --git a/src/pane-container.coffee b/src/pane-container.coffee index bc5f0e2f4..8f2d71750 100644 --- a/src/pane-container.coffee +++ b/src/pane-container.coffee @@ -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)