mirror of
https://github.com/wassname/nvatom.git
synced 2026-09-10 12:21:11 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee5dc2a87a | ||
|
|
bd7d47474c | ||
|
|
424f2a13d6 | ||
|
|
04b7df8676 | ||
|
|
2d2a070d1e | ||
|
|
6ae37437be | ||
|
|
51f769a017 | ||
|
|
ca7c14e3b7 | ||
|
|
c5eca919ed | ||
|
|
9244b0a0b9 | ||
|
|
323fb29e56 | ||
|
|
6c55f58774 | ||
|
|
9c5c4e43da | ||
|
|
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 | ||
|
|
4dd0b518aa | ||
|
|
bdf384f158 | ||
|
|
c2db598f17 | ||
|
|
1e1aa06e3c | ||
|
|
8384b81a04 | ||
|
|
ef3fb73c88 | ||
|
|
6c9752ae25 | ||
|
|
bb80f5e203 | ||
|
|
5f26638a78 |
@@ -1,3 +1,24 @@
|
||||
## 0.9.0
|
||||
- Add an interlink feature
|
||||
|
||||
## 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
|
||||
|
||||
## 0.3.0
|
||||
- Fix the bug that the default note directory is within packages directory. If it happens, it **deletes** all of existing notes. If you read this before updating the package, please check your note directory before updating it.
|
||||
|
||||
## 0.2.0
|
||||
- Use DocQuery
|
||||
- Introduce autosave features
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Notational Velocity for Atom
|
||||
|
||||
*`notational-velocity` package is renamed to `nvatom` package due to a fatal bug. For more info, refer [migration section](#migration).*
|
||||
|
||||
[![Build Status][3]][4]
|
||||
|
||||
[Notational Velocity][1] is an application that stores and retrieves notes.
|
||||
@@ -11,6 +13,7 @@ This Atom package implements the some key features from this amazing app:
|
||||
- Modeless operation
|
||||
- Mouseless interaction
|
||||
- Incremental Search
|
||||
- Interlinks
|
||||
|
||||
Integrated with Atom, we have several advantages:
|
||||
|
||||
@@ -26,13 +29,13 @@ We do believe Notational Velocity is the precursor of the famous note-taking app
|
||||
|
||||
## Settings
|
||||
|
||||
To configure your note directory, set `notational-velocity.directory`:
|
||||
To configure your note directory, set `nvatom.directory`:
|
||||
|
||||
* Open your `~/.atom/config.cson` file from the menu: *Atom > Open Your Config*
|
||||
* Append the following lines:
|
||||
|
||||
```cson
|
||||
'notational-velocity':
|
||||
'nvatom':
|
||||
directory: '/path/to/your/notes'
|
||||
```
|
||||
|
||||
@@ -45,6 +48,7 @@ Double-quotes also work.
|
||||
## Key Bindings
|
||||
|
||||
- `alt-cmd-l`: Toggles the search view.
|
||||
- `alt-cmd-o`: Jumps to the referred note when the cursor is on the interlink in the form of [[double-bracketed interlink]].
|
||||
|
||||
You can also override `cmd-l` if you want to keep your muscle memory from Notational Velocity and nvALT. Just edit your keymap (Atom menu -> Open Your Keymap) and add the following lines:
|
||||
|
||||
@@ -52,9 +56,17 @@ You can also override `cmd-l` if you want to keep your muscle memory from Notati
|
||||
'atom-text-editor':
|
||||
'cmd-l': 'unset!'
|
||||
'atom-workspace':
|
||||
'cmd-l': 'notational-velocity:toggle'
|
||||
'cmd-l': 'nvatom:toggle'
|
||||
```
|
||||
|
||||
## 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. 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.
|
||||
|
||||
Since keymaps overlap with `notational-velocity`, follow the menu *Packages > nvAtom > Toggle* to activate this package.
|
||||
|
||||
## References
|
||||
|
||||
- [Notational Velocity](http://notational.net/)
|
||||
@@ -66,6 +78,7 @@ You can also override `cmd-l` if you want to keep your muscle memory from Notati
|
||||
|
||||
[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/nvatom/issues/25
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
'name': 'nvAtom Github Markdown'
|
||||
'scopeName': 'source.gfm.nvatom'
|
||||
'patterns': [
|
||||
{
|
||||
'include': 'source.gfm'
|
||||
}
|
||||
{
|
||||
'match': '(?<!\\[)(\\[\\[)([^\\[\\]\|]+)(\\]\\])(?!\\])'
|
||||
'name': 'interlink'
|
||||
'captures':
|
||||
'1':
|
||||
'name': 'punctuation.definition.begin.gfm'
|
||||
'2':
|
||||
'name': 'markup.underline.link.interlink.gfm'
|
||||
'3':
|
||||
'name': 'punctuation.definition.begin.gfm'
|
||||
}
|
||||
]
|
||||
@@ -8,4 +8,6 @@
|
||||
# For more detailed documentation see
|
||||
# https://atom.io/docs/latest/advanced/keymaps
|
||||
'atom-workspace':
|
||||
'alt-cmd-l': 'notational-velocity:toggle'
|
||||
'alt-cmd-l': 'nvatom:toggle'
|
||||
'atom-workspace atom-text-editor':
|
||||
'alt-cmd-o': 'nvatom:openInterlink'
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
{CompositeDisposable} = require 'atom'
|
||||
Utility = require './utility'
|
||||
|
||||
module.exports =
|
||||
class Interlink
|
||||
constructor: ->
|
||||
Interlink.loadGrammarSync()
|
||||
@subscriptions = new CompositeDisposable
|
||||
@subscriptions.add atom.commands.add 'atom-workspace', 'nvatom:openInterlink': => Interlink.openInterlink()
|
||||
@subscriptions.add atom.workspace.observeTextEditors (editor) ->
|
||||
if Utility.isNote(editor.getPath())
|
||||
editor.setGrammar(atom.grammars.grammarForScopeName('source.gfm.nvatom'))
|
||||
|
||||
destroy: ->
|
||||
@subscriptions.dispose()
|
||||
|
||||
@loadGrammarSync: ->
|
||||
unless atom.grammars.grammarForScopeName('source.gfm.nvatom')
|
||||
grammarPath = path.join(atom.packages.resolvePackagePath('nvatom'), 'grammars', 'nvatom.cson')
|
||||
atom.grammars.loadGrammarSync(grammarPath)
|
||||
|
||||
@openInterlink: ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
return unless editor?
|
||||
return unless Utility.isNote(editor.getPath())
|
||||
|
||||
noteTitle = Interlink.getInterlinkUnderCursor(editor)
|
||||
return unless noteTitle?
|
||||
return unless noteTitle.length
|
||||
|
||||
notePath = Utility.getNotePath(noteTitle)
|
||||
|
||||
unless fs.existsSync(notePath)
|
||||
fs.writeFileSync(notePath, '')
|
||||
atom.workspace.open(notePath)
|
||||
|
||||
@getInterlinkUnderCursor: (editor) ->
|
||||
cursorPosition = editor.getCursorBufferPosition()
|
||||
token = editor.tokenForBufferPosition(cursorPosition)
|
||||
return unless token
|
||||
return unless token.value
|
||||
return unless token.scopes.indexOf('markup.underline.link.interlink.gfm') > -1
|
||||
|
||||
interlink = Utility.trim(token.value)
|
||||
return unless interlink.length
|
||||
return interlink
|
||||
@@ -2,22 +2,23 @@ path = require 'path'
|
||||
fs = require 'fs-plus'
|
||||
_ = require 'underscore-plus'
|
||||
{$, $$, SelectListView} = require 'atom-space-pen-views'
|
||||
DocQuery = require 'DocQuery'
|
||||
DocQuery = require 'docquery'
|
||||
Utility = require './utility'
|
||||
|
||||
module.exports =
|
||||
class NotationalVelocityView extends SelectListView
|
||||
initialize: (state) ->
|
||||
@initializedAt = new Date()
|
||||
super
|
||||
@addClass('notational-velocity from-top overlay')
|
||||
@rootDirectory = atom.config.get('notational-velocity.directory')
|
||||
if !fs.existsSync(@rootDirectory)
|
||||
@addClass('nvatom from-top overlay')
|
||||
@rootDirectory = Utility.getNoteDirectory()
|
||||
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 +29,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 +90,10 @@ class NotationalVelocityView extends SelectListView
|
||||
@div class: 'secondary-line', "#{content}"
|
||||
|
||||
confirmSelection: ->
|
||||
item = @getSelectedItem()
|
||||
filePath = null
|
||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
||||
calculatedPath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
||||
item = @getSelectedItem()
|
||||
sanitizedQuery = Utility.trim(@getFilterQuery())
|
||||
calculatedPath = Utility.getNotePath(sanitizedQuery)
|
||||
filePath = null
|
||||
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
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
path = require 'path'
|
||||
fs = require 'fs-plus'
|
||||
{CompositeDisposable, Disposable} = require 'atom'
|
||||
Interlink = require './interlink'
|
||||
Utility = require './utility'
|
||||
|
||||
module.exports =
|
||||
config:
|
||||
@@ -8,20 +10,28 @@ module.exports =
|
||||
title: 'Note Directory'
|
||||
description: 'The directory to archive notes'
|
||||
type: 'string'
|
||||
default: process.env.ATOM_HOME + '/packages/notational-velocity/notebook'
|
||||
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
|
||||
|
||||
activate: (state) ->
|
||||
@rootDirectory = fs.realpathSync(atom.config.get('notational-velocity.directory'))
|
||||
@rootDirectory = @ensureNoteDirectory()
|
||||
|
||||
# Events subscribed to in atom's system can be easily cleaned up with a
|
||||
# CompositeDisposable
|
||||
@subscriptions = new CompositeDisposable
|
||||
|
||||
# Register command that toggles this view
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'notational-velocity:toggle': => @createView(state).toggle()
|
||||
'nvatom:toggle': => @createView(state).toggle()
|
||||
|
||||
handleBeforeUnload = @autosaveAll.bind(this)
|
||||
window.addEventListener('beforeunload', handleBeforeUnload, true)
|
||||
@@ -35,14 +45,17 @@ 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)
|
||||
|
||||
@interlink = new Interlink()
|
||||
|
||||
deactivate: ->
|
||||
@subscriptions.dispose()
|
||||
@notationalVelocityView.destroy()
|
||||
@interlnk?.destroy()
|
||||
@notationalVelocityView?.destroy()
|
||||
|
||||
serialize: ->
|
||||
notationalVelocityViewState: @notationalVelocityView.serialize()
|
||||
notationalVelocityViewState: @notationalVelocityView?.serialize()
|
||||
|
||||
createView: (state, docQuery) ->
|
||||
unless @notationalVelocityView?
|
||||
@@ -54,9 +67,61 @@ 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 Utility.isNote(uri)
|
||||
paneItem?.save?()
|
||||
|
||||
autodelete: (paneItem) ->
|
||||
return false unless paneItem?.getURI?()?
|
||||
uri = paneItem.getURI()
|
||||
return false unless Utility.isNote(uri)
|
||||
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 = 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.")
|
||||
|
||||
# Initialize note directory.
|
||||
unless fs.existsSync(noteDirectory)
|
||||
@tryMigrateFromNotationalVelocity()
|
||||
noteDirectory = atom.config.get('nvatom.directory')
|
||||
unless fs.existsSync(noteDirectory)
|
||||
fs.makeTreeSync(noteDirectory)
|
||||
fs.copySync(defaultNoteDirectory, noteDirectory)
|
||||
|
||||
return fs.realpathSync(noteDirectory)
|
||||
|
||||
tryMigrateFromNotationalVelocity: ->
|
||||
prevNoteDirectory = atom.config.get('notational-velocity.directory')
|
||||
currNoteDirectory = atom.config.get('nvatom.directory')
|
||||
packagesDirectory = path.join(process.env.ATOM_HOME, 'packages')
|
||||
defaultNoteDirectory = path.join(packagesDirectory, 'nvatom', 'notebook')
|
||||
|
||||
# notational-velocity does not exist.
|
||||
if prevNoteDirectory is undefined
|
||||
return
|
||||
|
||||
atom.notifications.addInfo('Migrating from notational-velocity package...')
|
||||
|
||||
unless fs.existsSync(prevNoteDirectory)
|
||||
atom.notifications.addError("notational-velocity.directory #{prevNoteDirectory} does not exists. Migration process is failed.")
|
||||
return
|
||||
|
||||
if prevNoteDirectory.startsWith(packagesDirectory)
|
||||
fs.makeTreeSync(currNoteDirectory)
|
||||
fs.copySync(prevNoteDirectory, currNoteDirectory)
|
||||
else
|
||||
if path.join(process.env.ATOM_HOME, 'nvatom-notes') == currNoteDirectory
|
||||
atom.config.set('nvatom.directory', prevNoteDirectory)
|
||||
|
||||
atom.notifications.addInfo('Finished migration.')
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
path = require 'path'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
module.exports =
|
||||
class Utility
|
||||
|
||||
@getNotePath: (title) -> path.join(Utility.getNoteDirectory(), Utility.trim(title) + Utility.getPrimaryNoteExtension())
|
||||
|
||||
@getNoteDirectory: -> fs.normalize(atom.config.get('nvatom.directory'))
|
||||
|
||||
@getPrimaryNoteExtension: -> if atom.config.get('nvatom.extensions').length then atom.config.get('nvatom.extensions')[0] else '.md'
|
||||
|
||||
@isNote: (filePath) ->
|
||||
return false unless path.extname(filePath) in atom.config.get('nvatom.extensions')
|
||||
|
||||
filePath = fs.normalize(filePath)
|
||||
return true if filePath.startsWith(Utility.getNoteDirectory())
|
||||
return true if filePath.startsWith(fs.realpathSync(Utility.getNoteDirectory()))
|
||||
return false unless fs.existsSync(filePath)
|
||||
|
||||
filePath = fs.realpathSync(filePath)
|
||||
return true if filePath.startsWith(Utility.getNoteDirectory())
|
||||
return true if filePath.startsWith(fs.realpathSync(Utility.getNoteDirectory()))
|
||||
return false
|
||||
|
||||
@trim: (str) -> str?.replace /^\s+|\s+$/g, ''
|
||||
@@ -3,11 +3,15 @@
|
||||
{
|
||||
'label': 'Packages'
|
||||
'submenu': [
|
||||
'label': 'Notational Velocity'
|
||||
'label': 'nvAtom'
|
||||
'submenu': [
|
||||
{
|
||||
'label': 'Toggle'
|
||||
'command': 'notational-velocity:toggle'
|
||||
'command': 'nvatom:toggle'
|
||||
}
|
||||
{
|
||||
'label': 'Open Interlink'
|
||||
'command': 'nvatom:openInterlink'
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
+15
-9
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "notational-velocity",
|
||||
"name": "nvatom",
|
||||
"main": "./lib/notational-velocity",
|
||||
"version": "0.2.0",
|
||||
"version": "0.9.1",
|
||||
"private": true,
|
||||
"contributors": [
|
||||
"Seongjae Lee <seongjae@gmail.com>",
|
||||
@@ -9,18 +9,22 @@
|
||||
"Jonathan Hoyt <hoyt@github.com>"
|
||||
],
|
||||
"description": "Notational Velocity for Atom",
|
||||
"activationCommands": {
|
||||
"atom-workspace": "notational-velocity:toggle"
|
||||
},
|
||||
"repository": "https://github.com/seongjaelee/notational-velocity",
|
||||
"keywords": [
|
||||
"wiki",
|
||||
"notational velocity",
|
||||
"nvatom",
|
||||
"note",
|
||||
"notetaking"
|
||||
],
|
||||
"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",
|
||||
@@ -28,5 +32,7 @@
|
||||
"fs-plus": "2.x",
|
||||
"underscore-plus": "^1.6.6"
|
||||
},
|
||||
"devDependencies": {}
|
||||
"devDependencies": {
|
||||
"temp": "0.8.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
Interlink = require '../lib/interlink'
|
||||
|
||||
temp.track()
|
||||
|
||||
describe 'Interlink', ->
|
||||
defaultDirectory = atom.config.get('nvatom.directory')
|
||||
noteDirectory = null
|
||||
|
||||
beforeEach ->
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
noteDirectory = temp.mkdirSync()
|
||||
|
||||
atom.config.set('nvatom.directory', noteDirectory)
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('nvatom')
|
||||
|
||||
afterEach ->
|
||||
atom.config.set('nvatom.directory', defaultDirectory)
|
||||
|
||||
describe 'when getInterlinkUnderCursor is called', ->
|
||||
editor = null
|
||||
|
||||
describe 'under the note directory', ->
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.workspace.open(path.join(noteDirectory, 'Interlink.md')).then (o) -> editor = o
|
||||
|
||||
it 'returns a trimmed interlink text', ->
|
||||
testdata = [
|
||||
{ position: [0, 2], text: '[[Car]]', expected: 'Car' },
|
||||
{ position: [0, 2], text: '[[Notational Velocity]]', expected: 'Notational Velocity' },
|
||||
{ position: [0, 2], text: '[[한글 Alphabet Test]]', expected: '한글 Alphabet Test' },
|
||||
{ position: [0, 2], text: '[[ Car ]]', expected: 'Car' },
|
||||
{ position: [0, 2], text: '[[Car/Mini]]', expected: 'Car/Mini' },
|
||||
]
|
||||
|
||||
for testitem in testdata
|
||||
editor.setText testitem.text
|
||||
editor.setCursorBufferPosition testitem.position
|
||||
expect(Interlink.getInterlinkUnderCursor(editor)).toBe testitem.expected
|
||||
|
||||
it 'returns undefined for invalid text', ->
|
||||
testdata = [
|
||||
{ position: [0, 2], text: '[[]]' },
|
||||
{ position: [0, 3], text: '[[]]' },
|
||||
{ position: [0, 2], text: '[[ ]]' },
|
||||
{ position: [0, 1], text: '[Car]' },
|
||||
{ position: [0, 2], text: '[[[Car]]]' },
|
||||
{ position: [0, 2], text: '[[Car]' },
|
||||
{ position: [0, 2], text: '[[Car]]]' },
|
||||
{ position: [0, 1], text: 'Car' },
|
||||
]
|
||||
|
||||
for testitem in testdata
|
||||
editor.setText testitem.text
|
||||
editor.setCursorBufferPosition testitem.position
|
||||
expect(Interlink.getInterlinkUnderCursor(editor)).toBe undefined
|
||||
|
||||
describe 'under a random directory', ->
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.workspace.open(path.join(temp.mkdirSync(), 'Interlink.md')).then (o) -> editor = o
|
||||
|
||||
it 'does not apply the grammar', ->
|
||||
editor.setText '[[Car]]'
|
||||
editor.setCursorBufferPosition [0, 2]
|
||||
expect(Interlink.getInterlinkUnderCursor(editor)).toBe undefined
|
||||
|
||||
describe 'when openInterlink is called', ->
|
||||
describe 'when the editor path is under the note directory', ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.workspace.open(path.join(noteDirectory, 'Interlink.md')).then (o) -> editor = o
|
||||
|
||||
it 'opens the referred notes', ->
|
||||
editor.setText '[[Car]]'
|
||||
editor.setCursorBufferPosition [0, 2]
|
||||
|
||||
editorPromise = Interlink.openInterlink()
|
||||
expect(editorPromise).not.toBe undefined
|
||||
waitsForPromise ->
|
||||
editorPromise
|
||||
|
||||
runs ->
|
||||
expect(atom.workspace.getActiveTextEditor().getPath().endsWith('Car.md')).toBe true
|
||||
|
||||
describe 'when the editor path is not under the note directory', ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.workspace.open(path.join(temp.mkdirSync(), 'Interlink.md')).then (o) -> editor = o
|
||||
|
||||
it 'does nothing', ->
|
||||
editor.setText '[[Car]]'
|
||||
editor.setCursorBufferPosition [0, 2]
|
||||
|
||||
editorPromise = Interlink.openInterlink()
|
||||
expect(editorPromise).toBe undefined
|
||||
@@ -1,32 +1,49 @@
|
||||
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
||||
#
|
||||
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
|
||||
# or `fdescribe`). Remove the `f` to unfocus the block.
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
|
||||
describe "NotationalVelocity", ->
|
||||
defaultDirectory = atom.config.get('notational-velocity.directory')
|
||||
temp.track()
|
||||
|
||||
describe "nvAtom", ->
|
||||
defaultDirectory = atom.config.get('nvatom.directory')
|
||||
activationPromise = null
|
||||
workspaceElement = null
|
||||
|
||||
beforeEach ->
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
activationPromise = atom.packages.activatePackage('notational-velocity')
|
||||
atom.config.set('notational-velocity.directory', 'testdata')
|
||||
|
||||
afterEach ->
|
||||
atom.config.set('notational-velocity.directory', defaultDirectory)
|
||||
atom.config.set('nvatom.directory', defaultDirectory)
|
||||
|
||||
describe "when the notational-velocity:toggle event is triggered", ->
|
||||
describe "when the nvatom:toggle event is triggered", ->
|
||||
it "attaches and then detaches the view", ->
|
||||
expect(workspaceElement.querySelector('.notational-velocity')).not.toExist()
|
||||
|
||||
# This is an activation event, triggering it will cause the package to be
|
||||
# activated.
|
||||
atom.commands.dispatch workspaceElement, 'notational-velocity:toggle'
|
||||
|
||||
noteDirectory = path.join(temp.mkdirSync())
|
||||
atom.config.set('nvatom.directory', noteDirectory)
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
atom.packages.activatePackage('nvatom')
|
||||
|
||||
runs ->
|
||||
expect(workspaceElement.querySelector('.notational-velocity')).toExist()
|
||||
atom.commands.dispatch workspaceElement, 'notational-velocity:toggle'
|
||||
expect(workspaceElement.querySelector('.nvatom')).not.toExist()
|
||||
|
||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
||||
expect(workspaceElement.querySelector('.nvatom')).toExist()
|
||||
expect(workspaceElement.querySelector('.nvatom').parentNode.style.display).not.toBe 'none'
|
||||
|
||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
||||
expect(workspaceElement.querySelector('.nvatom').parentNode.style.display).toBe 'none'
|
||||
|
||||
it "checks if we banned the default directory under packages directory", ->
|
||||
noteDirectory = path.join(process.env.ATOM_HOME, 'packages', 'nvatom', 'notebook')
|
||||
atom.config.set('nvatom.directory', noteDirectory)
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('nvatom')
|
||||
|
||||
runs ->
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('notifications')
|
||||
|
||||
runs ->
|
||||
notificationContainer = workspaceElement.querySelector('atom-notifications')
|
||||
notification = notificationContainer.querySelector('atom-notification.fatal')
|
||||
expect(notification).toExist()
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
Utility = require '../lib/utility'
|
||||
|
||||
temp.track()
|
||||
|
||||
describe "utility", ->
|
||||
defaultNoteDirectory = atom.config.get('nvatom.directory')
|
||||
defaultNoteExtensions = atom.config.get('nvatom.extensions')
|
||||
|
||||
afterEach ->
|
||||
atom.config.set('nvatom.directory', defaultDirectory)
|
||||
atom.config.set('nvatom.extensions', defaultNoteExtensions)
|
||||
|
||||
describe 'trim', ->
|
||||
expect(Utility.trim(null)).toBe(undefined)
|
||||
expect(Utility.trim(undefined)).toBe(undefined)
|
||||
expect(Utility.trim('')).toBe('')
|
||||
expect(Utility.trim(' ')).toBe('')
|
||||
expect(Utility.trim(' hello world ')).toBe('hello world')
|
||||
expect(Utility.trim(' hello world\t\n\r ')).toBe('hello world')
|
||||
|
||||
describe 'getPrimaryNoteExtension', ->
|
||||
atom.config.set('nvatom.extensions', ['.md', '.markdown'])
|
||||
expect(Utility.getPrimaryNoteExtension()).toBe('.md')
|
||||
atom.config.set('nvatom.extensions', ['.markdown'])
|
||||
expect(Utility.getPrimaryNoteExtension()).toBe('.markdown')
|
||||
atom.config.set('nvatom.extensions', [])
|
||||
expect(Utility.getPrimaryNoteExtension()).toBe('.md')
|
||||
|
||||
describe 'isNote handles symlinks correctly', ->
|
||||
atom.config.set('nvatom.extensions', ['.md', '.markdown'])
|
||||
|
||||
tempDirectoryPath = path.join(temp.mkdirSync())
|
||||
noteDirectoryPath = path.join(temp.mkdirSync())
|
||||
noteDirectoryPathSymlink = path.join(tempDirectoryPath, 'note book')
|
||||
notePath = path.join(noteDirectoryPath, 'note.md')
|
||||
notePathSymlink = path.join(noteDirectoryPathSymlink, 'note symlink.md')
|
||||
|
||||
fs.writeFileSync(notePath, 'dummy')
|
||||
fs.symlinkSync(noteDirectoryPath, noteDirectoryPathSymlink)
|
||||
fs.symlinkSync(notePath, notePathSymlink)
|
||||
|
||||
expect(fs.existsSync(notePath)).toBe(true)
|
||||
expect(fs.existsSync(fs.normalize(notePath))).toBe(true)
|
||||
|
||||
atom.config.set('nvatom.directory', noteDirectoryPath)
|
||||
expect(Utility.isNote(notePath)).toBe(true)
|
||||
expect(Utility.isNote(notePathSymlink)).toBe(true)
|
||||
|
||||
atom.config.set('nvatom.directory', noteDirectoryPathSymlink)
|
||||
expect(Utility.isNote(notePath)).toBe(true)
|
||||
expect(Utility.isNote(notePathSymlink)).toBe(true)
|
||||
@@ -4,7 +4,7 @@
|
||||
// for a full listing of what's available.
|
||||
@import "ui-variables";
|
||||
|
||||
.notational-velocity {
|
||||
.nvatom {
|
||||
li {
|
||||
text-overflow: ellipsis;
|
||||
overflow-x: hidden;
|
||||
|
||||
Reference in New Issue
Block a user