Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add setting for ignoring files #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/autosave.coffee
Expand Up @@ -28,10 +28,13 @@ module.exports =
@subscriptions.dispose()

autosavePaneItem: (paneItem) ->
ignorable = (file) -> new RegExp(file).test(paneItem.getPath())
filesToIgnore = atom.config.get('autosave.ignoreFiles')?.split(',') || []
return unless atom.config.get('autosave.enabled')
return unless paneItem?.getURI?()?
return unless paneItem?.isModified?()
return unless paneItem?.getPath?()? and fs.isFileSync(paneItem.getPath())
return if filesToIgnore.some(ignorable)

pane = atom.workspace.paneForItem(paneItem)
if pane?
Expand Down
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -18,6 +18,12 @@
"enabled": {
"type": "boolean",
"default": false
},
"ignoreFiles": {
"title": "Files to ignore",
"type": "string",
"description": "Files which should not be autosaved",
"default": null
}
}
}
14 changes: 14 additions & 0 deletions spec/autosave-spec.coffee
Expand Up @@ -140,6 +140,20 @@ describe "Autosave", ->
atom.workspace.getActivePane().destroyItem(pathLessItem)
expect(pathLessItem.save).not.toHaveBeenCalled()

describe "when the item is ignored in the settings", ->
it "does not save the item", ->
waitsForPromise ->
atom.workspace.open('sample.js')

runs ->
atom.config.set('autosave.enabled', true)
atom.config.set('autosave.ignoreFiles', 'sample.js')
file = atom.workspace.getActiveTextEditor()
file.insertText('text!')

window.dispatchEvent(new FocusEvent('blur'))
expect(file.save).not.toHaveBeenCalled()

describe "when the window is blurred", ->
it "saves all items", ->
atom.config.set('autosave.enabled', true)
Expand Down