mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Move autosave from editor into panes
This commit is contained in:
committed by
probablycorey
parent
d97e91bdcb
commit
f2e5fcc902
@@ -157,10 +157,10 @@ its own namespace.
|
||||
- hideGitIgnoredFiles: Whether files in the .gitignore should be hidden
|
||||
- ignoredNames: File names to ignore across all of atom (not fully implemented)
|
||||
- themes: An array of theme names to load, in cascading order
|
||||
- autosave: Save a resource when its view loses focus
|
||||
- editor
|
||||
- autoIndent: Enable/disable basic auto-indent (defaults to true)
|
||||
- autoIndentOnPaste: Enable/disable auto-indented pasted text (defaults to false)
|
||||
- autosave: Save a file when an editor loses focus
|
||||
- nonWordCharacters: A string of non-word characters to define word boundaries
|
||||
- fontSize
|
||||
- fontFamily
|
||||
|
||||
@@ -7,7 +7,7 @@ read config settings. You can read a value from `config` with `config.get`:
|
||||
|
||||
```coffeescript
|
||||
# read a value with `config.get`
|
||||
@autosave() if config.get "editor.autosave"
|
||||
@autosave() if config.get "core.autosave"
|
||||
```
|
||||
|
||||
Or you can use `observeConfig` to track changes from a view object.
|
||||
@@ -47,7 +47,7 @@ the following way:
|
||||
|
||||
```coffeescript
|
||||
# basic key update
|
||||
config.set("editor.autosave", true)
|
||||
config.set("core.autosave", true)
|
||||
|
||||
# if you mutate a config key, you'll need to call `config.update` to inform
|
||||
# observers of the change
|
||||
|
||||
@@ -575,6 +575,68 @@ describe "Pane", ->
|
||||
expect(container.children('.pane').length).toBe 1
|
||||
expect(pane1.outerWidth()).toBe container.width()
|
||||
|
||||
describe "autosave", ->
|
||||
[initialActiveItem, initialActiveItemPath] = []
|
||||
|
||||
beforeEach ->
|
||||
initialActiveItem = pane.activeItem
|
||||
initialActiveItemPath = null
|
||||
pane.activeItem.getPath = -> initialActiveItemPath
|
||||
pane.activeItem.save = jasmine.createSpy("activeItem.save")
|
||||
spyOn(pane, 'saveItem').andCallThrough()
|
||||
|
||||
describe "when the active view loses focus", ->
|
||||
it "saves the item if core.autosave is true and the item has a path", ->
|
||||
pane.activeView.trigger 'focusout'
|
||||
expect(pane.saveItem).not.toHaveBeenCalled()
|
||||
expect(pane.activeItem.save).not.toHaveBeenCalled()
|
||||
|
||||
config.set('core.autosave', true)
|
||||
pane.activeView.trigger 'focusout'
|
||||
expect(pane.saveItem).not.toHaveBeenCalled()
|
||||
expect(pane.activeItem.save).not.toHaveBeenCalled()
|
||||
|
||||
initialActiveItemPath = '/tmp/hi'
|
||||
pane.activeView.trigger 'focusout'
|
||||
expect(pane.activeItem.save).toHaveBeenCalled()
|
||||
|
||||
describe "when an item becomes inactive", ->
|
||||
it "saves the item if core.autosave is true and the item has a path", ->
|
||||
expect(view2).not.toBe pane.activeItem
|
||||
expect(pane.saveItem).not.toHaveBeenCalled()
|
||||
expect(initialActiveItem.save).not.toHaveBeenCalled()
|
||||
pane.showItem(view2)
|
||||
|
||||
pane.showItem(initialActiveItem)
|
||||
config.set('core.autosave', true)
|
||||
pane.showItem(view2)
|
||||
expect(pane.saveItem).not.toHaveBeenCalled()
|
||||
expect(initialActiveItem.save).not.toHaveBeenCalled()
|
||||
|
||||
pane.showItem(initialActiveItem)
|
||||
initialActiveItemPath = '/tmp/hi'
|
||||
pane.showItem(view2)
|
||||
expect(initialActiveItem.save).toHaveBeenCalled()
|
||||
|
||||
describe "when an item is destroyed", ->
|
||||
it "saves the item if core.autosave is true and the item has a path", ->
|
||||
# doesn't have to be the active item
|
||||
expect(view2).not.toBe pane.activeItem
|
||||
pane.showItem(view2)
|
||||
|
||||
pane.destroyItem(editSession1)
|
||||
expect(pane.saveItem).not.toHaveBeenCalled()
|
||||
|
||||
config.set("core.autosave", true)
|
||||
view2.getPath = -> undefined
|
||||
view2.save = ->
|
||||
pane.destroyItem(view2)
|
||||
expect(pane.saveItem).not.toHaveBeenCalled()
|
||||
|
||||
initialActiveItemPath = '/tmp/hi'
|
||||
pane.destroyItem(initialActiveItem)
|
||||
expect(initialActiveItem.save).toHaveBeenCalled()
|
||||
|
||||
describe ".itemForPath(path)", ->
|
||||
it "returns the item for which a call to .getPath() returns the given path", ->
|
||||
expect(pane.itemForPath(editSession1.getPath())).toBe editSession1
|
||||
|
||||
@@ -16,7 +16,6 @@ class Editor extends View
|
||||
fontSize: 20
|
||||
showInvisibles: false
|
||||
showIndentGuide: false
|
||||
autosave: false
|
||||
autoIndent: true
|
||||
autoIndentOnPaste: false
|
||||
nonWordCharacters: "./\\()\"':,.;<>~!@#$%^&*|+=[]{}`~?-"
|
||||
@@ -348,7 +347,6 @@ class Editor extends View
|
||||
|
||||
@hiddenInput.on 'focusout', =>
|
||||
@isFocused = false
|
||||
# @autosave() if config.get "editor.autosave"
|
||||
@removeClass 'is-focused'
|
||||
|
||||
@underlayer.on 'click', (e) =>
|
||||
@@ -456,7 +454,6 @@ class Editor extends View
|
||||
return if editSession is @activeEditSession
|
||||
|
||||
if @activeEditSession
|
||||
# @autosave() if config.get "editor.autosave"
|
||||
@saveScrollPositionForActiveEditSession()
|
||||
@activeEditSession.off(".editor")
|
||||
|
||||
@@ -609,9 +606,6 @@ class Editor extends View
|
||||
@removeClass 'soft-wrap'
|
||||
$(window).off 'resize', @_setSoftWrapColumn
|
||||
|
||||
# autosave: ->
|
||||
# @save() if @getPath()?
|
||||
|
||||
setFontSize: (fontSize) ->
|
||||
headTag = $("head")
|
||||
styleTag = headTag.find("style.font-size")
|
||||
|
||||
@@ -45,6 +45,7 @@ class Pane extends View
|
||||
@command 'pane:close-other-items', => @destroyInactiveItems()
|
||||
@on 'focus', => @activeView.focus(); false
|
||||
@on 'focusin', => @makeActive()
|
||||
@on 'focusout', => @autosaveActiveItem()
|
||||
|
||||
afterAttach: ->
|
||||
return if @attached
|
||||
@@ -92,6 +93,9 @@ class Pane extends View
|
||||
|
||||
showItem: (item) ->
|
||||
return if !item? or item is @activeItem
|
||||
|
||||
@autosaveActiveItem() if @activeItem
|
||||
|
||||
isFocused = @is(':has(:focus)')
|
||||
@addItem(item)
|
||||
view = @viewForItem(item)
|
||||
@@ -119,6 +123,8 @@ class Pane extends View
|
||||
@removeItem(item)
|
||||
item.destroy?()
|
||||
|
||||
@autosaveItem(item)
|
||||
|
||||
if item.isModified?()
|
||||
@promptToSaveItem(item, reallyDestroyItem)
|
||||
else
|
||||
@@ -163,6 +169,12 @@ class Pane extends View
|
||||
saveItems: =>
|
||||
@saveItem(item) for item in @getItems()
|
||||
|
||||
autosaveActiveItem: ->
|
||||
@autosaveItem(@activeItem)
|
||||
|
||||
autosaveItem: (item) ->
|
||||
@saveItem(item) if config.get('core.autosave') and item.getPath?()
|
||||
|
||||
removeItem: (item) ->
|
||||
index = @items.indexOf(item)
|
||||
return if index == -1
|
||||
|
||||
Reference in New Issue
Block a user