delete the editor session when closing a tab

This commit is contained in:
Chris Wanstrath 2011-09-08 00:41:41 -07:00
parent c3dc1cc3eb
commit 7ea2efaf06
2 changed files with 9 additions and 5 deletions

View File

@ -26,7 +26,7 @@ class Tabs extends Pane
tab = this
# click tab
$(document).delegate '#tabs ul a', 'click', ->
$(document).delegate '#tabs ul li', 'click', ->
tab.switchToTab this
false
@ -38,7 +38,7 @@ class Tabs extends Pane
name = _.last path.split '/'
$('#tabs ul .active').removeClass()
$('#tabs ul li:last').after """
<li><a data-path='#{path}' href='#'>#{name}</a></li>
<li data-path='#{path}'><a href='#'>#{name}</a></li>
"""
$('#tabs ul li:last').addClass 'active'
@ -47,10 +47,10 @@ class Tabs extends Pane
nextTab = activeTab.next()
nextTab = activeTab.prev() if nextTab.length == 0
console.log(nextTab)
if nextTab.length != 0
@editor.deleteSession activeTab.data 'path'
activeTab.remove()
@switchToTab nextTab.children("a")
@switchToTab nextTab
hideTabs: ->
$('#tabs').parents('.pane').remove()
@ -64,7 +64,7 @@ class Tabs extends Pane
switchToTab: (tab) ->
$('#tabs ul .active').removeClass()
$(tab).parents('li').addClass 'active'
$(tab).addClass 'active'
@editor.switchToSession $(tab).data 'path'
toggle: ->

View File

@ -102,6 +102,10 @@ class Editor extends Pane
@filename = path
@ace.setSession @sessions[path]
deleteSession: (path) ->
@filename = null if path is @filename
delete @sessions[path]
newSession: (code) ->
doc = new EditSession code or ''
doc.setUndoManager new UndoManager