mirror of
https://github.com/wassname/nvatom.git
synced 2026-09-10 12:21:11 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca6f9e76a3 | ||
|
|
5e44098ae3 | ||
|
|
a3f5d445c0 | ||
|
|
abb7339a6e | ||
|
|
4ddc133920 | ||
|
|
bca1646f8f | ||
|
|
40e785ef57 | ||
|
|
273d506f38 | ||
|
|
09d0efc06f |
@@ -1,3 +1,8 @@
|
|||||||
|
## 0.5.0
|
||||||
|
- Add `useLunrPipeline` feature
|
||||||
|
- Improve autoselect/autocomplete logic
|
||||||
|
- Fix a bug that autocomplete feature does not work
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
- Rename `notational-velocity` to `nvatom`
|
- Rename `notational-velocity` to `nvatom`
|
||||||
- Copy `notational-velocity` settings/notes on initialization
|
- Copy `notational-velocity` settings/notes on initialization
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class NotationalVelocityView extends SelectListView
|
|||||||
if !fs.existsSync(@rootDirectory)
|
if !fs.existsSync(@rootDirectory)
|
||||||
throw new Error("The given directory #{@rootDirectory} does not exist. "
|
throw new Error("The given directory #{@rootDirectory} does not exist. "
|
||||||
+ "Set the note directory to the existing one from Settings.")
|
+ "Set the note directory to the existing one from Settings.")
|
||||||
@prevFilterQuery = ''
|
@skipPopulateList = false
|
||||||
@prevCursorPosition = 0
|
@prevCursorPosition = 0
|
||||||
@documentsLoaded = false
|
@documentsLoaded = false
|
||||||
@docQuery = new DocQuery(@rootDirectory, {recursive: true})
|
@docQuery = new DocQuery(@rootDirectory, {recursive: true})
|
||||||
@@ -28,27 +28,41 @@ class NotationalVelocityView extends SelectListView
|
|||||||
@populateList() if @documentsLoaded
|
@populateList() if @documentsLoaded
|
||||||
@docQuery.on "removed", (fileDetails) =>
|
@docQuery.on "removed", (fileDetails) =>
|
||||||
@populateList() if @documentsLoaded
|
@populateList() if @documentsLoaded
|
||||||
|
if !atom.config.get('nvatom.enableLunrPipeline')
|
||||||
|
@docQuery.searchIndex.pipeline.reset()
|
||||||
|
|
||||||
selectItem: (filterQuery) ->
|
isCursorProceeded: ->
|
||||||
if filterQuery.length == 0
|
|
||||||
@prevCursorPosition = 0
|
|
||||||
return null
|
|
||||||
|
|
||||||
titleItem = @docQuery.search(filterQuery)[0]
|
|
||||||
|
|
||||||
# If title item is not null, auto-fill the search panel.
|
|
||||||
# But we don't want to fill it when deleting.
|
|
||||||
editor = @filterEditorView.model
|
editor = @filterEditorView.model
|
||||||
currCursorPosition = editor.getCursorBufferPosition().column
|
currCursorPosition = editor.getCursorBufferPosition().column
|
||||||
if titleItem != undefined && @prevCursorPosition < currCursorPosition
|
isCursorProceeded = @prevCursorPosition < currCursorPosition
|
||||||
@prevFilterQuery = titleItem.title
|
|
||||||
editor.setText(filterQuery + titleItem.title.slice(filterQuery.length))
|
|
||||||
editor.selectLeft(titleItem.title.length - filterQuery.length)
|
|
||||||
@prevCursorPosition = currCursorPosition
|
@prevCursorPosition = currCursorPosition
|
||||||
|
return isCursorProceeded
|
||||||
|
|
||||||
return titleItem
|
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) ->
|
filter: (filterQuery) ->
|
||||||
|
if filterQuery == "" || filterQuery == undefined
|
||||||
|
return @docQuery.documents
|
||||||
return @docQuery.search(filterQuery)
|
return @docQuery.search(filterQuery)
|
||||||
|
|
||||||
getFilterKey: ->
|
getFilterKey: ->
|
||||||
@@ -75,8 +89,8 @@ class NotationalVelocityView extends SelectListView
|
|||||||
@div class: 'secondary-line', "#{content}"
|
@div class: 'secondary-line', "#{content}"
|
||||||
|
|
||||||
confirmSelection: ->
|
confirmSelection: ->
|
||||||
item = @getSelectedItem()
|
item = @getSelectedItem()
|
||||||
filePath = null
|
filePath = null
|
||||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
||||||
calculatedPath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
calculatedPath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
||||||
if item?
|
if item?
|
||||||
@@ -115,15 +129,15 @@ class NotationalVelocityView extends SelectListView
|
|||||||
hide: ->
|
hide: ->
|
||||||
@panel?.hide()
|
@panel?.hide()
|
||||||
|
|
||||||
|
getFilterQuery: ->
|
||||||
|
editor = @filterEditorView.model
|
||||||
|
fullText = editor.getText()
|
||||||
|
selectedText = editor.getSelectedText()
|
||||||
|
return fullText.substring(0, fullText.length - selectedText.length)
|
||||||
|
|
||||||
populateList: ->
|
populateList: ->
|
||||||
filterQuery = @getFilterQuery()
|
filterQuery = @getFilterQuery()
|
||||||
filteredItems = null
|
filteredItems = @filter(filterQuery)
|
||||||
if filterQuery == "" || filterQuery == undefined
|
|
||||||
filteredItems = @docQuery.documents
|
|
||||||
else
|
|
||||||
filteredItems = @filter(filterQuery)
|
|
||||||
|
|
||||||
selectedItem = @selectItem(filterQuery)
|
|
||||||
|
|
||||||
@list.empty()
|
@list.empty()
|
||||||
if filteredItems.length
|
if filteredItems.length
|
||||||
@@ -135,16 +149,12 @@ class NotationalVelocityView extends SelectListView
|
|||||||
itemView.data('select-list-item', item)
|
itemView.data('select-list-item', item)
|
||||||
@list.append(itemView)
|
@list.append(itemView)
|
||||||
|
|
||||||
if selectedItem
|
@selectItem(filteredItems, filterQuery)
|
||||||
n = filteredItems.indexOf(selectedItem) + 1
|
|
||||||
@selectItemView(@list.find("li:nth-child(#{n})"))
|
|
||||||
|
|
||||||
else
|
else
|
||||||
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
||||||
|
|
||||||
schedulePopulateList: ->
|
schedulePopulateList: ->
|
||||||
# We can skip it when we are just moving the position of the cursor.
|
if !@skipPopulateList
|
||||||
currFilterQuery = @getFilterQuery()
|
|
||||||
if @prevFilterQuery != currFilterQuery
|
|
||||||
super
|
super
|
||||||
@prevFilterQuery = currFilterQuery
|
@skipPopulateList = false
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ module.exports =
|
|||||||
description: 'The directory to archive notes'
|
description: 'The directory to archive notes'
|
||||||
type: 'string'
|
type: 'string'
|
||||||
default: path.join(process.env.ATOM_HOME, 'nvatom-notes')
|
default: path.join(process.env.ATOM_HOME, 'nvatom-notes')
|
||||||
|
enableLunrPipeline:
|
||||||
|
title: 'Enable Lunr Pipeline'
|
||||||
|
description: 'Lunr pipeline preprocesses query to make search faster. However, it will skip searching some of stop words such as "an" or "be".'
|
||||||
|
type: 'boolean'
|
||||||
|
default: true
|
||||||
|
|
||||||
notationalVelocityView: null
|
notationalVelocityView: null
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nvatom",
|
"name": "nvatom",
|
||||||
"main": "./lib/notational-velocity",
|
"main": "./lib/notational-velocity",
|
||||||
"version": "0.4.2",
|
"version": "0.5.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Seongjae Lee <seongjae@gmail.com>",
|
"Seongjae Lee <seongjae@gmail.com>",
|
||||||
|
|||||||
Reference in New Issue
Block a user