mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Meta+s triggers save on Editor.
Still can't save buffers that don't have a url.
This commit is contained in:
committed by
Corey Johnson & Nathan Sobo
parent
79fbc0118c
commit
c75c3555bb
@@ -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)
|
||||
|
||||
@@ -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 = $("<div id='main'>")
|
||||
$("#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", ->
|
||||
|
||||
|
||||
13
spec/spec-helper.coffee
Normal file
13
spec/spec-helper.coffee
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 = $("<div class='editor'>")
|
||||
$('#main').append(editorElement)
|
||||
@aceEditor = ace.edit editorElement[0]
|
||||
@editorElement = $("<div class='editor'>")
|
||||
$('#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()
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@ windowAdditions =
|
||||
onerror: ->
|
||||
@showConsole true
|
||||
|
||||
handleKeyEvent: ->
|
||||
null
|
||||
|
||||
triggerEvent: ->
|
||||
null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user