diff --git a/spec/text-buffer-io-spec.js b/spec/text-buffer-io-spec.js index 3f2cf8a9a..62593aa17 100644 --- a/spec/text-buffer-io-spec.js +++ b/spec/text-buffer-io-spec.js @@ -408,6 +408,13 @@ describe('TextBuffer IO', () => { expect(buffer.isInConflict()).toBe(true) await buffer.save() expect(buffer.isInConflict()).toBe(false) + // Ensure we don't get flipped into conflicted status after the + // `onDidChange` handler comes through… + await wait(1000) + expect(buffer.isInConflict()).toBe(false) + buffer.setText('q') + // …and the buffer is modified again. + expect(buffer.isInConflict()).toBe(false) done() }) }) diff --git a/src/text-buffer.js b/src/text-buffer.js index 19a1bcbb2..4537560cf 100644 --- a/src/text-buffer.js +++ b/src/text-buffer.js @@ -2273,9 +2273,20 @@ class TextBuffer { if (this.isModified()) { const source = this.file.getPath() if (!(await this.buffer.baseTextMatchesFile(source, this.getEncoding()))) { + // Emit `did-conflict` and take no other action. We will keep the + // current buffer contents so that the user's changes are not lost. this.emitter.emit('did-conflict') + } else { + // Despite being modified, we're once again in alignment with what + // is on disk. This file is not in conflict. + this.fileHasChangedSinceLastLoad = false } } else { + // This buffer was previously in sync with what was on disk, so we + // can update its contents to match the new contents on disk. By + // definition, this means there is no conflict, so we'll reset the + // appropriate flag. + this.fileHasChangedSinceLastLoad = false return this.load({internal: true}) } }, this.fileChangeDelay)))