diff --git a/lib/notational-velocity-view.coffee b/lib/notational-velocity-view.coffee index ac14cd8..454453c 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' @@ -87,16 +88,26 @@ 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) -> + save = -> + atom.packages.deactivatePackage 'whitespace' + editor.save() + atom.packages.activatePackage 'whitespace' + debouncedSave = _.debounce save, 1000 + editor.onDidStopChanging () -> + debouncedSave() if editor.isModified() + + @cancel() destroy: -> @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",