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

Only autosave new items if isModified() returns true #84

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/autosave.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
if (!atom.config.get('autosave.enabled')) return
if (!paneItem) return
if (typeof paneItem.getURI !== 'function' || !paneItem.getURI()) return
if (!create && (typeof paneItem.isModified !== 'function' || !paneItem.isModified())) return
if (typeof paneItem.isModified !== 'function' || !paneItem.isModified()) return
if (typeof paneItem.getPath !== 'function' || !paneItem.getPath()) return
if (!shouldSave(paneItem)) return

Expand Down
19 changes: 11 additions & 8 deletions spec/autosave-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ describe('Autosave', () => {
})

describe('when the item is not modified', () => {
it('autosaves newly added items', async () => {
atom.config.set('autosave.enabled', true)
spyOn(atom.workspace.getActivePane(), 'saveItem').andCallFake(() => Promise.resolve())
const newItem = await atom.workspace.open('notyet.coffee')

expect(atom.workspace.getActivePane().saveItem).toHaveBeenCalledWith(newItem)
})

it('does not autosave the item', () => {
atom.config.set('autosave.enabled', true)
atom.workspace.getActivePane().splitRight({items: [otherItem1]})
Expand All @@ -46,6 +38,17 @@ describe('Autosave', () => {
describe('when the buffer is modified', () => {
beforeEach(() => initialActiveItem.setText('i am modified'))

it('autosaves newly added items', async () => {
const newItem = await atom.workspace.createItemForURI('notyet.js')
spyOn(newItem, 'isModified').andReturn(true)

atom.config.set('autosave.enabled', true)
spyOn(atom.workspace.getActivePane(), 'saveItem').andCallFake(() => Promise.resolve())
atom.workspace.getActivePane().addItem(newItem)

expect(atom.workspace.getActivePane().saveItem).toHaveBeenCalledWith(newItem)
})

describe('when a pane loses focus', () => {
it('saves the item if autosave is enabled and the item has a uri', () => {
document.body.focus()
Expand Down