When an EditSession is removed, remove its tab

This commit is contained in:
Nathan Sobo
2012-11-20 16:03:25 -07:00
parent 69ec6b5441
commit 0f2cb6fd96
2 changed files with 11 additions and 0 deletions

View File

@@ -52,3 +52,10 @@ fdescribe "Tabs", ->
rootView.open('two-hundred.txt')
expect(tabs.find('.tab').length).toBe 3
expect(tabs.find('.tab:eq(2) .file-name').text()).toBe 'two-hundred.txt'
describe "when an edit session is removed", ->
it "removes the tab for the removed edit session", ->
editor.setActiveEditSessionIndex(0)
editor.destroyActiveEditSession()
expect(tabs.find('.tab').length).toBe 1
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.txt'

View File

@@ -25,6 +25,7 @@ class Tabs extends View
@setActiveTab(@editor.getActiveEditSessionIndex())
@editor.on 'editor:active-edit-session-changed', (e, editSession, index) => @setActiveTab(index)
@editor.on 'editor:edit-session-added', (e, editSession) => @addTabForEditSession(editSession)
@editor.on 'editor:edit-session-removed', (e, editSession, index) => @removeTabAtIndex(index)
addTabForEditSession: (editSession) ->
@append $$ ->
@@ -34,3 +35,6 @@ class Tabs extends View
setActiveTab: (index) ->
@find(".tab.active").removeClass('active')
@find(".tab:eq(#{index})").addClass('active')
removeTabAtIndex: (index) ->
@find(".tab:eq(#{index})").remove()