Tear down editors and unsubscribe from buffers on window unload to prevent exceptions when typing after reload

This commit is contained in:
Nathan Sobo
2012-04-18 11:01:30 -06:00
parent b5e2beab96
commit e89a2255cf
4 changed files with 47 additions and 31 deletions

View File

@@ -52,7 +52,7 @@ class RootView extends View
panesViewState: @serializePanes()
serializePanes: () ->
@panes.children().view().serialize()
@panes.children().view()?.serialize()
deserializePanes: (panesViewState) ->
@panes.append @deserializeView(panesViewState)
@@ -122,3 +122,7 @@ class RootView extends View
selected: (relativePath) => @open(relativePath)
@append @fileFinder
@fileFinder.editor.focus()
remove: ->
editor.remove() for editor in @editors()
super

View File

@@ -24,11 +24,14 @@ windowAdditions =
@attachRootView(path)
@loadUserConfiguration()
$(window).on 'close', => @close()
$(window).on 'beforeunload', => @saveRootViewState()
$(window).on 'beforeunload', =>
@shutdown()
false
$(window).focus()
atom.windowOpened this
shutdown: ->
@saveRootViewState()
@rootView.remove()
$(window).unbind('focus')
$(window).unbind('blur')
@@ -38,6 +41,7 @@ windowAdditions =
attachRootView: (pathToOpen) ->
rootViewState = atom.rootViewStates[$windowNumber]
@rootView = if rootViewState
console.log "RootView deserialize", rootViewState
RootView.deserialize(rootViewState)
else
new RootView {pathToOpen}