Make Pane maintain a currentView pointer based on its current item

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-02-21 14:47:26 -07:00
committed by probablycorey
parent d310fb366f
commit ad62f896bc
2 changed files with 7 additions and 5 deletions

View File

@@ -41,7 +41,8 @@ describe "Pane", ->
describe "when no view has yet been appended for that item", ->
it "appends and shows a view to display the item based on its `.getViewClass` method", ->
pane.showItem(editSession1)
editor = pane.itemViews.find('.editor').view()
editor = pane.currentView
expect(editor.css('display')).toBe ''
expect(editor.activeEditSession).toBe editSession1
describe "when a valid view has already been appended for another item", ->
@@ -49,7 +50,7 @@ describe "Pane", ->
pane.showItem(editSession1)
pane.showItem(editSession2)
expect(pane.itemViews.find('.editor').length).toBe 1
editor = pane.itemViews.find('.editor').view()
editor = pane.currentView
expect(editor.css('display')).toBe ''
expect(editor.activeEditSession).toBe editSession2
@@ -58,6 +59,7 @@ describe "Pane", ->
expect(pane.itemViews.find('#view-2')).not.toExist()
pane.showItem(view2)
expect(pane.itemViews.find('#view-2')).toExist()
expect(pane.currentView).toBe view2
describe ".removeItem(item)", ->
it "removes the item from the items list and shows the next item if it was showing", ->

View File

@@ -58,10 +58,10 @@ class Pane extends View
@addItem(item)
@itemViews.children().hide()
view = @viewForItem(item)
unless view.parent().is(@itemViews)
@itemViews.append(view)
@itemViews.append(view) unless view.parent().is(@itemViews)
@currentItem = item
view.show()
@currentView = view
@currentView.show()
addItem: (item) ->
return if _.include(@items, item)