From e94430630ca05e0a66ebf3baaee413e4da66776e Mon Sep 17 00:00:00 2001 From: Jonathan Hoyt Date: Sat, 9 May 2015 13:49:42 -0700 Subject: [PATCH 1/3] Save in editor.onDidStopChanging Temporarily disables whitespace package so that you can create newlines without getting them removed on autosave. --- lib/notational-velocity-view.coffee | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/notational-velocity-view.coffee b/lib/notational-velocity-view.coffee index ac14cd8..3301d14 100644 --- a/lib/notational-velocity-view.coffee +++ b/lib/notational-velocity-view.coffee @@ -87,16 +87,24 @@ class NotationalVelocityView extends SelectListView confirmSelection: -> item = @getSelectedItem() + filePath = null if item? - atom.workspace.open(item.getFilePath()) - @cancel() + filePath = item.getFilePath() else sanitizedQuery = @getFilterQuery().replace(/\s+$/, '') if sanitizedQuery.length > 0 filePath = path.join(@rootDirectory, sanitizedQuery + '.md') fs.writeFileSync(filePath, '') - atom.workspace.open(filePath) - @cancel() + + if filePath + atom.workspace.open(filePath).then (editor) -> + editor.onDidStopChanging () -> + if editor.isModified() + atom.packages.deactivatePackage("whitespace"); + editor.save() + atom.packages.activatePackage("whitespace"); + + @cancel() destroy: -> @cancel() From 0f269c921698e4954faca6990c2357b3524dac9b Mon Sep 17 00:00:00 2001 From: Jonathan Hoyt Date: Sat, 9 May 2015 14:27:21 -0700 Subject: [PATCH 2/3] Debounce the save so the editor doesn't slow down --- lib/notational-velocity-view.coffee | 12 ++++++++---- package.json | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/notational-velocity-view.coffee b/lib/notational-velocity-view.coffee index 3301d14..799fa71 100644 --- a/lib/notational-velocity-view.coffee +++ b/lib/notational-velocity-view.coffee @@ -1,5 +1,6 @@ path = require 'path' fs = require 'fs-plus' +_ = require 'underscore-plus' {$, $$, SelectListView} = require 'atom-space-pen-views' NoteDirectory = require './note-directory' Note = require './note' @@ -98,11 +99,14 @@ class NotationalVelocityView extends SelectListView if filePath atom.workspace.open(filePath).then (editor) -> + save = -> + atom.packages.deactivatePackage 'whitespace' + console.log 'save' + editor.save() + atom.packages.activatePackage 'whitespace' + debouncedSave = _.debounce save, 1000 editor.onDidStopChanging () -> - if editor.isModified() - atom.packages.deactivatePackage("whitespace"); - editor.save() - atom.packages.activatePackage("whitespace"); + debouncedSave() if editor.isModified() @cancel() diff --git a/package.json b/package.json index 571ddda..a972a09 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "dependencies": { "fs-plus": "2.x", "atom-space-pen-views": "^2.0.3", - "pathwatcher": "^4.2" + "pathwatcher": "^4.2", + "underscore-plus": "^1.6.6" }, "devDependencies": { "fs-plus": "2.x", From 1f91f4d6b55fb8ddc9620d645207cda88c8b8e73 Mon Sep 17 00:00:00 2001 From: Jonathan Hoyt Date: Sat, 9 May 2015 14:34:49 -0700 Subject: [PATCH 3/3] Remove console.log --- lib/notational-velocity-view.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/notational-velocity-view.coffee b/lib/notational-velocity-view.coffee index 799fa71..454453c 100644 --- a/lib/notational-velocity-view.coffee +++ b/lib/notational-velocity-view.coffee @@ -101,7 +101,6 @@ class NotationalVelocityView extends SelectListView atom.workspace.open(filePath).then (editor) -> save = -> atom.packages.deactivatePackage 'whitespace' - console.log 'save' editor.save() atom.packages.activatePackage 'whitespace' debouncedSave = _.debounce save, 1000