From d13796074b3ebdcb804a565ac4c98eb5a2de34cc Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 25 Sep 2012 13:22:06 -0700 Subject: [PATCH] RootView passes focus to a child element with a tabindex of -1 (if one exists) --- spec/app/root-view-spec.coffee | 19 ++++++++++++++----- spec/extensions/tree-view-spec.coffee | 5 ++++- src/app/root-view.coffee | 5 +++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index bf1a1af3b..904ce21c4 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -16,7 +16,7 @@ describe "RootView", -> rootView.focus() afterEach -> - rootView.remove() + rootView.deactivate() describe "initialize(pathToOpen)", -> describe "when called with a pathToOpen", -> @@ -117,10 +117,11 @@ describe "RootView", -> expect(document.title).toBe editor2.getPath() describe "when called with no pathToOpen", -> - it "opens no buffer", -> + it "opens an empty buffer", -> rootView.remove() rootView = new RootView - expect(rootView.getEditors().length).toBe 0 + expect(rootView.getEditors().length).toBe 1 + expect(rootView.getEditors()[0].getText()).toEqual "" expect(document.title).toBe 'untitled' describe ".serialize()", -> @@ -145,11 +146,10 @@ describe "RootView", -> expect(console.error).toHaveBeenCalled() describe "focus", -> - it "can receive focus if there is no active editor, but otherwise hands off focus to the active editor", -> + it "hands off focus to the active editor", -> rootView.remove() rootView = new RootView(require.resolve 'fixtures') rootView.attachToDom() - expect(rootView).toMatchSelector(':focus') rootView.open() # create an editor expect(rootView).not.toMatchSelector(':focus') @@ -159,6 +159,15 @@ describe "RootView", -> 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() + + expect(rootView).not.toMatchSelector(':focus') + expect(rootView.find('.tree-view')).toMatchSelector(':focus') + describe "panes", -> [pane1, newPaneContent] = [] diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index c88220ba0..9dc278fb4 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -142,6 +142,7 @@ describe "TreeView", -> describe "when the tree view is not focused", -> it "shifts focus to the tree view", -> + rootView.open() # When we call focus below, we want an editor to become focused rootView.focus() rootView.trigger 'tree-view:toggle' expect(treeView).toBeVisible() @@ -184,12 +185,14 @@ describe "TreeView", -> describe "when tree-view:unfocus is triggered on the tree view", -> it "surrenders focus to the root view but remains open", -> + rootView.open() # When we trigger 'tree-view:unfocus' below, we want an editor to become focused rootView.attachToDom() treeView.focus() + expect(treeView).toMatchSelector(':focus') treeView.trigger 'tree-view:unfocus' expect(treeView).toBeVisible() expect(treeView).not.toMatchSelector(':focus') - expect(rootView).toMatchSelector(':focus') + expect(rootView.getActiveEditor().isFocused).toBeTruthy() describe "when a directory's disclosure arrow is clicked", -> it "expands / collapses the associated directory", -> diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 5bac4e5d5..7df198ac8 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -62,6 +62,11 @@ class RootView extends View false else @setTitle(@project?.getPath()) + if focusableChild = this.find("[tabindex=-1]") + focusableChild.focus() + false + else + true @on 'active-editor-path-change', (e, path) => @project.setPath(path) unless @project.getRootDirectory()