Preserve focus when switching between pane items

If the pane is currently focused, when showing a view associated with
a new item, focus that view.
This commit is contained in:
Corey Johnson & Nathan Sobo
2013-02-27 18:17:52 -07:00
committed by probablycorey
parent 80859b0a9f
commit 52b649dca5
2 changed files with 11 additions and 0 deletions

View File

@@ -44,6 +44,15 @@ describe "Pane", ->
expect(itemChangedHandler.argsForCall[0][1]).toBe editSession1
itemChangedHandler.reset()
describe "if the pane's active view is focused before calling showItem", ->
it "focuses the new active view", ->
container.attachToDom()
pane.focus()
expect(pane.activeView).not.toBe view2
expect(pane.activeView).toMatchSelector ':focus'
pane.showItem(view2)
expect(view2).toMatchSelector ':focus'
describe "when the given item isn't yet in the items list on the pane", ->
view3 = null
beforeEach ->

View File

@@ -73,11 +73,13 @@ class Pane extends View
showItem: (item) ->
return if item is @activeItem
isFocused = @is(':has(:focus)')
@addItem(item)
view = @viewForItem(item)
@itemViews.children().not(view).hide()
@itemViews.append(view) unless view.parent().is(@itemViews)
view.show()
view.focus() if isFocused
@activeItem = item
@activeView = view
@trigger 'pane:active-item-changed', [item]