mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add 'autosave' option, which saves when unfocusing or switching tabs
This commit is contained in:
@@ -1921,6 +1921,21 @@ describe "Editor", ->
|
||||
expect(editor.getCursor().getScreenPosition().row).toBe(0)
|
||||
expect(editor.getFirstVisibleScreenRow()).toBe(0)
|
||||
|
||||
describe "when autosave is enabled", ->
|
||||
it "autosaves the current buffer when the editor loses focus or switches edit sessions", ->
|
||||
rootView.attachToDom()
|
||||
editor2 = editor.splitRight()
|
||||
rootView.autosave = true
|
||||
spyOn(editor2.activeEditSession, 'save')
|
||||
|
||||
editor.focus()
|
||||
expect(editor2.activeEditSession.save).toHaveBeenCalled()
|
||||
|
||||
editSession = editor.activeEditSession
|
||||
spyOn(editSession, 'save')
|
||||
rootView.open('sample.txt')
|
||||
expect(editSession.save).toHaveBeenCalled()
|
||||
|
||||
describe ".checkoutHead()", ->
|
||||
[repo, path, originalPathText] = []
|
||||
|
||||
|
||||
@@ -135,6 +135,8 @@ class EditSession
|
||||
else
|
||||
_.multiplyString("\t", number)
|
||||
|
||||
save: -> @buffer.save()
|
||||
saveAs: (path) -> @buffer.saveAs(path)
|
||||
getFileExtension: -> @buffer.getExtension()
|
||||
getPath: -> @buffer.getPath()
|
||||
isBufferRowBlank: (bufferRow) -> @buffer.isRowBlank(bufferRow)
|
||||
|
||||
@@ -86,8 +86,7 @@ class Editor extends View
|
||||
throw new Error("Editor initialization requires an editSession")
|
||||
|
||||
serialize: ->
|
||||
@saveActiveEditSession()
|
||||
|
||||
@saveScrollPositionForActiveEditSession()
|
||||
viewClass: "Editor"
|
||||
editSessions: @editSessions.map (session) -> session.serialize()
|
||||
activeEditSessionIndex: @getActiveEditSessionIndex()
|
||||
@@ -309,6 +308,7 @@ class Editor extends View
|
||||
@hiddenInput.on 'focusout', =>
|
||||
@isFocused = false
|
||||
@removeClass 'focused'
|
||||
@autosave() if @rootView()?.autosave
|
||||
|
||||
@overlayer.on 'mousedown', (e) =>
|
||||
@overlayer.hide()
|
||||
@@ -433,7 +433,8 @@ class Editor extends View
|
||||
throw new Error("Edit session not found") unless @editSessions[index]
|
||||
|
||||
if @activeEditSession
|
||||
@saveActiveEditSession()
|
||||
@autosave() if @rootView()?.autosave
|
||||
@saveScrollPositionForActiveEditSession()
|
||||
@activeEditSession.off()
|
||||
|
||||
@activeEditSession = @editSessions[index]
|
||||
@@ -551,7 +552,7 @@ class Editor extends View
|
||||
@scrollTop(@activeEditSession.scrollTop ? 0)
|
||||
@scrollView.scrollLeft(@activeEditSession.scrollLeft ? 0)
|
||||
|
||||
saveActiveEditSession: ->
|
||||
saveScrollPositionForActiveEditSession: ->
|
||||
@activeEditSession.setScrollTop(@scrollTop())
|
||||
@activeEditSession.setScrollLeft(@scrollView.scrollLeft())
|
||||
|
||||
@@ -580,14 +581,17 @@ class Editor extends View
|
||||
|
||||
save: (onSuccess) ->
|
||||
if @getPath()
|
||||
@getBuffer().save()
|
||||
@activeEditSession.save()
|
||||
onSuccess?()
|
||||
else
|
||||
atom.showSaveDialog (path) =>
|
||||
if path
|
||||
@getBuffer().saveAs(path)
|
||||
@activeEditSession.saveAs(path)
|
||||
onSuccess?()
|
||||
|
||||
autosave: ->
|
||||
@save() if @getPath()?
|
||||
|
||||
subscribeToFontSize: ->
|
||||
return unless rootView = @rootView()
|
||||
@setFontSize(rootView.getFontSize())
|
||||
|
||||
Reference in New Issue
Block a user