From 4a7b43f609611134a270d01bc1b474a7441fbb09 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 14 Jan 2014 11:15:14 -0700 Subject: [PATCH] Write focusNext/PreviousPane in terms of activateNext/PreviousPane "Activate" is the model level equivalent of focus. --- spec/pane-container-view-spec.coffee | 2 +- src/pane-container-view.coffee | 19 ++----------------- src/pane-container.coffee | 14 +++++++++++++- src/workspace-view.coffee | 4 ++-- src/workspace.coffee | 3 ++- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/spec/pane-container-view-spec.coffee b/spec/pane-container-view-spec.coffee index fa0bcb83d..4f9d8ea2c 100644 --- a/spec/pane-container-view-spec.coffee +++ b/spec/pane-container-view-spec.coffee @@ -42,7 +42,7 @@ describe "PaneContainerView", -> describe ".focusPreviousPane()", -> it "focuses the pane preceding the focused pane or the last pane if no pane has focus", -> container.attachToDom() - $(document.body).focus() # clear focus + container.getPanes()[0].focus() # activate first pane container.focusPreviousPane() expect(pane3.activeItem).toMatchSelector ':focus' diff --git a/src/pane-container-view.coffee b/src/pane-container-view.coffee index 5ea822a8f..81ffffe10 100644 --- a/src/pane-container-view.coffee +++ b/src/pane-container-view.coffee @@ -106,22 +106,7 @@ class PaneContainerView extends View @viewForModel(@model.paneForUri(uri)) focusNextPane: -> - panes = @getPanes() - if panes.length > 1 - currentIndex = panes.indexOf(@getFocusedPane()) - nextIndex = (currentIndex + 1) % panes.length - panes[nextIndex].focus() - true - else - false + @model.activateNextPane() focusPreviousPane: -> - panes = @getPanes() - if panes.length > 1 - currentIndex = panes.indexOf(@getFocusedPane()) - previousIndex = currentIndex - 1 - previousIndex = panes.length - 1 if previousIndex < 0 - panes[previousIndex].focus() - true - else - false + @model.activatePreviousPane() diff --git a/src/pane-container.coffee b/src/pane-container.coffee index d4273db88..9f0dfc7ea 100644 --- a/src/pane-container.coffee +++ b/src/pane-container.coffee @@ -49,8 +49,20 @@ class PaneContainer extends Model currentIndex = panes.indexOf(@activePane) nextIndex = (currentIndex + 1) % panes.length panes[nextIndex].activate() + true else - @activePane = null + false + + activatePreviousPane: -> + panes = @getPanes() + if panes.length > 1 + currentIndex = panes.indexOf(@activePane) + previousIndex = currentIndex - 1 + previousIndex = panes.length - 1 if previousIndex < 0 + panes[previousIndex].activate() + true + else + false onRootChanged: (root) => @unsubscribe(@previousRoot) if @previousRoot? diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index 7eb9d37d8..c60c831f8 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -218,10 +218,10 @@ class WorkspaceView extends View @panes.getActiveView() # Public: Focuses the previous pane by id. - focusPreviousPane: -> @panes.focusPreviousPane() + focusPreviousPane: -> @model.activatePreviousPane() # Public: Focuses the next pane by id. - focusNextPane: -> @panes.focusNextPane() + focusNextPane: -> @model.activateNextPane() # Public: # diff --git a/src/workspace.coffee b/src/workspace.coffee index 4444a55dc..38b993c98 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -12,7 +12,8 @@ class Workspace extends Model Serializable.includeInto(this) @delegatesProperty 'activePane', 'activePaneItem', toProperty: 'paneContainer' - @delegatesMethod 'getPanes', 'saveAll', toProperty: 'paneContainer' + @delegatesMethod 'getPanes', 'saveAll', 'activateNextPane', 'activatePreviousPane', + toProperty: 'paneContainer' @properties paneContainer: -> new PaneContainer