From 685cbc35757e488c8d4018bc0644e18392d0afd3 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Tue, 25 Sep 2012 15:11:07 -0600 Subject: [PATCH] When focused, RootView retains focus itself if it has no focusable children --- spec/app/root-view-spec.coffee | 46 +++++++++++++++++++++------------- src/app/root-view.coffee | 3 ++- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 904ce21c4..5a1b857c6 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -146,27 +146,39 @@ describe "RootView", -> expect(console.error).toHaveBeenCalled() describe "focus", -> - it "hands off focus to the active editor", -> - rootView.remove() - rootView = new RootView(require.resolve 'fixtures') - rootView.attachToDom() + describe "when there is an active editor", -> + it "hands off focus to the active editor", -> + rootView.remove() + rootView = new RootView(require.resolve 'fixtures') + rootView.attachToDom() - rootView.open() # create an editor - expect(rootView).not.toMatchSelector(':focus') - expect(rootView.getActiveEditor().isFocused).toBeTruthy() + rootView.open() # create an editor + expect(rootView).not.toMatchSelector(':focus') + expect(rootView.getActiveEditor().isFocused).toBeTruthy() - rootView.focus() - expect(rootView).not.toMatchSelector(':focus') - expect(rootView.getActiveEditor().isFocused).toBeTruthy() + rootView.focus() + expect(rootView).not.toMatchSelector(':focus') + expect(rootView.getActiveEditor().isFocused).toBeTruthy() - it "passes focus to element with a tabIndex of -1 if there is no active editor", -> - rootView.remove() - rootView = new RootView(require.resolve 'fixtures') - rootView.activateExtension require('tree-view') - rootView.attachToDom() + describe "when there is no active editor", -> + describe "when there is a visible focusable element (with a -1 tabindex)", -> + it "passes focus to that element", -> + rootView.remove() + rootView = new RootView(require.resolve 'fixtures') + rootView.activateExtension require('tree-view') + rootView.attachToDom() - expect(rootView).not.toMatchSelector(':focus') - expect(rootView.find('.tree-view')).toMatchSelector(':focus') + expect(rootView).not.toMatchSelector(':focus') + expect(rootView.find('.tree-view')).toMatchSelector(':focus') + + describe "when there are no visible focusable elements", -> + it "retains focus itself", -> + rootView.remove() + rootView = new RootView(require.resolve 'fixtures') + rootView.activateExtension require('tree-view') + rootView.find('.tree-view').hide() + rootView.attachToDom() + expect(rootView).toMatchSelector(':focus') describe "panes", -> [pane1, newPaneContent] = [] diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 7df198ac8..a3c0af3e9 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -62,7 +62,8 @@ class RootView extends View false else @setTitle(@project?.getPath()) - if focusableChild = this.find("[tabindex=-1]") + focusableChild = this.find("[tabindex=-1]:visible") + if focusableChild.length focusableChild.focus() false else