mirror of
https://github.com/wassname/nvatom.git
synced 2026-09-10 12:21:11 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc8a780436 | ||
|
|
431b929208 | ||
|
|
61d071c15a | ||
|
|
4e4688fe78 | ||
|
|
0fffc6a6b1 | ||
|
|
547617f485 | ||
|
|
74735eec82 | ||
|
|
fa873af344 | ||
|
|
a31f490a70 | ||
|
|
27f2a5bb8d | ||
|
|
95093df286 | ||
|
|
5e4345f719 | ||
|
|
cee47a8fd7 | ||
|
|
15bf1e741b | ||
|
|
bd19c270b3 | ||
|
|
b5f7ba7b75 | ||
|
|
da888fa461 | ||
|
|
97830b31db | ||
|
|
a06e0127c2 | ||
|
|
cfd9dcef85 | ||
|
|
ca6f9e76a3 | ||
|
|
5e44098ae3 | ||
|
|
a3f5d445c0 | ||
|
|
abb7339a6e | ||
|
|
4ddc133920 | ||
|
|
bca1646f8f | ||
|
|
40e785ef57 | ||
|
|
273d506f38 | ||
|
|
09d0efc06f |
@@ -1,3 +1,14 @@
|
||||
## 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
|
||||
- Add `useLunrPipeline` setting
|
||||
- Improve autoselect/autocomplete logic
|
||||
- Fix a bug that autocomplete feature does not work
|
||||
|
||||
## 0.4.0
|
||||
- Rename `notational-velocity` to `nvatom`
|
||||
- Copy `notational-velocity` settings/notes on initialization
|
||||
|
||||
@@ -59,7 +59,7 @@ You can also override `cmd-l` if you want to keep your muscle memory from Notati
|
||||
|
||||
## Migration
|
||||
|
||||
v0.1.0 under published package name `notational-velocity` had a fatal bug that sets the default value of its note directory under package directory. Since package directory is overwritten when the user updates `notational-velocity` package. For more information, refer [#25][6].
|
||||
v0.1.0 under published package name `notational-velocity` had a fatal bug that sets the default value of its note directory under package directory. In that case, all notes are deleted once the user updates the package, since package directory is overwritten when the user. For more information, refer [#25][6].
|
||||
|
||||
To resolve this problem, we renamed our package name to `nvatom`. Users who have the old `notational-velocity` need to **install `nvatom` package first**, activate the package to automatically migrate the existing notes, and then delete `notational-velocity` package.
|
||||
|
||||
@@ -76,7 +76,7 @@ Since keymaps overlap with `notational-velocity`, follow the menu *Packages > nv
|
||||
|
||||
[1]: http://notational.net/
|
||||
[2]: http://daringfireball.net/projects/markdown/syntax
|
||||
[3]: https://travis-ci.org/seongjaelee/notational-velocity.svg?branch=master
|
||||
[4]: https://travis-ci.org/seongjaelee/notational-velocity
|
||||
[3]: https://travis-ci.org/seongjaelee/nvatom.svg?branch=master
|
||||
[4]: https://travis-ci.org/seongjaelee/nvatom
|
||||
[5]: https://cloud.githubusercontent.com/assets/948301/7246990/2e2b4c6e-e7b9-11e4-93b0-57954e011e81.gif
|
||||
[6]: https://github.com/seongjaelee/notational-velocity/issues/25
|
||||
[6]: https://github.com/seongjaelee/nvatom/issues/25
|
||||
|
||||
@@ -10,14 +10,14 @@ class NotationalVelocityView extends SelectListView
|
||||
@initializedAt = new Date()
|
||||
super
|
||||
@addClass('nvatom from-top overlay')
|
||||
@rootDirectory = atom.config.get('nvatom.directory')
|
||||
if !fs.existsSync(@rootDirectory)
|
||||
@rootDirectory = fs.normalize(atom.config.get('nvatom.directory'))
|
||||
unless fs.existsSync(@rootDirectory)
|
||||
throw new Error("The given directory #{@rootDirectory} does not exist. "
|
||||
+ "Set the note directory to the existing one from Settings.")
|
||||
@prevFilterQuery = ''
|
||||
@skipPopulateList = false
|
||||
@prevCursorPosition = 0
|
||||
@documentsLoaded = false
|
||||
@docQuery = new DocQuery(@rootDirectory, {recursive: true})
|
||||
@docQuery = new DocQuery(@rootDirectory, {recursive: true, extensions: atom.config.get('nvatom.extensions')})
|
||||
@docQuery.on "ready", () =>
|
||||
@documentsLoaded = true
|
||||
@setLoading()
|
||||
@@ -28,27 +28,41 @@ class NotationalVelocityView extends SelectListView
|
||||
@populateList() if @documentsLoaded
|
||||
@docQuery.on "removed", (fileDetails) =>
|
||||
@populateList() if @documentsLoaded
|
||||
unless atom.config.get('nvatom.enableLunrPipeline')
|
||||
@docQuery.searchIndex.pipeline.reset()
|
||||
|
||||
selectItem: (filterQuery) ->
|
||||
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.
|
||||
isCursorProceeded: ->
|
||||
editor = @filterEditorView.model
|
||||
currCursorPosition = editor.getCursorBufferPosition().column
|
||||
if titleItem != undefined && @prevCursorPosition < currCursorPosition
|
||||
@prevFilterQuery = titleItem.title
|
||||
editor.setText(filterQuery + titleItem.title.slice(filterQuery.length))
|
||||
editor.selectLeft(titleItem.title.length - filterQuery.length)
|
||||
isCursorProceeded = @prevCursorPosition < currCursorPosition
|
||||
@prevCursorPosition = currCursorPosition
|
||||
return isCursorProceeded
|
||||
|
||||
return titleItem
|
||||
selectItem: (filteredItems, filterQuery) ->
|
||||
isCursorProceeded = @isCursorProceeded()
|
||||
|
||||
for item in filteredItems
|
||||
if item.title.toLowerCase() is filterQuery.toLowerCase()
|
||||
# autoselect
|
||||
n = filteredItems.indexOf(item) + 1
|
||||
@selectItemView(@list.find("li:nth-child(#{n})"))
|
||||
return
|
||||
|
||||
for item in filteredItems
|
||||
if item.title.toLowerCase().startsWith(filterQuery.toLowerCase()) and 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 is "") or (filterQuery is undefined)
|
||||
return @docQuery.documents
|
||||
return @docQuery.search(filterQuery)
|
||||
|
||||
getFilterKey: ->
|
||||
@@ -75,10 +89,11 @@ class NotationalVelocityView extends SelectListView
|
||||
@div class: 'secondary-line', "#{content}"
|
||||
|
||||
confirmSelection: ->
|
||||
item = @getSelectedItem()
|
||||
filePath = null
|
||||
item = @getSelectedItem()
|
||||
filePath = null
|
||||
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?
|
||||
filePath = item.filePath
|
||||
else if fs.existsSync(calculatedPath)
|
||||
@@ -115,15 +130,15 @@ class NotationalVelocityView extends SelectListView
|
||||
hide: ->
|
||||
@panel?.hide()
|
||||
|
||||
getFilterQuery: ->
|
||||
editor = @filterEditorView.model
|
||||
fullText = editor.getText()
|
||||
selectedText = editor.getSelectedText()
|
||||
return fullText.substring(0, fullText.length - selectedText.length)
|
||||
|
||||
populateList: ->
|
||||
filterQuery = @getFilterQuery()
|
||||
filteredItems = null
|
||||
if filterQuery == "" || filterQuery == undefined
|
||||
filteredItems = @docQuery.documents
|
||||
else
|
||||
filteredItems = @filter(filterQuery)
|
||||
|
||||
selectedItem = @selectItem(filterQuery)
|
||||
filteredItems = @filter(filterQuery)
|
||||
|
||||
@list.empty()
|
||||
if filteredItems.length
|
||||
@@ -135,16 +150,12 @@ class NotationalVelocityView extends SelectListView
|
||||
itemView.data('select-list-item', item)
|
||||
@list.append(itemView)
|
||||
|
||||
if selectedItem
|
||||
n = filteredItems.indexOf(selectedItem) + 1
|
||||
@selectItemView(@list.find("li:nth-child(#{n})"))
|
||||
@selectItem(filteredItems, filterQuery)
|
||||
|
||||
else
|
||||
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
||||
|
||||
schedulePopulateList: ->
|
||||
# We can skip it when we are just moving the position of the cursor.
|
||||
currFilterQuery = @getFilterQuery()
|
||||
if @prevFilterQuery != currFilterQuery
|
||||
unless @skipPopulateList
|
||||
super
|
||||
@prevFilterQuery = currFilterQuery
|
||||
@skipPopulateList = false
|
||||
|
||||
@@ -9,6 +9,18 @@ module.exports =
|
||||
description: 'The directory to archive notes'
|
||||
type: 'string'
|
||||
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:
|
||||
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
|
||||
|
||||
@@ -35,7 +47,7 @@ module.exports =
|
||||
window.addEventListener('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: ->
|
||||
@subscriptions.dispose()
|
||||
@@ -54,26 +66,37 @@ module.exports =
|
||||
return unless paneItem?.getURI?()?
|
||||
return unless paneItem?.isModified?()
|
||||
uri = paneItem.getURI()
|
||||
return unless uri.indexOf(@rootDirectory) == 0
|
||||
return unless fs.isMarkdownExtension(path.extname(uri))
|
||||
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) 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: ->
|
||||
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
||||
|
||||
ensureNoteDirectory: ->
|
||||
noteDirectory = atom.config.get('nvatom.directory')
|
||||
noteDirectory = fs.normalize(atom.config.get('nvatom.directory'))
|
||||
packagesDirectory = path.join(process.env.ATOM_HOME, 'packages')
|
||||
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
|
||||
|
||||
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.
|
||||
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)
|
||||
|
||||
@@ -86,13 +109,13 @@ 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)
|
||||
atom.notifications.addError('notational-velocity.directory #{prevNoteDirectory} does not exists. Migration process is failed.')
|
||||
unless fs.existsSync(prevNoteDirectory)
|
||||
atom.notifications.addError("notational-velocity.directory #{prevNoteDirectory} does not exists. Migration process is failed.")
|
||||
return
|
||||
|
||||
if prevNoteDirectory.startsWith(packagesDirectory)
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "nvatom",
|
||||
"main": "./lib/notational-velocity",
|
||||
"version": "0.4.2",
|
||||
"version": "0.8.2",
|
||||
"private": true,
|
||||
"contributors": [
|
||||
"Seongjae Lee <seongjae@gmail.com>",
|
||||
@@ -12,15 +12,15 @@
|
||||
"activationCommands": {
|
||||
"atom-workspace": "nvatom:toggle"
|
||||
},
|
||||
"repository": "https://github.com/seongjaelee/notational-velocity",
|
||||
"repository": "https://github.com/seongjaelee/nvatom",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"atom": ">0.50.0"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/seongjaelee/notational-velocity/issues"
|
||||
"url": "https://github.com/seongjaelee/nvatom/issues"
|
||||
},
|
||||
"homepage": "https://github.com/seongjaelee/notational-velocity",
|
||||
"homepage": "https://github.com/seongjaelee/nvatom",
|
||||
"dependencies": {
|
||||
"atom-space-pen-views": "^2.0.3",
|
||||
"chokidar": "^1.0.5",
|
||||
|
||||
Reference in New Issue
Block a user