Merge pull request #12922 from stereobooster/10474-prompt-to-save-unsaved-buffer

Fix for #10474
This commit is contained in:
Ian Olsen
2016-10-26 16:35:43 -07:00
committed by GitHub
3 changed files with 19 additions and 4 deletions

View File

@@ -5173,12 +5173,16 @@ describe "TextEditor", ->
expect(editor.getSelectedBufferRange()).toEqual [[13, 0], [14, 2]]
describe ".shouldPromptToSave()", ->
it "returns false when an edit session's buffer is in use by more than one session", ->
it "returns true when buffer changed", ->
jasmine.unspy(editor, 'shouldPromptToSave')
expect(editor.shouldPromptToSave()).toBeFalsy()
buffer.setText('changed')
expect(editor.shouldPromptToSave()).toBeTruthy()
it "returns false when an edit session's buffer is in use by more than one session", ->
jasmine.unspy(editor, 'shouldPromptToSave')
buffer.setText('changed')
editor2 = null
waitsForPromise ->
atom.workspace.getActivePane().splitRight()
@@ -5189,6 +5193,16 @@ describe "TextEditor", ->
editor2.destroy()
expect(editor.shouldPromptToSave()).toBeTruthy()
it "returns false when close of a window requested and edit session opened inside project", ->
jasmine.unspy(editor, 'shouldPromptToSave')
buffer.setText('changed')
expect(editor.shouldPromptToSave(windowCloseRequested: true, projectHasPaths: true)).toBeFalsy()
it "returns true when close of a window requested and edit session opened without project", ->
jasmine.unspy(editor, 'shouldPromptToSave')
buffer.setText('changed')
expect(editor.shouldPromptToSave(windowCloseRequested: true, projectHasPaths: false)).toBeTruthy()
describe "when the editor contains surrogate pair characters", ->
it "correctly backspaces over them", ->
editor.setText('\uD835\uDF97\uD835\uDF97\uD835\uDF97')

View File

@@ -892,8 +892,8 @@ class TextEditor extends Model
# Determine whether the user should be prompted to save before closing
# this editor.
shouldPromptToSave: ({windowCloseRequested}={}) ->
if windowCloseRequested
shouldPromptToSave: ({windowCloseRequested, projectHasPaths}={}) ->
if windowCloseRequested and projectHasPaths
false
else
@isModified() and not @buffer.hasMultipleEditors()

View File

@@ -148,7 +148,8 @@ class WindowEventHandler
@document.body.classList.remove("fullscreen")
handleWindowBeforeunload: (event) =>
confirmed = @atomEnvironment.workspace?.confirmClose(windowCloseRequested: true)
projectHasPaths = @atomEnvironment.project.getPaths().length > 0
confirmed = @atomEnvironment.workspace?.confirmClose(windowCloseRequested: true, projectHasPaths: projectHasPaths)
if confirmed and not @reloadRequested and not @atomEnvironment.inSpecMode() and @atomEnvironment.getCurrentWindow().isWebViewFocused()
@atomEnvironment.hide()
@reloadRequested = false