Skip to content

Commit 98bf595

Browse files
Merge pull request #11 from pulsar-edit/fix-conflict-after-modification-bug
Fix incorrect `isInConflict` logic
2 parents bf519a5 + ee7e425 commit 98bf595

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

spec/text-buffer-io-spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ describe('TextBuffer IO', () => {
408408
expect(buffer.isInConflict()).toBe(true)
409409
await buffer.save()
410410
expect(buffer.isInConflict()).toBe(false)
411+
// Ensure we don't get flipped into conflicted status after the
412+
// `onDidChange` handler comes through…
413+
await wait(1000)
414+
expect(buffer.isInConflict()).toBe(false)
415+
buffer.setText('q')
416+
// …and the buffer is modified again.
417+
expect(buffer.isInConflict()).toBe(false)
411418
done()
412419
})
413420
})

src/text-buffer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,9 +2273,20 @@ class TextBuffer {
22732273
if (this.isModified()) {
22742274
const source = this.file.getPath()
22752275
if (!(await this.buffer.baseTextMatchesFile(source, this.getEncoding()))) {
2276+
// Emit `did-conflict` and take no other action. We will keep the
2277+
// current buffer contents so that the user's changes are not lost.
22762278
this.emitter.emit('did-conflict')
2279+
} else {
2280+
// Despite being modified, we're once again in alignment with what
2281+
// is on disk. This file is not in conflict.
2282+
this.fileHasChangedSinceLastLoad = false
22772283
}
22782284
} else {
2285+
// This buffer was previously in sync with what was on disk, so we
2286+
// can update its contents to match the new contents on disk. By
2287+
// definition, this means there is no conflict, so we'll reset the
2288+
// appropriate flag.
2289+
this.fileHasChangedSinceLastLoad = false
22792290
return this.load({internal: true})
22802291
}
22812292
}, this.fileChangeDelay)))

0 commit comments

Comments
 (0)