mirror of
https://github.com/wassname/nvatom.git
synced 2026-09-10 12:21:11 +08:00
Compare commits
13
Commits
v0.6.0
...
feature-30
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce9869362a | ||
|
|
4e4688fe78 | ||
|
|
0fffc6a6b1 | ||
|
|
547617f485 | ||
|
|
74735eec82 | ||
|
|
fa873af344 | ||
|
|
a31f490a70 | ||
|
|
27f2a5bb8d | ||
|
|
95093df286 | ||
|
|
5e4345f719 | ||
|
|
cee47a8fd7 | ||
|
|
15bf1e741b | ||
|
|
bd19c270b3 |
+7
-1
@@ -1,5 +1,11 @@
|
|||||||
|
## 0.8.0
|
||||||
|
- Add a feature to delete an empty note automatically when closing its pane
|
||||||
|
|
||||||
|
## 0.7.0
|
||||||
|
- Add `extensions` setting
|
||||||
|
|
||||||
## 0.5.0
|
## 0.5.0
|
||||||
- Add `useLunrPipeline` feature
|
- Add `useLunrPipeline` setting
|
||||||
- Improve autoselect/autocomplete logic
|
- Improve autoselect/autocomplete logic
|
||||||
- Fix a bug that autocomplete feature does not work
|
- Fix a bug that autocomplete feature does not work
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ class NotationalVelocityView extends SelectListView
|
|||||||
super
|
super
|
||||||
@addClass('nvatom from-top overlay')
|
@addClass('nvatom from-top overlay')
|
||||||
@rootDirectory = atom.config.get('nvatom.directory')
|
@rootDirectory = atom.config.get('nvatom.directory')
|
||||||
if !fs.existsSync(@rootDirectory)
|
unless 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.")
|
||||||
@skipPopulateList = false
|
@skipPopulateList = false
|
||||||
@prevCursorPosition = 0
|
@prevCursorPosition = 0
|
||||||
@documentsLoaded = false
|
@documentsLoaded = false
|
||||||
@docQuery = new DocQuery(@rootDirectory, {recursive: true})
|
@docQuery = new DocQuery(@rootDirectory, {recursive: true, extensions: atom.config.get('nvatom.extensions')})
|
||||||
@docQuery.on "ready", () =>
|
@docQuery.on "ready", () =>
|
||||||
@documentsLoaded = true
|
@documentsLoaded = true
|
||||||
@setLoading()
|
@setLoading()
|
||||||
@@ -28,7 +28,7 @@ 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')
|
unless atom.config.get('nvatom.enableLunrPipeline')
|
||||||
@docQuery.searchIndex.pipeline.reset()
|
@docQuery.searchIndex.pipeline.reset()
|
||||||
|
|
||||||
isCursorProceeded: ->
|
isCursorProceeded: ->
|
||||||
@@ -38,33 +38,6 @@ class NotationalVelocityView extends SelectListView
|
|||||||
@prevCursorPosition = currCursorPosition
|
@prevCursorPosition = currCursorPosition
|
||||||
return isCursorProceeded
|
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: ->
|
getFilterKey: ->
|
||||||
'filetext'
|
'filetext'
|
||||||
|
|
||||||
@@ -92,7 +65,8 @@ class NotationalVelocityView extends SelectListView
|
|||||||
item = @getSelectedItem()
|
item = @getSelectedItem()
|
||||||
filePath = null
|
filePath = null
|
||||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
||||||
calculatedPath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
extension = if atom.config.get('nvatom.extensions').length then atom.config.get('nvatom.extensions')[0] else '.md'
|
||||||
|
calculatedPath = path.join(@rootDirectory, sanitizedQuery + extension)
|
||||||
if item?
|
if item?
|
||||||
filePath = item.filePath
|
filePath = item.filePath
|
||||||
else if fs.existsSync(calculatedPath)
|
else if fs.existsSync(calculatedPath)
|
||||||
@@ -135,26 +109,75 @@ class NotationalVelocityView extends SelectListView
|
|||||||
selectedText = editor.getSelectedText()
|
selectedText = editor.getSelectedText()
|
||||||
return fullText.substring(0, fullText.length - selectedText.length)
|
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: ->
|
populateList: ->
|
||||||
filterQuery = @getFilterQuery()
|
filterQuery = @getFilterQuery()
|
||||||
filteredItems = @filter(filterQuery)
|
notesByTitle = @filterByTitle(filterQuery)
|
||||||
|
notesByLunr = @filterByLunr(filterQuery)
|
||||||
|
isCursorProceeded = @isCursorProceeded()
|
||||||
|
|
||||||
@list.empty()
|
@list.empty()
|
||||||
if filteredItems.length
|
if notesByTitle.length + notesByLunr.length == 0
|
||||||
@setError(null)
|
@setError(@getEmptyMessage(@docQuery.documents.length, 0))
|
||||||
|
return
|
||||||
|
|
||||||
for i in [0...Math.min(filteredItems.length, @maxItems)]
|
@setError(null)
|
||||||
item = filteredItems[i]
|
for note in notesByTitle
|
||||||
itemView = $(@viewForItem(item))
|
itemView = $(@viewForItem(note))
|
||||||
itemView.data('select-list-item', item)
|
itemView.data('select-list-item', note)
|
||||||
@list.append(itemView)
|
@list.append(itemView)
|
||||||
|
|
||||||
@selectItem(filteredItems, filterQuery)
|
if notesByTitle.length
|
||||||
|
# autoselect
|
||||||
|
@selectItemView(@list.find("li:nth-child(1)"))
|
||||||
|
|
||||||
else
|
#autocomplete
|
||||||
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
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: ->
|
schedulePopulateList: ->
|
||||||
if !@skipPopulateList
|
unless @skipPopulateList
|
||||||
super
|
super
|
||||||
@skipPopulateList = false
|
@skipPopulateList = false
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ 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')
|
||||||
|
extensions:
|
||||||
|
title: 'Extensions'
|
||||||
|
description: 'The first extension will be used for newly created notes.'
|
||||||
|
type: 'array'
|
||||||
|
default: ['.md', '.txt']
|
||||||
|
items:
|
||||||
|
type: 'string'
|
||||||
enableLunrPipeline:
|
enableLunrPipeline:
|
||||||
title: 'Enable Lunr Pipeline'
|
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".'
|
description: 'Lunr pipeline preprocesses query to make search faster. However, it will skip searching some of stop words such as "an" or "be".'
|
||||||
@@ -40,7 +47,7 @@ module.exports =
|
|||||||
window.addEventListener('blur', handleBlur, true)
|
window.addEventListener('blur', handleBlur, true)
|
||||||
@subscriptions.add new Disposable -> window.removeEventListener('blur', handleBlur, true)
|
@subscriptions.add new Disposable -> window.removeEventListener('blur', handleBlur, true)
|
||||||
|
|
||||||
@subscriptions.add atom.workspace.onWillDestroyPaneItem ({item}) => @autosave(item)
|
@subscriptions.add atom.workspace.onWillDestroyPaneItem ({item}) => @autosave(item) unless @autodelete(item)
|
||||||
|
|
||||||
deactivate: ->
|
deactivate: ->
|
||||||
@subscriptions.dispose()
|
@subscriptions.dispose()
|
||||||
@@ -59,10 +66,21 @@ module.exports =
|
|||||||
return unless paneItem?.getURI?()?
|
return unless paneItem?.getURI?()?
|
||||||
return unless paneItem?.isModified?()
|
return unless paneItem?.isModified?()
|
||||||
uri = paneItem.getURI()
|
uri = paneItem.getURI()
|
||||||
return unless uri.indexOf(@rootDirectory) == 0
|
return unless uri.indexOf(@rootDirectory) is 0
|
||||||
return unless fs.isMarkdownExtension(path.extname(uri))
|
return unless path.extname(uri) in atom.config.get('nvatom.extensions')
|
||||||
paneItem?.save?()
|
paneItem?.save?()
|
||||||
|
|
||||||
|
autodelete: (paneItem) ->
|
||||||
|
return false unless paneItem?.getURI?()?
|
||||||
|
uri = paneItem.getURI()
|
||||||
|
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)
|
||||||
|
noteName = uri.substring(@rootDirectory.length + 1)
|
||||||
|
atom.notifications.addInfo("Empty note #{noteName} is deleted.")
|
||||||
|
return true
|
||||||
|
|
||||||
autosaveAll: ->
|
autosaveAll: ->
|
||||||
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
||||||
|
|
||||||
@@ -72,13 +90,13 @@ module.exports =
|
|||||||
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
|
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
|
||||||
|
|
||||||
if noteDirectory.startsWith(packagesDirectory)
|
if noteDirectory.startsWith(packagesDirectory)
|
||||||
throw new Error('Note directory #{noteDirectory} cannot reside within atom packages directory. Please change its value from package settings.')
|
throw new Error("Note directory #{noteDirectory} cannot reside within atom packages directory. Please change its value from package settings.")
|
||||||
|
|
||||||
# Initialize note directory.
|
# Initialize note directory.
|
||||||
if !fs.existsSync(noteDirectory)
|
unless fs.existsSync(noteDirectory)
|
||||||
@tryMigrateFromNotationalVelocity()
|
@tryMigrateFromNotationalVelocity()
|
||||||
noteDirectory = atom.config.get('nvatom.directory')
|
noteDirectory = atom.config.get('nvatom.directory')
|
||||||
if !fs.existsSync(noteDirectory)
|
unless fs.existsSync(noteDirectory)
|
||||||
fs.makeTreeSync(noteDirectory)
|
fs.makeTreeSync(noteDirectory)
|
||||||
fs.copySync(defaultNoteDirectory, noteDirectory)
|
fs.copySync(defaultNoteDirectory, noteDirectory)
|
||||||
|
|
||||||
@@ -91,13 +109,13 @@ module.exports =
|
|||||||
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
|
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
|
||||||
|
|
||||||
# notational-velocity does not exist.
|
# notational-velocity does not exist.
|
||||||
if prevNoteDirectory == undefined
|
if prevNoteDirectory is undefined
|
||||||
return
|
return
|
||||||
|
|
||||||
atom.notifications.addInfo('Migrating from notational-velocity package...')
|
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.')
|
atom.notifications.addError("notational-velocity.directory #{prevNoteDirectory} does not exists. Migration process is failed.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if prevNoteDirectory.startsWith(packagesDirectory)
|
if prevNoteDirectory.startsWith(packagesDirectory)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nvatom",
|
"name": "nvatom",
|
||||||
"main": "./lib/notational-velocity",
|
"main": "./lib/notational-velocity",
|
||||||
"version": "0.6.0",
|
"version": "0.8.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Seongjae Lee <seongjae@gmail.com>",
|
"Seongjae Lee <seongjae@gmail.com>",
|
||||||
|
|||||||
Reference in New Issue
Block a user