From 3eb8ff93c3b8a26550db4a64b0acb1c2159d3e78 Mon Sep 17 00:00:00 2001 From: Seongjae Lee Date: Sun, 19 Apr 2015 23:50:23 -0700 Subject: [PATCH] Enable creating a note via the search panel Fix #6. --- lib/notational-velocity-view.coffee | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/notational-velocity-view.coffee b/lib/notational-velocity-view.coffee index 9e04b58..e85bc60 100644 --- a/lib/notational-velocity-view.coffee +++ b/lib/notational-velocity-view.coffee @@ -1,3 +1,5 @@ +path = require 'path' +fs = require 'fs-plus' {$, $$, SelectListView} = require 'atom-space-pen-views' NoteDirectory = require './note-directory' Note = require './note' @@ -7,8 +9,8 @@ class NotationalVelocityView extends SelectListView initialize: -> super @addClass('notational-velocity from-top overlay') - rootDirectory = atom.config.get('notational-velocity.directory') - @noteDirectory = new NoteDirectory(rootDirectory, null, () => @updateNotes()) + @rootDirectory = atom.config.get('notational-velocity.directory') + @noteDirectory = new NoteDirectory(@rootDirectory, null, () => @updateNotes()) @updateNotes() @prevFilterQuery = '' @prevCursorPosition = 0 @@ -83,14 +85,14 @@ class NotationalVelocityView extends SelectListView confirmSelection: -> item = @getSelectedItem() if item? - @confirmed(item) - else - query = @getFilterQuery() + atom.workspace.open(item.getFilePath()) + @cancel() + else + sanitizedQuery = @getFilterQuery().replace(/\s+$/, '') + filePath = path.join(@rootDirectory, sanitizedQuery + '.md') + fs.writeFileSync(filePath, '') + atom.workspace.open(filePath) @cancel() - - confirmed: (item) -> - atom.workspace.open(item.getFilePath()) - @cancel() destroy: -> @cancel()