4 Commits
3 changed files with 70 additions and 48 deletions
+63 -41
View File
@@ -11,7 +11,7 @@ class NotationalVelocityView extends SelectListView
super
@addClass('nvatom from-top overlay')
@rootDirectory = atom.config.get('nvatom.directory')
if !fs.existsSync(@rootDirectory)
unless fs.existsSync(@rootDirectory)
throw new Error("The given directory #{@rootDirectory} does not exist. "
+ "Set the note directory to the existing one from Settings.")
@skipPopulateList = false
@@ -28,7 +28,7 @@ class NotationalVelocityView extends SelectListView
@populateList() if @documentsLoaded
@docQuery.on "removed", (fileDetails) =>
@populateList() if @documentsLoaded
if !atom.config.get('nvatom.enableLunrPipeline')
unless atom.config.get('nvatom.enableLunrPipeline')
@docQuery.searchIndex.pipeline.reset()
isCursorProceeded: ->
@@ -38,33 +38,6 @@ class NotationalVelocityView extends SelectListView
@prevCursorPosition = currCursorPosition
return isCursorProceeded
selectItem: (filteredItems, filterQuery) ->
isCursorProceeded = @isCursorProceeded()
for item in filteredItems
if item.title.match(///^#{filterQuery}$///i) != null
# autoselect
n = filteredItems.indexOf(item) + 1
@selectItemView(@list.find("li:nth-child(#{n})"))
return
for item in filteredItems
if item.title.match(///^#{filterQuery}///i) != null && isCursorProceeded
# autocomplete
@skipPopulateList = true
editor = @filterEditorView.model
editor.setText(filterQuery + item.title.slice(filterQuery.length))
editor.selectLeft(item.title.length - filterQuery.length)
# autoselect
n = filteredItems.indexOf(item) + 1
@selectItemView(@list.find("li:nth-child(#{n})"))
filter: (filterQuery) ->
if filterQuery == "" || filterQuery == undefined
return @docQuery.documents
return @docQuery.search(filterQuery)
getFilterKey: ->
'filetext'
@@ -136,26 +109,75 @@ class NotationalVelocityView extends SelectListView
selectedText = editor.getSelectedText()
return fullText.substring(0, fullText.length - selectedText.length)
filterByTitle: (filterQuery) ->
if (filterQuery is "") or (filterQuery is undefined)
return []
filterQuery = filterQuery.toLowerCase()
matchingNotes = []
filteredNotes = []
for note in @docQuery.documents
title = note.title.toLowerCase()
if title is filterQuery
matchingNotes.push(note)
else if filteredNotes.length < @maxItems and title.startsWith(filterQuery)
filteredNotes.push(note)
notes = matchingNotes.concat(filteredNotes)
if notes.length > @maxItems
notes = notes.slice(0, @maxItems)
return notes
filterByLunr: (filterQuery) ->
notes = []
if (filterQuery is "") or (filterQuery is undefined)
notes = @docQuery.documents
else
notes = @docQuery.search(filterQuery)
if notes.length > @maxItems
notes = notes.slice(0, @maxItems)
return notes
populateList: ->
filterQuery = @getFilterQuery()
filteredItems = @filter(filterQuery)
notesByTitle = @filterByTitle(filterQuery)
notesByLunr = @filterByLunr(filterQuery)
isCursorProceeded = @isCursorProceeded()
@list.empty()
if filteredItems.length
@setError(null)
if notesByTitle.length + notesByLunr.length == 0
@setError(@getEmptyMessage(@docQuery.documents.length, 0))
return
for i in [0...Math.min(filteredItems.length, @maxItems)]
item = filteredItems[i]
itemView = $(@viewForItem(item))
itemView.data('select-list-item', item)
@list.append(itemView)
@setError(null)
for note in notesByTitle
itemView = $(@viewForItem(note))
itemView.data('select-list-item', note)
@list.append(itemView)
@selectItem(filteredItems, filterQuery)
if notesByTitle.length
# autoselect
@selectItemView(@list.find("li:nth-child(1)"))
else
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
#autocomplete
note = notesByTitle[0]
if note.title.toLowerCase() is filterQuery.toLowerCase() or isCursorProceeded
@skipPopulateList = true
editor = @filterEditorView.model
editor.setText(filterQuery + note.title.slice(filterQuery.length))
editor.selectLeft(note.title.length - filterQuery.length)
if @list.length >= @maxItems
return
for note in notesByLunr
if @list.length >= @maxItems
break
if filterQuery?.length and note.title.toLowerCase().startsWith(filterQuery.toLowerCase())
continue
itemView = $(@viewForItem(note))
itemView.data('select-list-item', note)
@list.append(itemView)
schedulePopulateList: ->
if !@skipPopulateList
unless @skipPopulateList
super
@skipPopulateList = false
+6 -6
View File
@@ -66,14 +66,14 @@ module.exports =
return unless paneItem?.getURI?()?
return unless paneItem?.isModified?()
uri = paneItem.getURI()
return unless uri.indexOf(@rootDirectory) == 0
return unless uri.indexOf(@rootDirectory) is 0
return unless path.extname(uri) in atom.config.get('nvatom.extensions')
paneItem?.save?()
autodelete: (paneItem) ->
return false unless paneItem?.getURI?()?
uri = paneItem.getURI()
return false unless uri.indexOf(@rootDirectory) == 0
return false unless uri.indexOf(@rootDirectory) is 0
return false unless path.extname(uri) in atom.config.get('nvatom.extensions')
return false unless paneItem?.isEmpty()
fs.unlinkSync(uri)
@@ -93,10 +93,10 @@ module.exports =
throw new Error("Note directory #{noteDirectory} cannot reside within atom packages directory. Please change its value from package settings.")
# Initialize note directory.
if !fs.existsSync(noteDirectory)
unless fs.existsSync(noteDirectory)
@tryMigrateFromNotationalVelocity()
noteDirectory = atom.config.get('nvatom.directory')
if !fs.existsSync(noteDirectory)
unless fs.existsSync(noteDirectory)
fs.makeTreeSync(noteDirectory)
fs.copySync(defaultNoteDirectory, noteDirectory)
@@ -109,12 +109,12 @@ module.exports =
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
# notational-velocity does not exist.
if prevNoteDirectory == undefined
if prevNoteDirectory is undefined
return
atom.notifications.addInfo('Migrating from notational-velocity package...')
if !fs.existsSync(prevNoteDirectory)
unless fs.existsSync(prevNoteDirectory)
atom.notifications.addError("notational-velocity.directory #{prevNoteDirectory} does not exists. Migration process is failed.")
return
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "nvatom",
"main": "./lib/notational-velocity",
"version": "0.8.0",
"version": "0.8.1",
"private": true,
"contributors": [
"Seongjae Lee <seongjae@gmail.com>",