Don't prompt to save if buffer is opened elsewhere

This corrects a regression where closing an edit session that
is opened somewhere else should not prompt to save since it
won't be lost if closed immediately since it is still open in
another pane.
This commit is contained in:
Kevin Sawicki
2013-04-08 16:27:17 -07:00
parent 78cb747a39
commit 2f67312a80
4 changed files with 13 additions and 3 deletions

View File

@@ -2358,3 +2358,13 @@ describe "EditSession", ->
editSession.joinLine()
expect(editSession.lineForBufferRow(9)).toBe ' }; return sort(Array.apply(this, arguments)); };'
expect(editSession.getSelectedBufferRange()).toEqual [[9, 3], [9, 49]]
describe ".shouldPromptToSave()", ->
it "returns false when an edit session's buffer is in use by more than one session", ->
expect(editSession.shouldPromptToSave()).toBeFalsy()
buffer.setText('changed')
expect(editSession.shouldPromptToSave()).toBeTruthy()
editSession2 = project.buildEditSession('sample.js', autoIndent: false)
expect(editSession.shouldPromptToSave()).toBeFalsy()
editSession2.destroy()
expect(editSession.shouldPromptToSave()).toBeTruthy()

View File

@@ -168,7 +168,7 @@ class EditSession
scanInBufferRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInBufferRange: (args...) -> @buffer.backwardsScanInRange(args...)
isModified: -> @buffer.isModified()
hasEditors: -> @buffer.hasEditors()
shouldPromptToSave: -> @isModified() and not @buffer.hasMultipleEditors()
screenPositionForBufferPosition: (bufferPosition, options) -> @displayBuffer.screenPositionForBufferPosition(bufferPosition, options)
bufferPositionForScreenPosition: (screenPosition, options) -> @displayBuffer.bufferPositionForScreenPosition(screenPosition, options)

View File

@@ -148,7 +148,7 @@ class Pane extends View
@autosaveItem(item)
if item.isModified?()
if item.shouldPromptToSave?()
@promptToSaveItem(item, reallyDestroyItem)
else
reallyDestroyItem()

View File

@@ -70,7 +70,7 @@ class Buffer
path: @getPath()
text: @getText() if @isModified()
hasEditors: -> @refcount > 1
hasMultipleEditors: -> @refcount > 1
subscribeToFile: ->
@file.on "contents-changed", =>