Merge pull request #45 from jazzpi/fix-write

Fix :write behaviour
This commit is contained in:
Loic Nageleisen 2015-05-28 09:12:18 +02:00
commit bf0f492740

View file

@ -1,5 +1,6 @@
path = require 'path' path = require 'path'
CommandError = require './command-error' CommandError = require './command-error'
fs = require 'fs'
trySave = (func) -> trySave = (func) ->
deferred = Promise.defer() deferred = Promise.defer()
@ -30,6 +31,10 @@ trySave = (func) ->
deferred.promise deferred.promise
saveAs = (filePath) ->
editor = atom.workspace.getActiveTextEditor()
fs.writeFileSync(filePath, editor.getText())
getFullPath = (filePath) -> getFullPath = (filePath) ->
return filePath if path.isAbsolute(filePath) return filePath if path.isAbsolute(filePath)
return path.join(atom.project.getPath(), filePath) return path.join(atom.project.getPath(), filePath)
@ -119,7 +124,7 @@ class Ex
if filePath.length > 0 if filePath.length > 0
editorPath = editor.getPath() editorPath = editor.getPath()
fullPath = getFullPath(filePath) fullPath = getFullPath(filePath)
trySave(-> editor.saveAs(fullPath)) trySave(-> saveAs(fullPath))
.then -> .then ->
deferred.resolve() deferred.resolve()
editor.buffer.setPath(editorPath) editor.buffer.setPath(editorPath)
@ -129,7 +134,7 @@ class Ex
else else
if filePath.length > 0 if filePath.length > 0
fullPath = getFullPath(filePath) fullPath = getFullPath(filePath)
trySave(-> editor.saveAs(fullPath)) trySave(-> saveAs(fullPath))
.then deferred.resolve .then deferred.resolve
else else
fullPath = atom.showSaveDialogSync() fullPath = atom.showSaveDialogSync()