From a9c74762cc5421e87f84ca3260485c718be80fee Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Tue, 2 Apr 2013 14:52:39 -0700 Subject: [PATCH] Add `focusPreviousPane` to pane container --- spec/app/pane-container-spec.coffee | 12 ++++++++++++ src/app/pane-container.coffee | 11 +++++++++++ src/app/root-view.coffee | 2 ++ 3 files changed, 25 insertions(+) diff --git a/spec/app/pane-container-spec.coffee b/spec/app/pane-container-spec.coffee index 708beb081..3289ab5f5 100644 --- a/spec/app/pane-container-spec.coffee +++ b/spec/app/pane-container-spec.coffee @@ -39,6 +39,18 @@ describe "PaneContainer", -> container.focusNextPane() expect(pane1.activeItem).toMatchSelector ':focus' + describe ".focusPreviousPane()", -> + it "focuses the pane preceding the focused pane or the last pane if no pane has focus", -> + container.attachToDom() + container.focusPreviousPane() + expect(pane3.activeItem).toMatchSelector ':focus' + container.focusPreviousPane() + expect(pane2.activeItem).toMatchSelector ':focus' + container.focusPreviousPane() + expect(pane1.activeItem).toMatchSelector ':focus' + container.focusPreviousPane() + expect(pane3.activeItem).toMatchSelector ':focus' + describe ".getActivePane()", -> it "returns the most-recently focused pane", -> focusStealer = $$ -> @div tabindex: -1, "focus stealer" diff --git a/src/app/pane-container.coffee b/src/app/pane-container.coffee index 2118af2b0..6f59af0f4 100644 --- a/src/app/pane-container.coffee +++ b/src/app/pane-container.coffee @@ -32,6 +32,17 @@ class PaneContainer extends View else false + 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 + makeNextPaneActive: -> panes = @getPanes() currentIndex = panes.indexOf(@getActivePane()) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 2c299c92c..fc1fdb4e1 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -53,6 +53,7 @@ class RootView extends View config.set("editor.fontSize", fontSize - 1) if fontSize > 1 @command 'window:focus-next-pane', => @focusNextPane() + @command 'window:focus-previous-pane', => @focusPreviousPane() @command 'window:save-all', => @saveAll() @command 'window:toggle-invisibles', => config.set("editor.showInvisibles", !config.get("editor.showInvisibles")) @@ -143,6 +144,7 @@ class RootView extends View getActiveView: -> @panes.getActiveView() + focusPreviousPane: -> @panes.focusPreviousPane() focusNextPane: -> @panes.focusNextPane() getFocusedPane: -> @panes.getFocusedPane()