mirror of
https://github.com/wassname/nvatom.git
synced 2026-06-27 16:10:36 +08:00
Apply the interlink extended grammar only on valid notes
To do so, we need to activate the package on Atom startup.
This commit is contained in:
+2
-11
@@ -1,14 +1,5 @@
|
||||
'name': 'nvAtom Markdown'
|
||||
'scopeName': 'source.gfm'
|
||||
'fileTypes': [
|
||||
'markdown'
|
||||
'md'
|
||||
'mdown'
|
||||
'mkd'
|
||||
'mkdown'
|
||||
'rmd'
|
||||
'ron'
|
||||
]
|
||||
'name': 'nvAtom Github Markdown'
|
||||
'scopeName': 'source.gfm.nvatom'
|
||||
'patterns': [
|
||||
{
|
||||
'include': 'source.gfm'
|
||||
|
||||
@@ -7,6 +7,9 @@ class Interlink
|
||||
constructor: ->
|
||||
@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()
|
||||
|
||||
@@ -24,16 +24,12 @@ module.exports =
|
||||
type: 'boolean'
|
||||
default: true
|
||||
|
||||
notationalVelocityView: null
|
||||
|
||||
activate: (state) ->
|
||||
@rootDirectory = @ensureNoteDirectory()
|
||||
|
||||
# Events subscribed to in atom's system can be easily cleaned up with a
|
||||
# CompositeDisposable
|
||||
@subscriptions = new CompositeDisposable
|
||||
|
||||
# Register command that toggles this view
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'nvatom:toggle': => @createView(state).toggle()
|
||||
|
||||
@@ -55,11 +51,11 @@ module.exports =
|
||||
|
||||
deactivate: ->
|
||||
@subscriptions.dispose()
|
||||
@interlnk.destroy()
|
||||
@notationalVelocityView.destroy()
|
||||
@interlnk?.destroy()
|
||||
@notationalVelocityView?.destroy()
|
||||
|
||||
serialize: ->
|
||||
notationalVelocityViewState: @notationalVelocityView.serialize()
|
||||
notationalVelocityViewState: @notationalVelocityView?.serialize()
|
||||
|
||||
createView: (state, docQuery) ->
|
||||
unless @notationalVelocityView?
|
||||
|
||||
@@ -9,12 +9,6 @@
|
||||
"Jonathan Hoyt <hoyt@github.com>"
|
||||
],
|
||||
"description": "Notational Velocity for Atom",
|
||||
"activationCommands": {
|
||||
"atom-workspace": [
|
||||
"nvatom:toggle",
|
||||
"nvatom:openInterlink"
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"wiki",
|
||||
"notational velocity",
|
||||
|
||||
+41
-32
@@ -9,14 +9,12 @@ describe 'Interlink', ->
|
||||
|
||||
beforeEach ->
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
activationPromise = atom.packages.activatePackage('nvatom')
|
||||
noteDirectory = temp.mkdirSync()
|
||||
|
||||
atom.config.set('nvatom.directory', noteDirectory)
|
||||
|
||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
atom.packages.activatePackage('nvatom')
|
||||
|
||||
afterEach ->
|
||||
atom.config.set('nvatom.directory', defaultDirectory)
|
||||
@@ -24,39 +22,50 @@ describe 'Interlink', ->
|
||||
describe 'when getInerlinkUnderCursor is called', ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.workspace.open(path.join(noteDirectory, 'Interlink.md')).then (o) -> editor = o
|
||||
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' },
|
||||
]
|
||||
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
|
||||
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' },
|
||||
]
|
||||
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
|
||||
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', ->
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
|
||||
describe "nvAtom", ->
|
||||
defaultDirectory = atom.config.get('nvatom.directory')
|
||||
@@ -7,41 +8,38 @@ describe "nvAtom", ->
|
||||
|
||||
beforeEach ->
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
activationPromise = atom.packages.activatePackage('nvatom')
|
||||
atom.config.set('nvatom.directory', 'testdata')
|
||||
|
||||
afterEach ->
|
||||
atom.config.set('nvatom.directory', defaultDirectory)
|
||||
|
||||
describe "when the nvatom:toggle event is triggered", ->
|
||||
it "attaches and then detaches the view", ->
|
||||
expect(workspaceElement.querySelector('.nvatom')).not.toExist()
|
||||
|
||||
# This is an activation event, triggering it will cause the package to be activated.
|
||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
||||
|
||||
noteDirectory = path.join(temp.mkdirSync())
|
||||
atom.config.set('nvatom.directory', noteDirectory)
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
atom.packages.activatePackage('nvatom')
|
||||
|
||||
runs ->
|
||||
expect(workspaceElement.querySelector('.nvatom')).toExist()
|
||||
expect(workspaceElement.querySelector('.nvatom')).not.toExist()
|
||||
|
||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
||||
expect(workspaceElement.querySelector('.nvatom')).toExist()
|
||||
expect(workspaceElement.querySelector('.nvatom').parentNode.style.display).not.toBe 'none'
|
||||
|
||||
atom.commands.dispatch workspaceElement, 'nvatom:toggle'
|
||||
expect(workspaceElement.querySelector('.nvatom').parentNode.style.display).toBe 'none'
|
||||
|
||||
it "checks if we banned the default directory under packages directory", ->
|
||||
atom.notifications.clear()
|
||||
noteDirectory = path.join(process.env.ATOM_HOME, 'packages', 'nvatom', 'notebook')
|
||||
atom.config.set('nvatom.directory', noteDirectory)
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('notifications')
|
||||
atom.packages.activatePackage('nvatom')
|
||||
|
||||
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 ->
|
||||
activationPromise
|
||||
atom.packages.activatePackage('notifications')
|
||||
|
||||
runs ->
|
||||
notificationContainer = workspaceElement.querySelector('atom-notifications')
|
||||
|
||||
Reference in New Issue
Block a user