Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
11 changes: 10 additions & 1 deletion spec/text-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Expand Down
22 changes: 12 additions & 10 deletions src/text-buffer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: ->
Expand Down