mirror of
https://github.com/wassname/nvatom.git
synced 2026-09-10 12:21:11 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb80f5e203 | ||
|
|
5f26638a78 | ||
|
|
52937e2f3c | ||
|
|
55631b89ea | ||
|
|
7ae6d1c211 | ||
|
|
56821bccbc | ||
|
|
11a6c37c70 | ||
|
|
ae435d7043 | ||
|
|
03654ac2c6 | ||
|
|
91f4bca077 | ||
|
|
e39334f9fa | ||
|
|
d8e60f9cfc | ||
|
|
95a793f050 | ||
|
|
c15e7e0f96 | ||
|
|
3679cf0a71 | ||
|
|
6207b379eb | ||
|
|
66e03ce0e3 | ||
|
|
f19c613204 | ||
|
|
42eb70ac27 | ||
|
|
a2b81ad570 | ||
|
|
1f91f4d6b5 | ||
|
|
0f269c9216 | ||
|
|
e94430630c | ||
|
|
49c081ed6e |
@@ -1,2 +1,9 @@
|
||||
## 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
|
||||
- First release
|
||||
|
||||
@@ -26,12 +26,35 @@ We do believe Notational Velocity is the precursor of the famous note-taking app
|
||||
|
||||
## Settings
|
||||
|
||||
- `Note Directory`: The directory to archive notes.
|
||||
To configure your note directory, set `notational-velocity.directory`:
|
||||
|
||||
* Open your `~/.atom/config.cson` file from the menu: *Atom > Open Your Config*
|
||||
* Append the following lines:
|
||||
|
||||
```cson
|
||||
'notational-velocity':
|
||||
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
|
||||
|
||||
- `alt-cmd-l`: Toggles the search view.
|
||||
|
||||
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': 'notational-velocity:toggle'
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- [Notational Velocity](http://notational.net/)
|
||||
|
||||
@@ -1,69 +1,55 @@
|
||||
path = require 'path'
|
||||
fs = require 'fs-plus'
|
||||
_ = require 'underscore-plus'
|
||||
{$, $$, SelectListView} = require 'atom-space-pen-views'
|
||||
NoteDirectory = require './note-directory'
|
||||
Note = require './note'
|
||||
DocQuery = require 'DocQuery'
|
||||
|
||||
module.exports =
|
||||
class NotationalVelocityView extends SelectListView
|
||||
initialize: ->
|
||||
initialize: (state) ->
|
||||
@initializedAt = new Date()
|
||||
super
|
||||
@addClass('notational-velocity from-top overlay')
|
||||
@rootDirectory = atom.config.get('notational-velocity.directory')
|
||||
if !fs.existsSync(@rootDirectory)
|
||||
throw new Error("The given directory #{@rootDirectory} does not exist. "
|
||||
+ "Set the note directory to the existing one from Settings.")
|
||||
@noteDirectory = new NoteDirectory(@rootDirectory, null, () => @updateNotes())
|
||||
@updateNotes()
|
||||
@prevFilterQuery = ''
|
||||
@prevCursorPosition = 0
|
||||
|
||||
updateNotes: () ->
|
||||
@notes = @noteDirectory.getNotes()
|
||||
@setItems(@notes)
|
||||
@documentsLoaded = false
|
||||
@docQuery = new DocQuery(@rootDirectory, {recursive: true})
|
||||
@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
|
||||
|
||||
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
|
||||
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.
|
||||
editor = @filterEditorView.model
|
||||
currCursorPosition = editor.getCursorBufferPosition().column
|
||||
if titleItem != null && @prevCursorPosition < currCursorPosition
|
||||
@prevFilterQuery = titleItem.getTitle()
|
||||
editor.setText(titleItem.getTitle())
|
||||
editor.selectLeft(titleItem.getTitle().length - filterQuery.length)
|
||||
if titleItem != undefined && @prevCursorPosition < currCursorPosition
|
||||
@prevFilterQuery = titleItem.title
|
||||
editor.setText(filterQuery + titleItem.title.slice(filterQuery.length))
|
||||
editor.selectLeft(titleItem.title.length - filterQuery.length)
|
||||
@prevCursorPosition = currCursorPosition
|
||||
|
||||
return titleItem
|
||||
|
||||
filter: (filterQuery) ->
|
||||
if filterQuery.length == 0
|
||||
return @notes
|
||||
|
||||
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
|
||||
return @docQuery.search(filterQuery)
|
||||
|
||||
getFilterKey: ->
|
||||
'filetext'
|
||||
@@ -71,32 +57,47 @@ class NotationalVelocityView extends SelectListView
|
||||
toggle: ->
|
||||
if @panel?.isVisible()
|
||||
@hide()
|
||||
else
|
||||
else if @documentsLoaded
|
||||
@populateList()
|
||||
@show()
|
||||
else
|
||||
@setLoading("Loading documents")
|
||||
@show()
|
||||
|
||||
viewForItem: (item) ->
|
||||
content = item.getText()[0...100]
|
||||
content = item.body[0...100]
|
||||
|
||||
$$ ->
|
||||
@li class: 'two-lines', =>
|
||||
@div class: 'primary-line', =>
|
||||
@span "#{item.getTitle()}"
|
||||
@div class: 'metadata', "#{item.getModified().toLocaleDateString()}"
|
||||
@span "#{item.title}"
|
||||
@div class: 'metadata', "#{item.modifiedAt.toLocaleDateString()}"
|
||||
@div class: 'secondary-line', "#{content}"
|
||||
|
||||
confirmSelection: ->
|
||||
item = @getSelectedItem()
|
||||
item = @getSelectedItem()
|
||||
filePath = null
|
||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
||||
calculatedPath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
||||
if item?
|
||||
atom.workspace.open(item.getFilePath())
|
||||
@cancel()
|
||||
else
|
||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
||||
if sanitizedQuery.length > 0
|
||||
filePath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
||||
fs.writeFileSync(filePath, '')
|
||||
atom.workspace.open(filePath)
|
||||
@cancel()
|
||||
filePath = item.filePath
|
||||
else if fs.existsSync(calculatedPath)
|
||||
filePath = calculatedPath
|
||||
else if sanitizedQuery.length > 0
|
||||
filePath = calculatedPath
|
||||
fs.writeFileSync(filePath, '')
|
||||
|
||||
if filePath
|
||||
atom.workspace.open(filePath).then (editor) ->
|
||||
save = ->
|
||||
atom.packages.deactivatePackage 'whitespace'
|
||||
editor.save()
|
||||
atom.packages.activatePackage 'whitespace'
|
||||
debouncedSave = _.debounce save, 1000
|
||||
editor.onDidStopChanging () ->
|
||||
debouncedSave() if editor.isModified()
|
||||
|
||||
@cancel()
|
||||
|
||||
destroy: ->
|
||||
@cancel()
|
||||
@@ -115,10 +116,13 @@ class NotationalVelocityView extends SelectListView
|
||||
@panel?.hide()
|
||||
|
||||
populateList: ->
|
||||
return unless @notes?
|
||||
|
||||
filterQuery = @getFilterQuery()
|
||||
filteredItems = @filter(filterQuery)
|
||||
filteredItems = null
|
||||
if filterQuery == "" || filterQuery == undefined
|
||||
filteredItems = @docQuery.documents
|
||||
else
|
||||
filteredItems = @filter(filterQuery)
|
||||
|
||||
selectedItem = @selectItem(filterQuery)
|
||||
|
||||
@list.empty()
|
||||
@@ -136,7 +140,7 @@ class NotationalVelocityView extends SelectListView
|
||||
@selectItemView(@list.find("li:nth-child(#{n})"))
|
||||
|
||||
else
|
||||
@setError(@getEmptyMessage(@notes.length, filteredItems.length))
|
||||
@setError(@getEmptyMessage(@docQuery.documents.length, filteredItems.length))
|
||||
|
||||
schedulePopulateList: ->
|
||||
# We can skip it when we are just moving the position of the cursor.
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{CompositeDisposable} = require 'atom'
|
||||
path = require 'path'
|
||||
fs = require 'fs-plus'
|
||||
{CompositeDisposable, Disposable} = require 'atom'
|
||||
|
||||
module.exports =
|
||||
config:
|
||||
@@ -6,11 +8,13 @@ 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, 'notational-velocity-notes')
|
||||
|
||||
notationalVelocityView: null
|
||||
|
||||
activate: (state) ->
|
||||
@rootDirectory = @ensureNoteDirectory()
|
||||
|
||||
# Events subscribed to in atom's system can be easily cleaned up with a
|
||||
# CompositeDisposable
|
||||
@subscriptions = new CompositeDisposable
|
||||
@@ -19,6 +23,20 @@ module.exports =
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'notational-velocity: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)
|
||||
|
||||
deactivate: ->
|
||||
@subscriptions.dispose()
|
||||
@notationalVelocityView.destroy()
|
||||
@@ -26,8 +44,41 @@ module.exports =
|
||||
serialize: ->
|
||||
notationalVelocityViewState: @notationalVelocityView.serialize()
|
||||
|
||||
createView: (state) ->
|
||||
createView: (state, docQuery) ->
|
||||
unless @notationalVelocityView?
|
||||
NotationalVelocityView = require './notational-velocity-view'
|
||||
@notationalVelocityView = new NotationalVelocityView(state.notationalVelocityViewState)
|
||||
@notationalVelocityView
|
||||
|
||||
autosave: (paneItem) ->
|
||||
return unless paneItem?.getURI?()?
|
||||
return unless paneItem?.isModified?()
|
||||
uri = paneItem.getURI()
|
||||
return unless uri.indexOf(@rootDirectory) == 0
|
||||
return unless fs.isMarkdownExtension(path.extname(uri))
|
||||
paneItem?.save?()
|
||||
|
||||
autosaveAll: ->
|
||||
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
||||
|
||||
ensureNoteDirectory: ->
|
||||
noteDirectory = atom.config.get('notational-velocity.directory')
|
||||
packagesDirectory = path.join(process.env.ATOM_HOME, 'packages')
|
||||
defaultNoteDirectory = path.join(packagesDirectory, 'notational-velocity', 'notebook')
|
||||
|
||||
if noteDirectory.startsWith(packagesDirectory)
|
||||
storageDirectory = path.join(packagesDirectory, 'storage')
|
||||
throw new Error("""
|
||||
The note directory (#{noteDirectory}) should NOT nest under #{packagesDirectory}.
|
||||
It is likely that you updated the package to a newer version from v0.1.0.
|
||||
It is likely that the note directory is overwritten.
|
||||
Unfortunately, I couldn't find a way to recover overwritten notes.
|
||||
You might recover partial notes from #{storageDirectory}.
|
||||
I am extremely sorry.
|
||||
- Seongjae Lee""")
|
||||
|
||||
if !fs.existsSync(noteDirectory)
|
||||
fs.makeTreeSync(noteDirectory)
|
||||
fs.copySync(defaultNoteDirectory, noteDirectory)
|
||||
|
||||
return fs.realpathSync(noteDirectory)
|
||||
|
||||
@@ -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()
|
||||
@@ -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
|
||||
+9
-10
@@ -1,10 +1,12 @@
|
||||
{
|
||||
"name": "notational-velocity",
|
||||
"main": "./lib/notational-velocity",
|
||||
"version": "0.1.0",
|
||||
"version": "0.3.0",
|
||||
"private": true,
|
||||
"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",
|
||||
"activationCommands": {
|
||||
@@ -20,14 +22,11 @@
|
||||
},
|
||||
"homepage": "https://github.com/seongjaelee/notational-velocity",
|
||||
"dependencies": {
|
||||
"fs-plus": "2.x",
|
||||
"atom-space-pen-views": "^2.0.3",
|
||||
"pathwatcher": "^4.2"
|
||||
"chokidar": "^1.0.5",
|
||||
"docquery": "^1.1.0",
|
||||
"fs-plus": "2.x",
|
||||
"underscore-plus": "^1.6.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"fs-plus": "2.x",
|
||||
"atom-space-pen-views": "^2.0.3",
|
||||
"pathwatcher": "^4.2",
|
||||
"temp": "~0.7.0"
|
||||
}
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
{WorkspaceView} = require 'atom'
|
||||
NotationalVelocity = require '../lib/notational-velocity'
|
||||
|
||||
# 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'
|
||||
|
||||
describe "NotationalVelocity", ->
|
||||
defaultDirectory = atom.config.get('notational-velocity.directory')
|
||||
activationPromise = null
|
||||
workspaceElement = null
|
||||
|
||||
beforeEach ->
|
||||
atom.workspaceView = new WorkspaceView
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
activationPromise = atom.packages.activatePackage('notational-velocity')
|
||||
atom.config.set('notational-velocity.directory', 'testdata')
|
||||
|
||||
@@ -20,15 +15,35 @@ describe "NotationalVelocity", ->
|
||||
|
||||
describe "when the notational-velocity:toggle event is triggered", ->
|
||||
it "attaches and then detaches the view", ->
|
||||
expect(atom.workspaceView.find('.notational-velocity')).not.toExist()
|
||||
expect(workspaceElement.querySelector('.notational-velocity')).not.toExist()
|
||||
|
||||
# This is an activation event, triggering it will cause the package to be
|
||||
# activated.
|
||||
atom.commands.dispatch atom.workspaceView.element, 'notational-velocity:toggle'
|
||||
# This is an activation event, triggering it will cause the package to be activated.
|
||||
atom.commands.dispatch workspaceElement, 'notational-velocity:toggle'
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
|
||||
runs ->
|
||||
expect(atom.workspaceView.find('.notational-velocity')).toExist()
|
||||
atom.commands.dispatch atom.workspaceView.element, 'notational-velocity:toggle'
|
||||
expect(workspaceElement.querySelector('.notational-velocity')).toExist()
|
||||
atom.commands.dispatch workspaceElement, 'notational-velocity:toggle'
|
||||
|
||||
it "checks if we banned the default directory under packages directory", ->
|
||||
atom.notifications.clear()
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('notifications')
|
||||
|
||||
runs ->
|
||||
defaultNoteDirectory = path.join(process.env.ATOM_HOME, 'packages', 'notational-velocity', 'notebook')
|
||||
atom.config.set('notational-velocity.directory', defaultNoteDirectory)
|
||||
|
||||
# This is an activation event, triggering it will cause the package to be activated.
|
||||
atom.commands.dispatch workspaceElement, 'notational-velocity:toggle'
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
|
||||
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"
|
||||
@@ -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'))
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user