diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 75d3661dc..3c367eac5 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -1,6 +1,6 @@ PaneContainer = require '../src/pane-container' Pane = require '../src/pane' -{$, View} = require 'atom' +{fs, $, View} = require 'atom' path = require 'path' temp = require 'temp' @@ -347,14 +347,14 @@ describe "Pane", -> describe "when the current item has a saveAs method", -> it "opens a save dialog and saves the current item as the selected path", -> - spyOn(editor2, 'saveAs') - editor2.buffer.setPath(undefined) - pane.showItem(editor2) + newEditor = atom.project.openSync() + spyOn(newEditor, 'saveAs') + pane.showItem(newEditor) pane.trigger 'core:save' expect(atom.showSaveDialogSync).toHaveBeenCalled() - expect(editor2.saveAs).toHaveBeenCalledWith('/selected/path') + expect(newEditor.saveAs).toHaveBeenCalledWith('/selected/path') describe "when the current item has no saveAs method", -> it "does nothing", -> @@ -421,6 +421,17 @@ describe "Pane", -> view2.trigger 'title-changed' expect(activeItemTitleChangedHandler).toHaveBeenCalled() + describe "when an unmodifed buffer's path is deleted its pane item is removed", -> + it "removes the pane item", -> + filePath = temp.openSync('atom').path + editor = atom.project.openSync(filePath) + pane.showItem(editor) + expect(pane.items).toHaveLength(5) + + fs.removeSync(filePath) + waitsFor -> + pane.items.length == 4 + describe ".remove()", -> it "destroys all the pane's items", -> pane.remove() diff --git a/src/editor.coffee b/src/editor.coffee index 51cf56c98..f8fdef4d8 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -121,6 +121,7 @@ class Editor @subscribe @buffer, "contents-modified", => @emit "contents-modified" @subscribe @buffer, "contents-conflicted", => @emit "contents-conflicted" @subscribe @buffer, "modified-status-changed", => @emit "modified-status-changed" + @subscribe @buffer, "destroyed", => @destroy() @preserveCursorPositionOnBufferReload() # Private: diff --git a/src/pane.coffee b/src/pane.coffee index 765e914dc..112ee045d 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -189,6 +189,8 @@ class Pane extends View @items.splice(index, 0, item) @getContainer()?.itemAdded(item) @trigger 'pane:item-added', [item, index] + if item.on + @subscribe item, 'destroyed', => @destroyItem(item) item # Public: Remove the currently active item. @@ -198,11 +200,11 @@ class Pane extends View # Public: Remove the specified item. destroyItem: (item) -> + @unsubscribe(item) if item.off @trigger 'pane:before-item-destroyed', [item] - container = @getContainer() if @promptToSaveItem(item) - container.itemDestroyed(item) + @getContainer()?.itemDestroyed(item) @removeItem(item) item.destroy?() true diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 91125a888..a63406c99 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -116,8 +116,12 @@ class TextBuffer extends telepath.Model @reload() @file.on "removed", => - @wasModifiedBeforeRemove = @getText() != @cachedDiskContents - @updateCachedDiskContents() + modified = @getText() != @cachedDiskContents + @wasModifiedBeforeRemove = modified + if modified + @updateCachedDiskContents() + else + @destroy() @file.on "moved", => @emit "path-changed", this