mirror of
https://github.com/wassname/nvatom.git
synced 2026-09-10 12:21:11 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f005a3025 | ||
|
|
2cbf6a63d7 | ||
|
|
3c36f51fe6 | ||
|
|
956c0017e4 | ||
|
|
0dd99d805b | ||
|
|
aa641ba695 | ||
|
|
6a7e04d177 | ||
|
|
5aab86660f | ||
|
|
6ec1c4c2e8 | ||
|
|
f582f741ad | ||
|
|
6fe704aad1 | ||
|
|
669839750c | ||
|
|
452c34ba36 | ||
|
|
ee5dc2a87a | ||
|
|
bd7d47474c | ||
|
|
424f2a13d6 | ||
|
|
04b7df8676 | ||
|
|
2d2a070d1e | ||
|
|
6ae37437be | ||
|
|
51f769a017 | ||
|
|
ca7c14e3b7 | ||
|
|
c5eca919ed | ||
|
|
9244b0a0b9 | ||
|
|
323fb29e56 | ||
|
|
6c55f58774 | ||
|
|
9c5c4e43da | ||
|
|
cc8a780436 | ||
|
|
431b929208 | ||
|
|
61d071c15a | ||
|
|
4e4688fe78 | ||
|
|
0fffc6a6b1 | ||
|
|
547617f485 | ||
|
|
74735eec82 | ||
|
|
fa873af344 | ||
|
|
a31f490a70 | ||
|
|
27f2a5bb8d |
@@ -1,3 +1,13 @@
|
|||||||
|
## 0.11.0
|
||||||
|
- Make autosave a selectable feature
|
||||||
|
- Fix the bug that shows an error message on save when whitespace package is disabled
|
||||||
|
|
||||||
|
## 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
|
## 0.7.0
|
||||||
- Add `extensions` setting
|
- Add `extensions` setting
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ This Atom package implements the some key features from this amazing app:
|
|||||||
- Modeless operation
|
- Modeless operation
|
||||||
- Mouseless interaction
|
- Mouseless interaction
|
||||||
- Incremental Search
|
- Incremental Search
|
||||||
|
- Interlinks
|
||||||
|
|
||||||
Integrated with Atom, we have several advantages:
|
Integrated with Atom, we have several advantages:
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ Double-quotes also work.
|
|||||||
## Key Bindings
|
## Key Bindings
|
||||||
|
|
||||||
- `alt-cmd-l`: Toggles the search view.
|
- `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:
|
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:
|
||||||
|
|
||||||
@@ -57,6 +59,15 @@ You can also override `cmd-l` if you want to keep your muscle memory from Notati
|
|||||||
'cmd-l': 'nvatom:toggle'
|
'cmd-l': 'nvatom:toggle'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To set Windows and Linux key binds you can add the following lines to your keymap:
|
||||||
|
|
||||||
|
```cson
|
||||||
|
'atom-workspace':
|
||||||
|
'alt-ctrl-l': 'nvatom:toggle'
|
||||||
|
'atom-workspace atom-text-editor':
|
||||||
|
'alt-ctrl-o': 'nvatom:openInterlink'
|
||||||
|
```
|
||||||
|
|
||||||
## Migration
|
## 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].
|
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].
|
||||||
|
|||||||
@@ -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'
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -9,3 +9,5 @@
|
|||||||
# https://atom.io/docs/latest/advanced/keymaps
|
# https://atom.io/docs/latest/advanced/keymaps
|
||||||
'atom-workspace':
|
'atom-workspace':
|
||||||
'alt-cmd-l': 'nvatom: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
|
||||||
@@ -3,15 +3,16 @@ fs = require 'fs-plus'
|
|||||||
_ = require 'underscore-plus'
|
_ = require 'underscore-plus'
|
||||||
{$, $$, SelectListView} = require 'atom-space-pen-views'
|
{$, $$, SelectListView} = require 'atom-space-pen-views'
|
||||||
DocQuery = require 'docquery'
|
DocQuery = require 'docquery'
|
||||||
|
Utility = require './utility'
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
class NotationalVelocityView extends SelectListView
|
class NotationalVelocityView extends SelectListView
|
||||||
initialize: (state) ->
|
initialize: (state) ->
|
||||||
@initializedAt = new Date()
|
@initializedAt = new Date()
|
||||||
super
|
super
|
||||||
@addClass('nvatom from-top overlay')
|
@addClass('nvatom')
|
||||||
@rootDirectory = atom.config.get('nvatom.directory')
|
@rootDirectory = Utility.getNoteDirectory()
|
||||||
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
|
||||||
@@ -28,7 +29,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: ->
|
||||||
@@ -42,14 +43,14 @@ class NotationalVelocityView extends SelectListView
|
|||||||
isCursorProceeded = @isCursorProceeded()
|
isCursorProceeded = @isCursorProceeded()
|
||||||
|
|
||||||
for item in filteredItems
|
for item in filteredItems
|
||||||
if item.title.match(///^#{filterQuery}$///i) != null
|
if item.title.toLowerCase() is filterQuery.toLowerCase()
|
||||||
# autoselect
|
# autoselect
|
||||||
n = filteredItems.indexOf(item) + 1
|
n = filteredItems.indexOf(item) + 1
|
||||||
@selectItemView(@list.find("li:nth-child(#{n})"))
|
@selectItemView(@list.find("li:nth-child(#{n})"))
|
||||||
return
|
return
|
||||||
|
|
||||||
for item in filteredItems
|
for item in filteredItems
|
||||||
if item.title.match(///^#{filterQuery}///i) != null && isCursorProceeded
|
if item.title.toLowerCase().startsWith(filterQuery.toLowerCase()) and isCursorProceeded
|
||||||
# autocomplete
|
# autocomplete
|
||||||
@skipPopulateList = true
|
@skipPopulateList = true
|
||||||
editor = @filterEditorView.model
|
editor = @filterEditorView.model
|
||||||
@@ -61,7 +62,7 @@ class NotationalVelocityView extends SelectListView
|
|||||||
@selectItemView(@list.find("li:nth-child(#{n})"))
|
@selectItemView(@list.find("li:nth-child(#{n})"))
|
||||||
|
|
||||||
filter: (filterQuery) ->
|
filter: (filterQuery) ->
|
||||||
if filterQuery == "" || filterQuery == undefined
|
if (filterQuery is "") or (filterQuery is undefined)
|
||||||
return @docQuery.documents
|
return @docQuery.documents
|
||||||
return @docQuery.search(filterQuery)
|
return @docQuery.search(filterQuery)
|
||||||
|
|
||||||
@@ -90,10 +91,9 @@ class NotationalVelocityView extends SelectListView
|
|||||||
|
|
||||||
confirmSelection: ->
|
confirmSelection: ->
|
||||||
item = @getSelectedItem()
|
item = @getSelectedItem()
|
||||||
|
sanitizedQuery = Utility.trim(@getFilterQuery())
|
||||||
|
calculatedPath = Utility.getNotePath(sanitizedQuery)
|
||||||
filePath = null
|
filePath = null
|
||||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
|
||||||
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)
|
||||||
@@ -105,9 +105,12 @@ class NotationalVelocityView extends SelectListView
|
|||||||
if filePath
|
if filePath
|
||||||
atom.workspace.open(filePath).then (editor) ->
|
atom.workspace.open(filePath).then (editor) ->
|
||||||
save = ->
|
save = ->
|
||||||
atom.packages.deactivatePackage 'whitespace'
|
isWhiteSpaceActive = atom.packages.isPackageActive 'whitespace'
|
||||||
|
if isWhiteSpaceActive
|
||||||
|
atom.packages.deactivatePackage 'whitespace'
|
||||||
editor.save()
|
editor.save()
|
||||||
atom.packages.activatePackage 'whitespace'
|
if isWhiteSpaceActive
|
||||||
|
atom.packages.activatePackage 'whitespace'
|
||||||
debouncedSave = _.debounce save, 1000
|
debouncedSave = _.debounce save, 1000
|
||||||
editor.onDidStopChanging () ->
|
editor.onDidStopChanging () ->
|
||||||
debouncedSave() if editor.isModified()
|
debouncedSave() if editor.isModified()
|
||||||
@@ -156,6 +159,6 @@ class NotationalVelocityView extends SelectListView
|
|||||||
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
||||||
|
|
||||||
schedulePopulateList: ->
|
schedulePopulateList: ->
|
||||||
if !@skipPopulateList
|
unless @skipPopulateList
|
||||||
super
|
super
|
||||||
@skipPopulateList = false
|
@skipPopulateList = false
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
path = require 'path'
|
path = require 'path'
|
||||||
fs = require 'fs-plus'
|
fs = require 'fs-plus'
|
||||||
{CompositeDisposable, Disposable} = require 'atom'
|
{CompositeDisposable, Disposable} = require 'atom'
|
||||||
|
Interlink = require './interlink'
|
||||||
|
Utility = require './utility'
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
config:
|
config:
|
||||||
@@ -21,17 +23,17 @@ module.exports =
|
|||||||
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".'
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
default: true
|
default: true
|
||||||
|
enableAutosave:
|
||||||
notationalVelocityView: null
|
title: 'Enable Autosave'
|
||||||
|
description: 'Enable saving the document automatically whenever the user leaves the window or change the tab.'
|
||||||
|
type: 'boolean'
|
||||||
|
default: true
|
||||||
|
|
||||||
activate: (state) ->
|
activate: (state) ->
|
||||||
@rootDirectory = @ensureNoteDirectory()
|
@rootDirectory = @ensureNoteDirectory()
|
||||||
|
|
||||||
# Events subscribed to in atom's system can be easily cleaned up with a
|
|
||||||
# CompositeDisposable
|
|
||||||
@subscriptions = new CompositeDisposable
|
@subscriptions = new CompositeDisposable
|
||||||
|
|
||||||
# Register command that toggles this view
|
|
||||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||||
'nvatom:toggle': => @createView(state).toggle()
|
'nvatom:toggle': => @createView(state).toggle()
|
||||||
|
|
||||||
@@ -47,14 +49,17 @@ 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)
|
||||||
|
|
||||||
|
@interlink = new Interlink()
|
||||||
|
|
||||||
deactivate: ->
|
deactivate: ->
|
||||||
@subscriptions.dispose()
|
@subscriptions.dispose()
|
||||||
@notationalVelocityView.destroy()
|
@interlnk?.destroy()
|
||||||
|
@notationalVelocityView?.destroy()
|
||||||
|
|
||||||
serialize: ->
|
serialize: ->
|
||||||
notationalVelocityViewState: @notationalVelocityView.serialize()
|
notationalVelocityViewState: @notationalVelocityView?.serialize()
|
||||||
|
|
||||||
createView: (state, docQuery) ->
|
createView: (state, docQuery) ->
|
||||||
unless @notationalVelocityView?
|
unless @notationalVelocityView?
|
||||||
@@ -63,29 +68,40 @@ module.exports =
|
|||||||
@notationalVelocityView
|
@notationalVelocityView
|
||||||
|
|
||||||
autosave: (paneItem) ->
|
autosave: (paneItem) ->
|
||||||
|
return unless atom.config.get('nvatom.enableAutosave')
|
||||||
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 Utility.isNote(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 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: ->
|
autosaveAll: ->
|
||||||
|
return unless atom.config.get('nvatom.enableAutosave')
|
||||||
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
||||||
|
|
||||||
ensureNoteDirectory: ->
|
ensureNoteDirectory: ->
|
||||||
noteDirectory = atom.config.get('nvatom.directory')
|
noteDirectory = fs.normalize(atom.config.get('nvatom.directory'))
|
||||||
packagesDirectory = path.join(process.env.ATOM_HOME, 'packages')
|
packagesDirectory = path.join(process.env.ATOM_HOME, 'packages')
|
||||||
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)
|
||||||
|
|
||||||
@@ -98,13 +114,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)
|
||||||
|
|||||||
@@ -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, ''
|
||||||
@@ -9,6 +9,10 @@
|
|||||||
'label': 'Toggle'
|
'label': 'Toggle'
|
||||||
'command': 'nvatom:toggle'
|
'command': 'nvatom:toggle'
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
'label': 'Open Interlink'
|
||||||
|
'command': 'nvatom:openInterlink'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-6
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nvatom",
|
"name": "nvatom",
|
||||||
"main": "./lib/notational-velocity",
|
"main": "./lib/notational-velocity",
|
||||||
"version": "0.7.1",
|
"version": "0.11.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Seongjae Lee <seongjae@gmail.com>",
|
"Seongjae Lee <seongjae@gmail.com>",
|
||||||
@@ -9,9 +9,13 @@
|
|||||||
"Jonathan Hoyt <hoyt@github.com>"
|
"Jonathan Hoyt <hoyt@github.com>"
|
||||||
],
|
],
|
||||||
"description": "Notational Velocity for Atom",
|
"description": "Notational Velocity for Atom",
|
||||||
"activationCommands": {
|
"keywords": [
|
||||||
"atom-workspace": "nvatom:toggle"
|
"wiki",
|
||||||
},
|
"notational velocity",
|
||||||
|
"nvatom",
|
||||||
|
"note",
|
||||||
|
"notetaking"
|
||||||
|
],
|
||||||
"repository": "https://github.com/seongjaelee/nvatom",
|
"repository": "https://github.com/seongjaelee/nvatom",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -24,9 +28,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"atom-space-pen-views": "^2.0.3",
|
"atom-space-pen-views": "^2.0.3",
|
||||||
"chokidar": "^1.0.5",
|
"chokidar": "^1.0.5",
|
||||||
"docquery": "^1.1.0",
|
"docquery": "^1.1.1",
|
||||||
"fs-plus": "2.x",
|
"fs-plus": "2.x",
|
||||||
"underscore-plus": "^1.6.6"
|
"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,4 +1,7 @@
|
|||||||
path = require 'path'
|
path = require 'path'
|
||||||
|
temp = require 'temp'
|
||||||
|
|
||||||
|
temp.track()
|
||||||
|
|
||||||
describe "nvAtom", ->
|
describe "nvAtom", ->
|
||||||
defaultDirectory = atom.config.get('nvatom.directory')
|
defaultDirectory = atom.config.get('nvatom.directory')
|
||||||
@@ -7,41 +10,38 @@ describe "nvAtom", ->
|
|||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
workspaceElement = atom.views.getView(atom.workspace)
|
workspaceElement = atom.views.getView(atom.workspace)
|
||||||
activationPromise = atom.packages.activatePackage('nvatom')
|
|
||||||
atom.config.set('nvatom.directory', 'testdata')
|
|
||||||
|
|
||||||
afterEach ->
|
afterEach ->
|
||||||
atom.config.set('nvatom.directory', defaultDirectory)
|
atom.config.set('nvatom.directory', defaultDirectory)
|
||||||
|
|
||||||
describe "when the nvatom:toggle event is triggered", ->
|
describe "when the nvatom:toggle event is triggered", ->
|
||||||
it "attaches and then detaches the view", ->
|
it "attaches and then detaches the view", ->
|
||||||
expect(workspaceElement.querySelector('.nvatom')).not.toExist()
|
noteDirectory = path.join(temp.mkdirSync())
|
||||||
|
atom.config.set('nvatom.directory', noteDirectory)
|
||||||
# This is an activation event, triggering it will cause the package to be activated.
|
|
||||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
|
||||||
|
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
activationPromise
|
atom.packages.activatePackage('nvatom')
|
||||||
|
|
||||||
runs ->
|
runs ->
|
||||||
expect(workspaceElement.querySelector('.nvatom')).toExist()
|
expect(workspaceElement.querySelector('.nvatom')).not.toExist()
|
||||||
|
|
||||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
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", ->
|
it "checks if we banned the default directory under packages directory", ->
|
||||||
atom.notifications.clear()
|
noteDirectory = path.join(process.env.ATOM_HOME, 'packages', 'nvatom', 'notebook')
|
||||||
|
atom.config.set('nvatom.directory', noteDirectory)
|
||||||
|
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
atom.packages.activatePackage('notifications')
|
atom.packages.activatePackage('nvatom')
|
||||||
|
|
||||||
runs ->
|
runs ->
|
||||||
noteDirectoryUnderPackageDirectory = path.join(process.env.ATOM_HOME, 'packages', 'nvatom', 'notebook')
|
|
||||||
atom.config.set('nvatom.directory', noteDirectoryUnderPackageDirectory)
|
|
||||||
|
|
||||||
# This is an activation event, triggering it will cause the package to be activated.
|
|
||||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
|
||||||
|
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
activationPromise
|
atom.packages.activatePackage('notifications')
|
||||||
|
|
||||||
runs ->
|
runs ->
|
||||||
notificationContainer = workspaceElement.querySelector('atom-notifications')
|
notificationContainer = workspaceElement.querySelector('atom-notifications')
|
||||||
|
|||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user