Don't prompt to save on close if buffer is opened elsewhere

Only prompt to save when the buffer is dirty and the last
open session on it is being destroyed.
This commit is contained in:
Kevin Sawicki
2013-01-17 17:25:50 -08:00
parent 0ad71a6008
commit 62f1155706
4 changed files with 14 additions and 1 deletions

View File

@@ -199,6 +199,15 @@ describe "Editor", ->
expect(editor.remove).not.toHaveBeenCalled()
expect(atom.confirm).toHaveBeenCalled()
it "doesn't trigger an alert if the buffer is opened in multiple sessions", ->
spyOn(editor, 'remove').andCallThrough()
spyOn(atom, 'confirm')
editor.insertText("I AM CHANGED!")
editor.splitLeft()
editor.trigger "core:close"
expect(editor.remove).toHaveBeenCalled()
expect(atom.confirm).not.toHaveBeenCalled()
describe ".edit(editSession)", ->
otherEditSession = null

View File

@@ -54,6 +54,8 @@ class Buffer
@destroy() if @refcount <= 0
this
hasEditors: -> @refcount > 1
subscribeToFile: ->
@file.on "contents-changed", =>
if @isModified()

View File

@@ -142,6 +142,8 @@ class EditSession
lineLengthForBufferRow: (row) -> @buffer.lineLengthForRow(row)
scanInRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInRange: (args...) -> @buffer.backwardsScanInRange(args...)
isModified: -> @buffer.isModified()
hasEditors: -> @buffer.hasEditors()
screenPositionForBufferPosition: (bufferPosition, options) -> @displayBuffer.screenPositionForBufferPosition(bufferPosition, options)
bufferPositionForScreenPosition: (screenPosition, options) -> @displayBuffer.bufferPositionForScreenPosition(screenPosition, options)

View File

@@ -463,7 +463,7 @@ class Editor extends View
@remove() if @editSessions.length is 0
callback(index) if callback
if editSession.buffer.isModified()
if editSession.isModified() and not editSession.hasEditors()
@promptToSaveDirtySession(editSession, destroySession)
else
destroySession(editSession)