86 Commits
Author SHA1 Message Date
Seongjae Lee 1f005a3025 Prepare 0.11.0 release 2016-06-23 22:43:51 -07:00
Seongjae Lee 2cbf6a63d7 Update changelog 2016-06-23 22:43:25 -07:00
Seongjae Lee 3c36f51fe6 Add an option to enable/disable autosave, resolving #50
It would be more efficient if we can subscribe/unsubscribe autosave whenver this parameter is changed, but I don't think the current implementation would be that expansive.
2016-06-23 22:38:00 -07:00
Seongjae Lee 956c0017e4 Prepare 0.10.1 release 2016-06-23 19:09:31 -07:00
Seongjae Lee 0dd99d805b Fix #52 to prevent spitting an error message when whitespace package is not active 2016-06-23 19:07:40 -07:00
Seongjae Lee aa641ba695 Prepare 0.10.0 release 2016-04-25 18:47:08 -07:00
Seongjae Lee 6a7e04d177 Merge pull request #48 from jonmagic/patch-1
Update docquery to 1.1.1
2016-04-25 18:43:03 -07:00
Jonathan Hoyt 5aab86660f Update docquery to 1.1.1 2016-04-24 21:49:26 -07:00
Seongjae Lee 6ec1c4c2e8 Prepare 0.9.3 release 2015-10-17 00:14:44 -07:00
Seongjae Lee f582f741ad Merge pull request #38 from xHN35RQ/master
Add Windows/Linux keymap note
2015-10-17 00:14:13 -07:00
Seongjae Lee 6fe704aad1 Prepare 0.9.2 release 2015-10-16 23:49:32 -07:00
Seongjae Lee 669839750c Fix the double padding problem in the search window 2015-10-16 23:49:20 -07:00
Nic 452c34ba36 Add Windows/Linux keymap note 2015-10-16 23:03:11 -07:00
Seongjae Lee ee5dc2a87a Prepare 0.9.1 release 2015-10-16 22:33:32 -07:00
Seongjae Lee bd7d47474c Add interlink menu item 2015-10-16 22:33:11 -07:00
Seongjae Lee 424f2a13d6 Prepare 0.9.0 release 2015-10-16 22:17:43 -07:00
Seongjae Lee 04b7df8676 Update changelog 2015-10-16 22:16:23 -07:00
Seongjae Lee 2d2a070d1e Fix a bug that utility.isNote does not handle symlinks properly 2015-10-07 07:55:36 -07:00
Seongjae Lee 6ae37437be Load nvatom grammar on atom 2015-09-28 21:42:23 -07:00
Seongjae Lee 51f769a017 Apply the interlink extended grammar only on valid notes
To do so, we need to activate the package on Atom startup.
2015-09-28 01:14:39 -07:00
Seongjae Lee ca7c14e3b7 Rename notelink to interlink 2015-09-27 10:45:51 -07:00
Seongjae Lee c5eca919ed Add tests for notelinks 2015-09-27 10:39:03 -07:00
Seongjae Lee 9244b0a0b9 Update readme for interlinks 2015-09-26 10:34:02 -07:00
Seongjae Lee 323fb29e56 Add tests for utility class 2015-09-26 10:27:46 -07:00
Seongjae Lee 6c55f58774 Fix uncaught reference error for not including utility 2015-09-26 07:52:03 -07:00
Seongjae Lee 9c5c4e43da Add interlink highlight and jump features 2015-09-26 00:16:36 -07:00
Seongjae Lee cc8a780436 Prepare 0.8.2 release 2015-09-24 21:25:23 -07:00
Seongjae Lee 431b929208 Merge pull request #33 from lexicalunit/normalize_directory
Normalize nvatom.directory so that ~/... works correctly.
2015-09-24 21:22:32 -07:00
lexicalunit 61d071c15a Normalize nvatom.directory so that ~/... works correctly. 2015-09-24 18:36:59 -05:00
Seongjae Lee 4e4688fe78 Prepare 0.8.1 release 2015-09-16 19:56:14 -07:00
Seongjae Lee 0fffc6a6b1 Avoid using regexp for searching title
Fixes #28.
2015-09-16 19:56:00 -07:00
Seongjae Lee 547617f485 Refactor code based on CoffeeScript style guide
https://github.com/polarmobile/coffeescript-style-guide
2015-09-12 12:14:56 -07:00
Seongjae Lee 74735eec82 Prepare 0.8.0 release 2015-09-12 10:52:12 -07:00
Seongjae Lee fa873af344 Update changelog 2015-09-12 10:51:48 -07:00
Seongjae Lee a31f490a70 Fix a bug on warning messages
Ruby-style string interpolation is only with double-quoted strings.
2015-09-12 10:49:44 -07:00
Seongjae Lee 27f2a5bb8d Delete an empty note when closing a pane
Close #18. This is against nvALT, but I think this is more intuitive way.
2015-09-12 10:47:29 -07:00
Seongjae Lee 95093df286 Prepare 0.7.1 release 2015-09-12 10:17:10 -07:00
Seongjae Lee 5e4345f719 Make autosave also consider nvatom.extensions 2015-09-12 10:16:52 -07:00
Seongjae Lee cee47a8fd7 Prepare 0.7.0 release 2015-09-12 02:02:59 -07:00
Seongjae Lee 15bf1e741b Update changelog 2015-09-12 02:02:43 -07:00
Seongjae Lee bd19c270b3 Support other extensions than ".md"
Close #13.
2015-09-12 01:58:59 -07:00
Seongjae Lee b5f7ba7b75 Prepare 0.6.0 release 2015-09-12 01:36:40 -07:00
Seongjae Lee da888fa461 Prepare to move git repository from notational-velocity to nvatom 2015-09-12 01:36:12 -07:00
Seongjae Lee 97830b31db Prepare to move git repository from notational-velocity to nvatom 2015-09-12 01:33:38 -07:00
Seongjae Lee a06e0127c2 Prepare 0.5.1 release 2015-09-12 01:15:24 -07:00
Seongjae Lee cfd9dcef85 Fix typo on readme 2015-09-12 01:15:09 -07:00
Seongjae Lee ca6f9e76a3 Prepare 0.5.0 release 2015-09-12 01:08:24 -07:00
Seongjae Lee 5e44098ae3 Update changelog 2015-09-12 01:08:19 -07:00
Seongjae Lee a3f5d445c0 Make lunr pipeline feature optionable
If we have a note "Atom", and if the user types "a" or "at", then lunr pipeline ignores searching them because they are stop words. However, turning off this feature might not be a good idea when we have tons of body texts. So we turn it on as a default, but provide a way to turn it off as an option.
2015-09-12 01:04:11 -07:00
Seongjae Lee abb7339a6e Improve autoselect/autocomplete logic
Say we have two notes "Mark" and "Markdown". When the user type "Markd", then it will autocomplete to "Markd[own]". Say the user presses backspace key twice to make it to "Mark". In this case, we want to autoselect "Mark".
2015-09-12 00:54:56 -07:00
Seongjae Lee 4ddc133920 Refactor schedulePopulateList 2015-09-12 00:42:11 -07:00
Seongjae Lee bca1646f8f Refactor filter 2015-09-12 00:40:21 -07:00
Seongjae Lee 40e785ef57 Remove unnessary whitespaces
Refer https://github.com/polarmobile/coffeescript-style-guide#whitespace-in-expressions-and-statements.
2015-09-11 22:51:03 -07:00
Seongjae Lee 273d506f38 Make the searching query to be the non-selected text, not the full text
For example, if we have two notes "Car" and "Care", when we type "Ca", then it automatically fills "Care" and drops "Car". (Assume "Care" comes ahead of "Car"). However, we still want to search with "Ca".
2015-09-11 22:46:06 -07:00
Seongjae Lee 09d0efc06f Make the first found item to be automatically selected
This is a regression caused by docquery integration (56821bccbc). indexof always returns -1. Since the selected item is always the first filtered item, we can safely set it to 1.
2015-09-11 22:43:09 -07:00
Seongjae Lee 4dd0b518aa Prepare 0.4.2 release 2015-09-11 14:08:59 -07:00
Seongjae Lee bdf384f158 Fix #26 causing DocQuery loading error on case sensitive OS 2015-09-11 14:05:57 -07:00
Seongjae Lee c2db598f17 Prepare 0.4.1 release 2015-09-10 23:56:57 -07:00
Seongjae Lee 1e1aa06e3c Remove debug code 2015-09-10 23:56:17 -07:00
Seongjae Lee 8384b81a04 Prepare 0.4.0 release 2015-09-10 23:26:09 -07:00
Seongjae Lee ef3fb73c88 Make the first version of nvatom to be 0.4.0 2015-09-10 23:26:03 -07:00
Seongjae Lee 6c9752ae25 Rename notational-velocity to nvatom, copy notational-velocity settings/notes on initialization 2015-09-10 22:10:34 -07:00
Seongjae Lee bb80f5e203 Prepare 0.3.0 release 2015-09-10 00:35:11 -07:00
Seongjae Lee 5f26638a78 Fix #25 so that it ensures the note directory does not nest within the package directory 2015-09-10 00:32:22 -07:00
Seongjae Lee 52937e2f3c Prepare 0.2.0 release 2015-09-08 23:22:13 -07:00
Seongjae Lee 55631b89ea Update changelog and contributors 2015-09-08 23:20:28 -07:00
Seongjae Lee 7ae6d1c211 Fix the incompatible native module test failure 2015-09-08 22:56:57 -07:00
Seongjae Lee 56821bccbc First attempt with DocQuery 2015-08-30 21:52:20 -07:00
Seong Jae Lee 11a6c37c70 Revert to 03654ac, since the current one gives an error on OSX 2015-08-28 23:41:41 -04:00
Seongjae Lee ae435d7043 Merge pull request #24 from jonmagic/powered-by-docquery
First attempt with DocQuery
2015-08-28 23:18:36 -04:00
Seongjae Lee 03654ac2c6 Merge pull request #16 from garthk/fix-settings-documentation
Fix settings documentation
2015-05-28 12:11:36 -07:00
Garth Kidd 91f4bca077 Extract indentation advice to subsequent paragraph. 2015-05-27 16:28:38 +10:00
Garth Kidd e39334f9fa "via" is somewhat quaint. 2015-05-27 16:21:01 +10:00
Garth Kidd d8e60f9cfc Assert CSON format. 2015-05-27 16:18:29 +10:00
Garth Kidd 95a793f050 Fix settings docs: seongjaelee/notational-velocity#15 2015-05-27 15:31:17 +10:00
Jonathan Hoyt c15e7e0f96 First attempt with DocQuery 2015-05-24 23:09:50 -07:00
Seongjae Lee 3679cf0a71 Fix #14 so that it can create lowercase/uppercase notes as the user wants 2015-05-16 22:49:55 -07:00
Seongjae Lee 6207b379eb Avoid the user of WorkspaceView in tests 2015-05-09 15:41:16 -07:00
Seongjae Lee 66e03ce0e3 Fix a failing test due to a missing dependency 2015-05-09 15:11:16 -07:00
Seongjae Lee f19c613204 Merge pull request #11 from jonmagic/alternate-keybinding-instructions
Add instructions for changing the cmd-l keybinding
2015-05-09 15:02:57 -07:00
Seongjae Lee 42eb70ac27 Merge pull request #10 from jonmagic/auto-save-on-did-stop-changing
Auto save document 1 second after finishing typing
2015-05-09 15:02:46 -07:00
Jonathan Hoyt a2b81ad570 Add instructions for changing the cmd-l keybinding 2015-05-09 14:47:13 -07:00
Jonathan Hoyt 1f91f4d6b5 Remove console.log 2015-05-09 14:34:49 -07:00
Jonathan Hoyt 0f269c9216 Debounce the save so the editor doesn't slow down 2015-05-09 14:27:21 -07:00
Jonathan Hoyt e94430630c Save in editor.onDidStopChanging
Temporarily disables whitespace package so that you can create
newlines without getting them removed on autosave.
2015-05-09 13:49:47 -07:00
Seongjae Lee 49c081ed6e Introduce autosave feature
Fix #8.
2015-04-27 22:24:43 -07:00
19 changed files with 597 additions and 381 deletions
+29
View File
@@ -1,2 +1,31 @@
## 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
- 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
## 0.1.0 ## 0.1.0
- First release - First release
+48 -3
View File
@@ -1,5 +1,7 @@
# Notational Velocity for Atom # 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] [![Build Status][3]][4]
[Notational Velocity][1] is an application that stores and retrieves notes. [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 - 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:
@@ -26,11 +29,52 @@ We do believe Notational Velocity is the precursor of the famous note-taking app
## Settings ## Settings
- `Note Directory`: The directory to archive notes. 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
'nvatom':
directory: '/path/to/your/notes'
```
The first line should be indented by one step from `*` at the top. If you've
kept the default indentation of two spaces, the block above should paste in
properly.
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:
```cson
'atom-text-editor':
'cmd-l': 'unset!'
'atom-workspace':
'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
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 ## References
@@ -43,6 +87,7 @@ We do believe Notational Velocity is the precursor of the famous note-taking app
[1]: http://notational.net/ [1]: http://notational.net/
[2]: http://daringfireball.net/projects/markdown/syntax [2]: http://daringfireball.net/projects/markdown/syntax
[3]: https://travis-ci.org/seongjaelee/notational-velocity.svg?branch=master [3]: https://travis-ci.org/seongjaelee/nvatom.svg?branch=master
[4]: https://travis-ci.org/seongjaelee/notational-velocity [4]: https://travis-ci.org/seongjaelee/nvatom
[5]: https://cloud.githubusercontent.com/assets/948301/7246990/2e2b4c6e-e7b9-11e4-93b0-57954e011e81.gif [5]: https://cloud.githubusercontent.com/assets/948301/7246990/2e2b4c6e-e7b9-11e4-93b0-57954e011e81.gif
[6]: https://github.com/seongjaelee/nvatom/issues/25
+18
View File
@@ -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'
}
]
+3 -1
View File
@@ -8,4 +8,6 @@
# For more detailed documentation see # For more detailed documentation see
# https://atom.io/docs/latest/advanced/keymaps # https://atom.io/docs/latest/advanced/keymaps
'atom-workspace': 'atom-workspace':
'alt-cmd-l': 'notational-velocity:toggle' 'alt-cmd-l': 'nvatom:toggle'
'atom-workspace atom-text-editor':
'alt-cmd-o': 'nvatom:openInterlink'
+48
View File
@@ -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
+89 -71
View File
@@ -1,69 +1,70 @@
path = require 'path' path = require 'path'
fs = require 'fs-plus' fs = require 'fs-plus'
_ = require 'underscore-plus'
{$, $$, SelectListView} = require 'atom-space-pen-views' {$, $$, SelectListView} = require 'atom-space-pen-views'
NoteDirectory = require './note-directory' DocQuery = require 'docquery'
Note = require './note' Utility = require './utility'
module.exports = module.exports =
class NotationalVelocityView extends SelectListView class NotationalVelocityView extends SelectListView
initialize: -> initialize: (state) ->
@initializedAt = new Date()
super super
@addClass('notational-velocity from-top overlay') @addClass('nvatom')
@rootDirectory = atom.config.get('notational-velocity.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.")
@noteDirectory = new NoteDirectory(@rootDirectory, null, () => @updateNotes()) @skipPopulateList = false
@updateNotes()
@prevFilterQuery = ''
@prevCursorPosition = 0 @prevCursorPosition = 0
@documentsLoaded = false
@docQuery = new DocQuery(@rootDirectory, {recursive: true, extensions: atom.config.get('nvatom.extensions')})
@docQuery.on "ready", () =>
@documentsLoaded = true
@setLoading()
@populateList()
@docQuery.on "added", (fileDetails) =>
@populateList() if @documentsLoaded
@docQuery.on "updated", (fileDetails) =>
@populateList() if @documentsLoaded
@docQuery.on "removed", (fileDetails) =>
@populateList() if @documentsLoaded
unless atom.config.get('nvatom.enableLunrPipeline')
@docQuery.searchIndex.pipeline.reset()
updateNotes: () -> isCursorProceeded: ->
@notes = @noteDirectory.getNotes()
@setItems(@notes)
selectItem: (filterQuery) ->
if filterQuery.length == 0
@prevCursorPosition = 0
return null
titlePatterns = [
///^#{filterQuery}$///i,
///^#{filterQuery}///i,
]
titleItem = null
for titlePattern in titlePatterns
titleItems = @notes
.filter (x) -> x.getTitle().match(titlePattern) != null
titleItem = if titleItems.length > 0 then titleItems[0] else null
if titleItem != null
break
# If title item is not null, auto-fill the search panel.
# But we don't want to fill it when deleting.
editor = @filterEditorView.model editor = @filterEditorView.model
currCursorPosition = editor.getCursorBufferPosition().column currCursorPosition = editor.getCursorBufferPosition().column
if titleItem != null && @prevCursorPosition < currCursorPosition isCursorProceeded = @prevCursorPosition < currCursorPosition
@prevFilterQuery = titleItem.getTitle()
editor.setText(titleItem.getTitle())
editor.selectLeft(titleItem.getTitle().length - filterQuery.length)
@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) -> filter: (filterQuery) ->
if filterQuery.length == 0 if (filterQuery is "") or (filterQuery is undefined)
return @notes return @docQuery.documents
return @docQuery.search(filterQuery)
queries = filterQuery.split(' ')
.filter (x) -> x.length > 0
.map (x) -> new RegExp(x, 'gi')
return @notes
.filter (x) ->
queries
.map (q) -> q.test(x.getText()) || q.test(x.getTitle())
.reduce (x, y) -> x && y
getFilterKey: -> getFilterKey: ->
'filetext' 'filetext'
@@ -71,31 +72,49 @@ class NotationalVelocityView extends SelectListView
toggle: -> toggle: ->
if @panel?.isVisible() if @panel?.isVisible()
@hide() @hide()
else else if @documentsLoaded
@populateList() @populateList()
@show() @show()
else
@setLoading("Loading documents")
@show()
viewForItem: (item) -> viewForItem: (item) ->
content = item.getText()[0...100] content = item.body[0...100]
$$ -> $$ ->
@li class: 'two-lines', => @li class: 'two-lines', =>
@div class: 'primary-line', => @div class: 'primary-line', =>
@span "#{item.getTitle()}" @span "#{item.title}"
@div class: 'metadata', "#{item.getModified().toLocaleDateString()}" @div class: 'metadata', "#{item.modifiedAt.toLocaleDateString()}"
@div class: 'secondary-line', "#{content}" @div class: 'secondary-line', "#{content}"
confirmSelection: -> confirmSelection: ->
item = @getSelectedItem() item = @getSelectedItem()
sanitizedQuery = Utility.trim(@getFilterQuery())
calculatedPath = Utility.getNotePath(sanitizedQuery)
filePath = null
if item? if item?
atom.workspace.open(item.getFilePath()) filePath = item.filePath
@cancel() else if fs.existsSync(calculatedPath)
else filePath = calculatedPath
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '') else if sanitizedQuery.length > 0
if sanitizedQuery.length > 0 filePath = calculatedPath
filePath = path.join(@rootDirectory, sanitizedQuery + '.md')
fs.writeFileSync(filePath, '') fs.writeFileSync(filePath, '')
atom.workspace.open(filePath)
if filePath
atom.workspace.open(filePath).then (editor) ->
save = ->
isWhiteSpaceActive = atom.packages.isPackageActive 'whitespace'
if isWhiteSpaceActive
atom.packages.deactivatePackage 'whitespace'
editor.save()
if isWhiteSpaceActive
atom.packages.activatePackage 'whitespace'
debouncedSave = _.debounce save, 1000
editor.onDidStopChanging () ->
debouncedSave() if editor.isModified()
@cancel() @cancel()
destroy: -> destroy: ->
@@ -114,12 +133,15 @@ class NotationalVelocityView extends SelectListView
hide: -> hide: ->
@panel?.hide() @panel?.hide()
populateList: -> getFilterQuery: ->
return unless @notes? editor = @filterEditorView.model
fullText = editor.getText()
selectedText = editor.getSelectedText()
return fullText.substring(0, fullText.length - selectedText.length)
populateList: ->
filterQuery = @getFilterQuery() filterQuery = @getFilterQuery()
filteredItems = @filter(filterQuery) filteredItems = @filter(filterQuery)
selectedItem = @selectItem(filterQuery)
@list.empty() @list.empty()
if filteredItems.length if filteredItems.length
@@ -131,16 +153,12 @@ class NotationalVelocityView extends SelectListView
itemView.data('select-list-item', item) itemView.data('select-list-item', item)
@list.append(itemView) @list.append(itemView)
if selectedItem @selectItem(filteredItems, filterQuery)
n = filteredItems.indexOf(selectedItem) + 1
@selectItemView(@list.find("li:nth-child(#{n})"))
else else
@setError(@getEmptyMessage(@notes.length, filteredItems.length)) @setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
schedulePopulateList: -> schedulePopulateList: ->
# We can skip it when we are just moving the position of the cursor. unless @skipPopulateList
currFilterQuery = @getFilterQuery()
if @prevFilterQuery != currFilterQuery
super super
@prevFilterQuery = currFilterQuery @skipPopulateList = false
+111 -11
View File
@@ -1,4 +1,8 @@
{CompositeDisposable} = require 'atom' path = require 'path'
fs = require 'fs-plus'
{CompositeDisposable, Disposable} = require 'atom'
Interlink = require './interlink'
Utility = require './utility'
module.exports = module.exports =
config: config:
@@ -6,28 +10,124 @@ module.exports =
title: 'Note Directory' title: 'Note Directory'
description: 'The directory to archive notes' description: 'The directory to archive notes'
type: 'string' type: 'string'
default: process.env.ATOM_HOME + '/packages/notational-velocity/notebook' default: path.join(process.env.ATOM_HOME, 'nvatom-notes')
extensions:
notationalVelocityView: null 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
enableAutosave:
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) ->
# Events subscribed to in atom's system can be easily cleaned up with a @rootDirectory = @ensureNoteDirectory()
# 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',
'notational-velocity:toggle': => @createView(state).toggle() 'nvatom:toggle': => @createView(state).toggle()
handleBeforeUnload = @autosaveAll.bind(this)
window.addEventListener('beforeunload', handleBeforeUnload, true)
@subscriptions.add new Disposable -> window.removeEventListener('beforeunload', handleBeforeUnload, true)
handleBlur = (event) =>
if event.target is window
@autosaveAll()
else if event.target.matches('atom-text-editor:not([mini])') and not event.target.contains(event.relatedTarget)
@autosave(event.target.getModel())
window.addEventListener('blur', handleBlur, true)
@subscriptions.add new Disposable -> window.removeEventListener('blur', handleBlur, true)
@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) -> createView: (state, docQuery) ->
unless @notationalVelocityView? unless @notationalVelocityView?
NotationalVelocityView = require './notational-velocity-view' NotationalVelocityView = require './notational-velocity-view'
@notationalVelocityView = new NotationalVelocityView(state.notationalVelocityViewState) @notationalVelocityView = new NotationalVelocityView(state.notationalVelocityViewState)
@notationalVelocityView @notationalVelocityView
autosave: (paneItem) ->
return unless atom.config.get('nvatom.enableAutosave')
return unless paneItem?.getURI?()?
return unless paneItem?.isModified?()
uri = paneItem.getURI()
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: ->
return unless atom.config.get('nvatom.enableAutosave')
@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.')
-58
View File
@@ -1,58 +0,0 @@
path = require 'path'
fs = require 'fs-plus'
pathWatcher = require 'pathwatcher'
Note = require './note'
module.exports =
class NoteDirectory
constructor: (@filePath, @parent, @onChangeCallback) ->
@directories = []
@notes = []
@updateMetadata()
@watcher = pathWatcher.watch(@filePath, (event) => @onChange(event))
destroy: ->
@notes.map (x) -> x.destroy()
@directories.map (x) -> x.destroy()
@watcher.close()
updateMetadata: ->
@notes.map (x) -> x.destroy()
@directories.map (x) -> x.destroy()
@directories = []
@notes = []
try
filenames = fs.readdirSync(@filePath)
catch e
return
for filename in filenames
@addChild(path.join(@filePath, filename))
addChild: (filePath) ->
try
fileStat = fs.statSync(filePath)
catch e
return
if fileStat.isDirectory()
@directories.push(new NoteDirectory(filePath, this, @onChangeCallback))
else
if fs.isMarkdownExtension(path.extname(filePath))
@notes.push(new Note(filePath, this, @onChangeCallback))
getNotes: ->
ret = []
ret = ret.concat(@notes)
for directory in @directories
ret = ret.concat(directory.getNotes())
if @parent is null
ret.sort (x, y) -> if x.getModified().getTime() <= y.getModified().getTime() then 1 else -1
return ret
onChange: (event) ->
# For the case of rename and change, it will be handled in its parent.
if event == 'change'
@updateMetadata()
if @onChangeCallback != null
@onChangeCallback()
-37
View File
@@ -1,37 +0,0 @@
path = require 'path'
fs = require 'fs'
pathWatcher = require 'pathwatcher'
module.exports =
class Note
constructor: (@filePath, @parent, @onChangeCallback) ->
@updateMetadata()
@updateText()
@watcher = pathWatcher.watch(@filePath, (event) => @onChange(event))
destroy: ->
@watcher.close()
updateMetadata: ->
@modified = fs.statSync(@filePath).mtime
relativePath = path.relative(atom.config.get('notational-velocity.directory'), @filePath)
@title = path.join(
path.dirname(relativePath),
path.basename(relativePath, path.extname(relativePath))
)
updateText: ->
@text = fs.readFileSync(@filePath, 'utf8')
onChange: (event) ->
# For the case of rename and change, it will be handled in its parent.
if event == 'change' && fs.existsSync(@filePath)
@updateMetadata()
@updateText()
if @onChangeCallback != null
@onChangeCallback()
getTitle: -> @title
getText: -> @text
getModified: -> @modified
getFilePath: -> @filePath
+26
View File
@@ -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, ''
+6 -2
View File
@@ -3,11 +3,15 @@
{ {
'label': 'Packages' 'label': 'Packages'
'submenu': [ 'submenu': [
'label': 'Notational Velocity' 'label': 'nvAtom'
'submenu': [ 'submenu': [
{ {
'label': 'Toggle' 'label': 'Toggle'
'command': 'notational-velocity:toggle' 'command': 'nvatom:toggle'
}
{
'label': 'Open Interlink'
'command': 'nvatom:openInterlink'
} }
] ]
] ]
+20 -15
View File
@@ -1,33 +1,38 @@
{ {
"name": "notational-velocity", "name": "nvatom",
"main": "./lib/notational-velocity", "main": "./lib/notational-velocity",
"version": "0.1.0", "version": "0.11.0",
"private": true, "private": true,
"contributors": [ "contributors": [
"Seongjae Lee <seongjaelee@gmail.com>" "Seongjae Lee <seongjae@gmail.com>",
"Nikita Litvin <deltaidea@derpy.ru>",
"Jonathan Hoyt <hoyt@github.com>"
], ],
"description": "Notational Velocity for Atom", "description": "Notational Velocity for Atom",
"activationCommands": { "keywords": [
"atom-workspace": "notational-velocity:toggle" "wiki",
}, "notational velocity",
"repository": "https://github.com/seongjaelee/notational-velocity", "nvatom",
"note",
"notetaking"
],
"repository": "https://github.com/seongjaelee/nvatom",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"atom": ">0.50.0" "atom": ">0.50.0"
}, },
"bugs": { "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": { "dependencies": {
"fs-plus": "2.x",
"atom-space-pen-views": "^2.0.3", "atom-space-pen-views": "^2.0.3",
"pathwatcher": "^4.2" "chokidar": "^1.0.5",
"docquery": "^1.1.1",
"fs-plus": "2.x",
"underscore-plus": "^1.6.6"
}, },
"devDependencies": { "devDependencies": {
"fs-plus": "2.x", "temp": "0.8.1"
"atom-space-pen-views": "^2.0.3",
"pathwatcher": "^4.2",
"temp": "~0.7.0"
} }
} }
+105
View File
@@ -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
+36 -21
View File
@@ -1,34 +1,49 @@
{WorkspaceView} = require 'atom' path = require 'path'
NotationalVelocity = require '../lib/notational-velocity' temp = require 'temp'
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. temp.track()
#
# 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.
describe "NotationalVelocity", -> describe "nvAtom", ->
defaultDirectory = atom.config.get('notational-velocity.directory') defaultDirectory = atom.config.get('nvatom.directory')
activationPromise = null activationPromise = null
workspaceElement = null
beforeEach -> beforeEach ->
atom.workspaceView = new WorkspaceView workspaceElement = atom.views.getView(atom.workspace)
activationPromise = atom.packages.activatePackage('notational-velocity')
atom.config.set('notational-velocity.directory', 'testdata')
afterEach -> 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", -> it "attaches and then detaches the view", ->
expect(atom.workspaceView.find('.notational-velocity')).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 atom.workspaceView.element, 'notational-velocity:toggle'
waitsForPromise -> waitsForPromise ->
activationPromise atom.packages.activatePackage('nvatom')
runs -> runs ->
expect(atom.workspaceView.find('.notational-velocity')).toExist() expect(workspaceElement.querySelector('.nvatom')).not.toExist()
atom.commands.dispatch atom.workspaceView.element, 'notational-velocity: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", ->
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()
@@ -1,5 +0,0 @@
NotationalVelocityView = require '../lib/notational-velocity-view'
describe "NotationalVelocityView", ->
it "has one valid test", ->
expect("life").toBe "life"
-117
View File
@@ -1,117 +0,0 @@
path = require 'path'
fs = require 'fs-plus'
temp = require 'temp'
pathWatcher = require 'pathwatcher'
NoteDirectory = require '../lib/note-directory'
Note = require '../lib/note'
describe 'NoteDirectory.getNotes', ->
defaultDirectory = atom.config.get('notational-velocity.directory')
tempDirectory = temp.mkdirSync('node-pathwatcher-directory')
noteDirectory = null
isCallbackCalled = false
# We don't want to let the mtimes of two consecutively create files are same.
# This function ensures the mtime of the file created before calling this function to be always
# smaller than to the mtime of the file created after calling this function.
wait = ->
timestampDirectory = temp.mkdirSync('node-pathwatcher-timestamp')
filePath = path.join(timestampDirectory, 'temp')
fs.writeFileSync(filePath, '.')
mtimeOld = fs.statSync(filePath).mtime
mtimeNew = mtimeOld
while mtimeOld >= mtimeNew
fs.writeFileSync(filePath, '.')
mtimeNew = fs.statSync(filePath).mtime
beforeEach ->
isCallbackCalled = false
callback = => isCallbackCalled = true
atom.config.set('notational-velocity.directory', tempDirectory)
fs.writeFileSync(path.join(tempDirectory, 'Readme.md'), 'read me')
wait()
fs.mkdirSync(path.join(tempDirectory, 'Car'))
fs.writeFileSync(path.join(tempDirectory, 'Car', 'Mini.md'), 'mini')
wait()
noteDirectory = new NoteDirectory(tempDirectory, null, callback)
afterEach ->
noteDirectory.destroy()
fs.unlinkSync(path.join(tempDirectory, 'Car', 'Mini.md'))
fs.rmdirSync(path.join(tempDirectory, 'Car'))
fs.unlinkSync(path.join(tempDirectory, 'Readme.md'))
atom.config.set('notational-velocity.directory', defaultDirectory)
it 'gives a list of notes in the order so that the newest one comes first', ->
notes = noteDirectory.getNotes()
expect(notes.length).toEqual(2)
expect(notes[0].getText()).toBe 'mini'
expect(notes[1].getText()).toBe 'read me'
expect(notes[0].getModified().getTime()).toBeGreaterThan(notes[1].getModified().getTime())
it 'changes its order when a note is changed', ->
fs.writeFileSync(path.join(tempDirectory, 'Readme.md'), 'read me new')
wait()
waitsFor -> isCallbackCalled
runs ->
notes = noteDirectory.getNotes()
expect(notes[0].getText()).toBe 'read me new'
expect(notes[1].getText()).toBe 'mini'
it 'changes its order when a note is created', ->
fs.writeFileSync(path.join(tempDirectory, 'Car', 'Prius.md'), 'prius')
wait()
waitsFor -> isCallbackCalled
runs ->
notes = noteDirectory.getNotes()
expect(notes.length).toEqual(3)
expect(notes[0].getText()).toBe 'prius'
expect(notes[1].getText()).toBe 'mini'
expect(notes[2].getText()).toBe 'read me'
fs.unlinkSync(path.join(tempDirectory, 'Car', 'Prius.md'))
it 'changes its order when a note is deleted', ->
fs.unlinkSync(path.join(tempDirectory, 'Car', 'Mini.md'))
wait()
waitsFor -> isCallbackCalled
runs ->
notes = noteDirectory.getNotes()
expect(notes.length).toEqual(1)
expect(notes[0].getText()).toBe 'read me'
# So that it won't spit an error in the teardown stage.
fs.writeFileSync(path.join(tempDirectory, 'Car', 'Mini.md'), 'mini')
it 'changes its order when a note is renamed', ->
oldPath = path.join(tempDirectory, 'Car', 'Mini.md')
newPath = path.join(tempDirectory, 'Mini.md')
fs.renameSync(oldPath, newPath)
wait()
waitsFor -> isCallbackCalled
runs ->
notes = noteDirectory.getNotes()
expect(notes.length).toEqual(2)
expect(notes[0].getTitle()).toBe 'Mini'
expect(notes[1].getTitle()).toBe 'Readme'
# So that it won't spit an error in the teardown stage.
fs.renameSync(newPath, oldPath)
it 'updates properly when a directory is created and a note is created inside it', ->
fs.mkdirSync(path.join(tempDirectory, 'Food'))
fs.writeFileSync(path.join(tempDirectory, 'Food', 'Milk.md'), 'milk')
wait()
waitsFor -> isCallbackCalled
runs ->
notes = noteDirectory.getNotes()
expect(notes.length).toEqual(3)
expect(notes[0].getText()).toBe 'milk'
# So that it won't spit an error in the teardown stage.
fs.unlinkSync(path.join(tempDirectory, 'Food', 'Milk.md'))
fs.rmdirSync(path.join(tempDirectory, 'Food'))
-36
View File
@@ -1,36 +0,0 @@
path = require 'path'
fs = require 'fs-plus'
temp = require 'temp'
pathWatcher = require 'pathwatcher'
Note = require '../lib/note'
describe 'Note', ->
defaultDirectory = atom.config.get('notational-velocity.directory')
tempDirectory = temp.mkdirSync('node-pathwatcher-directory')
tempFilePath = path.join(tempDirectory, 'Temp.md')
beforeEach ->
atom.config.set('notational-velocity.directory', tempDirectory)
fs.writeFileSync(tempFilePath, 'old')
afterEach ->
fs.unlinkSync(tempFilePath)
atom.config.set('notational-velocity.directory', defaultDirectory)
it 'creates a note', ->
note = new Note(tempFilePath, null, null)
expect(note.getTitle()).toBe 'Temp'
expect(note.getText()).toBe 'old'
expect(note.getFilePath()).toBe tempFilePath
note.destroy()
it 'modifies a note', ->
note = new Note(tempFilePath, null, null)
expect(note.getText()).toBe 'old'
fs.writeFileSync(tempFilePath, 'new')
oldModified = note.getModified()
waitsFor -> oldModified != note.getModified()
runs ->
expect(note.getText()).toBe 'new'
note.destroy()
+54
View File
@@ -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)
+1 -1
View File
@@ -4,7 +4,7 @@
// for a full listing of what's available. // for a full listing of what's available.
@import "ui-variables"; @import "ui-variables";
.notational-velocity { .nvatom {
li { li {
text-overflow: ellipsis; text-overflow: ellipsis;
overflow-x: hidden; overflow-x: hidden;