diff --git a/package.json b/package.json index 3326a79517..bddceb2fdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "text-buffer", - "version": "6.7.0", + "version": "6.7.1-1", "description": "A container for large mutable strings with annotated regions", "main": "./lib/text-buffer", "scripts": { diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 8d59471778..14e7346fa4 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -837,6 +837,10 @@ describe "TextBuffer", -> marker3B = bufferB.markRange([[0, 1], [2, 3]]) expect(marker3B.id).toBe marker3A.id + # Doesn't try to reload the buffer since it has no file. + waits(50) + runs -> expect(bufferB.getText()).toBe "hello\nworld\r\nhow are you doing?" + it "doesn't serialize markers with the 'persistent' option set to false", -> bufferA = new TextBuffer(text: "hello\nworld\r\nhow are you doing?") marker1A = bufferA.markRange([[0, 1], [1, 2]], persistent: false, foo: 1) @@ -864,7 +868,6 @@ describe "TextBuffer", -> it "loads the current contents of the file at the serialized path", -> expect(buffer.isModified()).toBeFalsy() buffer2 = buffer.testSerialization() - buffer2.load() waitsFor -> buffer2.loaded @@ -894,6 +897,7 @@ describe "TextBuffer", -> it "restores the previous unsaved state of the buffer", -> previousText = buffer.getText() buffer.setText("abc") + buffer.append("d") buffer2 = buffer.testSerialization() buffer2.load() @@ -905,6 +909,11 @@ describe "TextBuffer", -> expect(buffer2.getPath()).toBe(buffer.getPath()) expect(buffer2.getText()).toBe(buffer.getText()) expect(buffer2.isModified()).toBeTruthy() + + buffer.undo() + buffer2.undo() + expect(buffer2.getText()).toBe(buffer.getText()) + buffer2.setText(previousText) expect(buffer2.isModified()).toBeFalsy() diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 896b9f4a0e..b90c7dccd2 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -116,11 +116,11 @@ class TextBuffer deserializeParams: (params) -> params.markerStore = MarkerStore.deserialize(this, params.markerStore) params.history = History.deserialize(this, params.history) - params.load = true params # Called by {Serializable} mixin during serialization. serializeParams: -> + load: @loaded text: @getText() markerStore: @markerStore.serialize() history: @history.serialize() @@ -554,7 +554,7 @@ class TextBuffer # given text. # # * `text` A {String} containing the new buffer contents. - setTextViaDiff: (text, skipUndo) -> + setTextViaDiff: (text) -> currentText = @getText() return if currentText == text @@ -577,7 +577,6 @@ class TextBuffer lineDiff = diff.diffLines(currentText, text) changeOptions = normalizeLineEndings: false - changeOptions.undo = 'skip' if skipUndo for change in lineDiff lineCount = change.value.match(newlineRegex)?.length ? 0 @@ -1251,10 +1250,14 @@ class TextBuffer # Public: Reload the buffer's contents from disk. # # Sets the buffer's content to the cached disk contents - reload: (skipUndo) -> + reload: (clearHistory=false) -> @emitter.emit 'will-reload' @emit 'will-reload' if Grim.includeDeprecatedAPIs - @setTextViaDiff(@cachedDiskContents, skipUndo) + if clearHistory + @clearUndoStack() + @setTextInRange(@getRange(), @cachedDiskContents, normalizeLineEndings: false, undo: 'skip') + else + @setTextViaDiff(@cachedDiskContents) @emitModifiedStatusChanged(false) @emitter.emit 'did-reload' @emit 'reloaded' if Grim.includeDeprecatedAPIs @@ -1322,17 +1325,16 @@ class TextBuffer @updateCachedDiskContentsSync() @finishLoading() - load: (skipUndo) -> - @updateCachedDiskContents().then => @finishLoading(skipUndo) + load: (clearHistory=false) -> + @updateCachedDiskContents().then => @finishLoading(clearHistory) - finishLoading: (skipUndo) -> + finishLoading: (clearHistory) -> if @isAlive() @loaded = true if @useSerializedText and @digestWhenLastPersisted is @file?.getDigestSync() @emitModifiedStatusChanged(true) else - @reload(skipUndo) - @clearUndoStack() + @reload(clearHistory) this destroy: ->