diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index aa9a881ae..d28ea4d07 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -625,3 +625,34 @@ describe "RootView", -> expect(rootView.getActiveEditor()).toBe editor1 expect(editor1.getPath()).toBe path expect(editSession).toBe rootView.getActiveEditor().activeEditSession + + describe "save-all", -> + it "saves all open editors", -> + rootView.remove() + file1 = '/tmp/atom-temp1.txt' + file2 = '/tmp/atom-temp2.txt' + fs.write(file1, "file1") + fs.write(file2, "file2") + rootView = new RootView(file1) + + editor1 = rootView.getActiveEditor() + buffer1 = editor1.activeEditSession.buffer + expect(buffer1.getText()).toBe("file1") + expect(buffer1.isModified()).toBe(false) + buffer1.setText('edited1') + expect(buffer1.isModified()).toBe(true) + + editor2 = editor1.splitRight() + editor2.edit(rootView.project.buildEditSessionForPath('atom-temp2.txt')) + buffer2 = editor2.activeEditSession.buffer + expect(buffer2.getText()).toBe("file2") + expect(buffer2.isModified()).toBe(false) + buffer2.setText('edited2') + expect(buffer2.isModified()).toBe(true) + + rootView.saveAll() + + expect(buffer1.isModified()).toBe(false) + expect(fs.read(buffer1.getPath())).toBe("edited1") + expect(buffer2.isModified()).toBe(false) + expect(fs.read(buffer2.getPath())).toBe("edited2") diff --git a/src/app/keymaps/atom.coffee b/src/app/keymaps/atom.coffee index 1949c4c0f..bfe0f2306 100644 --- a/src/app/keymaps/atom.coffee +++ b/src/app/keymaps/atom.coffee @@ -7,3 +7,4 @@ window.keymap.bindKeys '*' up: 'move-up' pagedown: 'page-down' pageup: 'page-up' + 'meta-S' : 'save-all' diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index a1a0cfba3..316f69fc3 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -64,6 +64,7 @@ class RootView extends View @on 'increase-font-size', => @setFontSize(@getFontSize() + 1) @on 'decrease-font-size', => @setFontSize(@getFontSize() - 1) @on 'focus-next-pane', => @focusNextPane() + @on 'save-all', => @saveAll() afterAttach: (onDom) -> @focus() if onDom @@ -217,3 +218,5 @@ class RootView extends View catch error console.error "Failed to load `#{atom.configFilePath}`", error.stack, error + saveAll: -> + editor.save() for editor in @getEditors()