From 8af8a6a4084d08fdd864d8cb04184c90dec174d0 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 3 Sep 2015 14:16:13 -0700 Subject: [PATCH 1/4] Don't clear undo stack on reload if buffer is up-to-date --- spec/text-buffer-spec.coffee | 10 ++++++++++ src/text-buffer.coffee | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 8d59471778..86daba8934 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) @@ -894,6 +898,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 +910,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..725e3c3078 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -116,7 +116,7 @@ class TextBuffer deserializeParams: (params) -> params.markerStore = MarkerStore.deserialize(this, params.markerStore) params.history = History.deserialize(this, params.history) - params.load = true + params.load = true if @loaded params # Called by {Serializable} mixin during serialization. @@ -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: -> From 684ec948157a9ac01c3f03e423c8871367694992 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 3 Sep 2015 14:19:58 -0700 Subject: [PATCH 2/4] 6.7.1-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3326a79517..b5e67c51f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "text-buffer", - "version": "6.7.0", + "version": "6.7.1-0", "description": "A container for large mutable strings with annotated regions", "main": "./lib/text-buffer", "scripts": { From 487ad7ff4ecbc64818f4bbad2239235fe0610da1 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 3 Sep 2015 14:53:27 -0700 Subject: [PATCH 3/4] Fix serialization of load parameter --- spec/text-buffer-spec.coffee | 1 - src/text-buffer.coffee | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 86daba8934..14e7346fa4 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -868,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 diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 725e3c3078..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 if @loaded params # Called by {Serializable} mixin during serialization. serializeParams: -> + load: @loaded text: @getText() markerStore: @markerStore.serialize() history: @history.serialize() From ab8312263257d267348c5189344182b3151719e8 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 3 Sep 2015 14:55:13 -0700 Subject: [PATCH 4/4] 6.7.1-1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5e67c51f4..bddceb2fdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "text-buffer", - "version": "6.7.1-0", + "version": "6.7.1-1", "description": "A container for large mutable strings with annotated regions", "main": "./lib/text-buffer", "scripts": {