From f28a155234e8c62c7ea8ea9721e125480040c331 Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Tue, 28 Jul 2015 11:53:31 -0500 Subject: [PATCH 1/2] :bug: Fix behavior when no filename is given to :write. --- lib/ex.coffee | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index c7f0d45..44ddced 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -37,16 +37,19 @@ saveAs = (filePath) -> fs.writeFileSync(filePath, editor.getText()) getFullPath = (filePath) -> - if filePath is '' - throw new Error + editor = atom.workspace.getActiveTextEditor() if path.isAbsolute(filePath) return filePath - else if atom.workspace.getActiveTextEditor().getPath()? - return path.join(path.dirname(atom.workspace.getActiveTextEditor().getPath()), filePath) - else if atom.project.getPaths()[0]? + else if editor.getPath()? + if filePath is '' + return editor.getPath() + else + return path.join(path.dirname(editor.getPath()), filePath) + else if atom.project.getPaths()[0]? and filePath isnt '' return path.join(atom.project.getPaths()[0], filePath) else - throw new Error + throw new CommandError + return replaceGroups = (groups, replString) -> arr = replString.split('') @@ -108,7 +111,9 @@ class Ex tabp: => @tabprevious() edit: (range, filePath) -> - filePath = fs.normalize(filePath.trim()) + filePath = filePath.trim() + if filePath isnt '' + filePath = fs.normalize(filePath) if filePath.indexOf(' ') isnt -1 throw new CommandError('Only one file name allowed') buffer = atom.workspace.getActiveTextEditor().buffer @@ -124,17 +129,23 @@ class Ex buffer.load() write: (range, filePath) -> - filePath = fs.normalize(filePath.trim()) + filePath = filePath.trim() + if filePath isnt '' + filePath = fs.normalize(filePath) deferred = Promise.defer() editor = atom.workspace.getActiveTextEditor() try fullPath = getFullPath(filePath) - catch error + catch CommandError fullPath = atom.showSaveDialogSync() if fullPath? - trySave(-> editor.saveAs(fullPath)) - .then deferred.resolve + if filePath is '' + trySave(-> editor.save()) + .then deferred.resolve + else + trySave(-> saveAs(fullPath)) + .then deferred.resolve editor.buffer.setPath(fullPath) deferred.promise From 9bce86dd4b5fcba9495ba690442e11c0f8218d38 Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Tue, 28 Jul 2015 17:59:48 -0500 Subject: [PATCH 2/2] Only update the path for save not saveAs. Save correctly for new files. --- lib/ex.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 44ddced..004e3a6 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -141,12 +141,16 @@ class Ex fullPath = atom.showSaveDialogSync() if fullPath? if filePath is '' - trySave(-> editor.save()) - .then deferred.resolve + if editor.getPath()? + trySave(-> editor.save()) + .then deferred.resolve + else + trySave(-> editor.saveAs(fullPath)) + .then deferred.resolve + editor.buffer.setPath(fullPath) else trySave(-> saveAs(fullPath)) .then deferred.resolve - editor.buffer.setPath(fullPath) deferred.promise