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

Commit 6a6a8d3

Browse files
author
Max Brunsfeld
authored
Merge pull request #253 from atom/mb-handle-destruction-during-save
On destroy, don't clear native buffer until all saves are done
2 parents 80ecaab + e64d7db commit 6a6a8d3

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "text-buffer",
3-
"version": "13.1.14",
3+
"version": "13.1.15-0",
44
"description": "A container for large mutable strings with annotated regions",
55
"main": "./lib/text-buffer",
66
"scripts": {

spec/text-buffer-io-spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ describe('TextBuffer IO', () => {
238238
})
239239
})
240240

241+
describe('when the buffer is destroyed before the save completes', () => {
242+
it('saves the current contents of the buffer to the path', (done) => {
243+
buffer.setText('hello\n')
244+
buffer.save().then(() => {
245+
expect(buffer.getText()).toBe('')
246+
expect(fs.readFileSync(filePath, 'utf8')).toBe('hello\n')
247+
done()
248+
})
249+
buffer.destroy()
250+
})
251+
})
252+
241253
describe('when a conflict is created', () => {
242254
beforeEach((done) => {
243255
buffer.setText('a')

src/text-buffer.coffee

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,14 @@ class TextBuffer
17241724
@fileSubscriptions?.dispose()
17251725
for id, markerLayer of @markerLayers
17261726
markerLayer.destroy()
1727-
@buffer.reset('')
1727+
if @outstandingSaveCount is 0
1728+
@buffer.reset('')
1729+
else
1730+
subscription = @onDidSave =>
1731+
if @outstandingSaveCount is 0
1732+
@buffer.reset('')
1733+
subscription.dispose()
1734+
17281735
@cachedText = null
17291736
@history.clear()
17301737

0 commit comments

Comments
 (0)