mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ class Buffer
|
||||
@destroy() if @refcount <= 0
|
||||
this
|
||||
|
||||
hasEditors: -> @refcount > 1
|
||||
|
||||
subscribeToFile: ->
|
||||
@file.on "contents-changed", =>
|
||||
if @isModified()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user