diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 67d2793149..a69fab3cbf 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -1330,13 +1330,10 @@ describe "TextBuffer", -> done() fs.removeSync(filePath) - it "retains its path and reports the buffer as not modified", -> - # FIXME: This doesn't pass on Linux - return if process.platform is 'linux' - - expect(bufferToDelete.getPath()).toBe filePath - expect(bufferToDelete.isModified()).toBeFalsy() - + it "unsets its path and reports the buffer as modified", -> + expect(bufferToDelete.getPath()).toBe undefined + expect(bufferToDelete.file).toBe null + expect(bufferToDelete.isModified()).toBeTruthy() describe "when the file is deleted", -> it "notifies all onDidDelete listeners ", (done) -> diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 762c99e964..d1153cb4c5 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -50,6 +50,9 @@ class TextBuffer # * `load` A {Boolean}, `true` to asynchronously load the buffer from disk # after initialization. # * `text` The initial {String} text of the buffer. + # * `shouldDestroyOnFileDelete` A {Function} that returns a {Boolean} + # indicating whether the buffer should be destroyed if its file is + # deleted. constructor: (params) -> text = params if typeof params is 'string' @@ -79,6 +82,8 @@ class TextBuffer @transactCallDepth = 0 @digestWhenLastPersisted = params?.digestWhenLastPersisted ? false + @shouldDestroyOnFileDelete = params?.shouldDestroyOnFileDelete ? -> false + @setPath(params.filePath) if params?.filePath @load() if params?.load @@ -1472,7 +1477,10 @@ class TextBuffer if modified @updateCachedDiskContents() else - @destroy() + if @shouldDestroyOnFileDelete() + @destroy() + else + @unsubscribeFromFile() @fileSubscriptions.add @file.onDidRename => @emitter.emit 'did-change-path', @getPath() @@ -1480,6 +1488,12 @@ class TextBuffer @fileSubscriptions.add @file.onWillThrowWatchError (errorObject) => @emitter.emit 'will-throw-watch-error', errorObject + unsubscribeFromFile: -> + @fileSubscriptions?.dispose() + @setPath(null) + @conflict = false + @cachedDiskContents = null + createMarkerSnapshot: -> snapshot = {} for markerLayerId, markerLayer of @markerLayers