When focused, RootView retains focus itself if it has no focusable children

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-09-25 15:11:07 -06:00
parent 5f253d78e9
commit 685cbc3575
2 changed files with 31 additions and 18 deletions

View File

@@ -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] = []

View File

@@ -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