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