Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix onDidChangeModified events after deserialization #102

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 11 additions & 4 deletions spec/text-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -900,17 +900,24 @@ describe "TextBuffer", ->
expect(buffer.isModified()).toBeFalsy()
buffer2 = buffer.testSerialization()

buffer2ModifiedEvents = []
buffer2.onDidChangeModified (value) -> buffer2ModifiedEvents.push(value)

waitsFor ->
buffer2.loaded

runs ->
expect(buffer2.isModified()).toBeFalsy()
expect(buffer2.getPath()).toBe(buffer.getPath())
expect(buffer2.getText()).toBe(buffer.getText())
expect(buffer2ModifiedEvents).toEqual [false]
expect(buffer2.getPath()).toBe(filePath)
expect(buffer2.getText()).toBe('words!')

buffer.undo()
buffer2.undo()
expect(buffer2.getText()).toBe(buffer.getText())
advanceClock(buffer.stoppedChangingDelay + 1)

expect(buffer2.getText()).toBe('words')
expect(buffer2ModifiedEvents).toEqual [false, true]

describe "when the serialized buffer had unsaved changes", ->
describe "when the disk contents were changed since serialization", ->
Expand Down Expand Up @@ -1722,7 +1729,7 @@ describe "TextBuffer", ->
saveBuffer.setText "hi"
expect(-> saveBuffer.save()).toThrow()

describe "reload()", ->
describe "::reload()", ->
it "reloads current text from disk and clears any conflicts", ->
filePath = require.resolve('./fixtures/sample.js')
fileContents = fs.readFileSync(filePath, 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion src/text-buffer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ class TextBuffer
if @isAlive()
@loaded = true
if @digestWhenLastPersisted is @file?.getDigestSync()
@emitModifiedStatusChanged(true)
@emitModifiedStatusChanged(@isModified())
else
@reload(true)
this
Expand Down