diff --git a/spec/atom/app-spec.coffee b/spec/atom/app-spec.coffee
index 74bb7d306..805a58f05 100644
--- a/spec/atom/app-spec.coffee
+++ b/spec/atom/app-spec.coffee
@@ -20,7 +20,5 @@ describe "App", ->
expect(app.windows().length).toBe 1
newWindow = app.windows()[0]
- expect(newWindow.editor).toBeDefined()
- expect(newWindow.editor.buffer).toBeDefined()
expect(newWindow.editor.buffer.url).toEqual filePath
expect(newWindow.editor.buffer.getText()).toEqual fs.read(filePath)
diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee
index fd1808991..0d12eed52 100644
--- a/spec/atom/editor-spec.coffee
+++ b/spec/atom/editor-spec.coffee
@@ -1,17 +1,21 @@
Editor = require 'editor'
$ = require 'jquery'
ck = require 'coffeekup'
+fs = require 'fs'
describe "Editor", ->
- mainDiv = null; editor = null; filePath = null
+ mainDiv = null; editor = null
+ filePath = null; tempFilePath = null
beforeEach ->
filePath = require.resolve 'fixtures/sample.txt'
+ tempFilePath = '/tmp/temp.txt'
mainDiv = $("
")
$("#jasmine-content").append(mainDiv)
editor = new Editor filePath
afterEach ->
+ fs.remove tempFilePath
editor.destroy()
describe "constructor", ->
@@ -35,3 +39,32 @@ describe "Editor", ->
expect(editor.buffer.getText()).not.toMatch /^.ooo/
editor.aceEditor.getSession().insert {row: 0, column: 1}, 'ooo'
expect(editor.buffer.getText()).toMatch /^.ooo/
+
+
+ describe "on key down", ->
+ describe "meta+s", ->
+ tempEditor = null
+
+ beforeEach ->
+ tempEditor = new Editor tempFilePath
+
+ afterEach ->
+ tempEditor.destroy()
+
+ describe "when the current buffer has a url", ->
+ it "saves the current buffer to disk", ->
+ tempEditor.buffer.setText 'Edited buffer!'
+ expect(fs.exists(tempFilePath)).toBeFalsy()
+
+ $(document).trigger(keydown 'meta+s')
+
+ expect(fs.exists(tempFilePath)).toBeTruthy()
+ expect(fs.read(tempFilePath)).toBe 'Edited buffer!'
+
+ describe "when the current buffer has no url", ->
+ it "presents a save as dialog", ->
+
+ describe "when a url is chosen", ->
+
+ describe "when dialog is cancelled", ->
+
diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee
new file mode 100644
index 000000000..73f08d1f9
--- /dev/null
+++ b/spec/spec-helper.coffee
@@ -0,0 +1,13 @@
+$ = require 'jquery'
+_ = require 'underscore'
+
+window.app = new (require 'app')
+
+window.keydown = (pattern) ->
+ keys = pattern.split '+'
+ $.Event "keydown",
+ ctrlKey: 'ctrl' in keys
+ altKey: 'alt' in keys
+ shiftKey: 'shift' in keys
+ metaKey: 'meta' in keys
+ which: _.last(keys).toUpperCase().charCodeAt 0
diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee
index bdab22929..e9418eb54 100644
--- a/spec/spec-suite.coffee
+++ b/spec/spec-suite.coffee
@@ -1,5 +1,4 @@
fs = require 'fs'
-window.app = new (require 'app')
-
+require 'spec-helper'
require path for path in fs.listDirectoryTree(require.resolve '.') when /-spec\.coffee$/.test path
diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee
index ffb32fd93..508624666 100644
--- a/src/atom/editor.coffee
+++ b/src/atom/editor.coffee
@@ -7,21 +7,30 @@ module.exports =
class Editor
aceEditor: null
buffer: null
+ editorElement: null
constructor: (url) ->
@buffer = new Buffer(url)
@buildAceEditor()
+ $(document).keydown (event) =>
+ if String.fromCharCode(event.which) == 'S' and event.metaKey
+ @save()
+
destroy: ->
@aceEditor.destroy()
buildAceEditor: ->
- editorElement = $("
")
- $('#main').append(editorElement)
- @aceEditor = ace.edit editorElement[0]
+ @editorElement = $("
")
+ $('#main').append(@editorElement)
+ @aceEditor = ace.edit @editorElement[0]
@aceEditor.setSession(new EditSession(@buffer.aceDocument))
@aceEditor.setTheme(require "ace/theme/twilight")
getAceSession: ->
@aceEditor.getSession()
+
+ save: ->
+ @buffer.save()
+
diff --git a/src/atom/window.coffee b/src/atom/window.coffee
index c1109e1f4..e1d06b98a 100644
--- a/src/atom/window.coffee
+++ b/src/atom/window.coffee
@@ -24,9 +24,6 @@ windowAdditions =
onerror: ->
@showConsole true
- handleKeyEvent: ->
- null
-
triggerEvent: ->
null