Add interlink highlight and jump features

This commit is contained in:
Seongjae Lee
2015-09-26 00:16:36 -07:00
parent cc8a780436
commit 9c5c4e43da
7 changed files with 101 additions and 9 deletions
+27
View File
@@ -0,0 +1,27 @@
'name': 'nvAtom Markdown'
'scopeName': 'source.gfm'
'fileTypes': [
'markdown'
'md'
'mdown'
'mkd'
'mkdown'
'rmd'
'ron'
]
'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'
}
]
+2
View File
@@ -9,3 +9,5 @@
# https://atom.io/docs/latest/advanced/keymaps
'atom-workspace':
'alt-cmd-l': 'nvatom:toggle'
'atom-workspace atom-text-editor':
'alt-cmd-o': 'nvatom:openInterlink'
+4 -4
View File
@@ -3,6 +3,7 @@ fs = require 'fs-plus'
_ = require 'underscore-plus'
{$, $$, SelectListView} = require 'atom-space-pen-views'
DocQuery = require 'docquery'
Utility = require './utility'
module.exports =
class NotationalVelocityView extends SelectListView
@@ -10,7 +11,7 @@ class NotationalVelocityView extends SelectListView
@initializedAt = new Date()
super
@addClass('nvatom from-top overlay')
@rootDirectory = fs.normalize(atom.config.get('nvatom.directory'))
@rootDirectory = Utility.getNoteDirectory()
unless fs.existsSync(@rootDirectory)
throw new Error("The given directory #{@rootDirectory} does not exist. "
+ "Set the note directory to the existing one from Settings.")
@@ -90,10 +91,9 @@ class NotationalVelocityView extends SelectListView
confirmSelection: ->
item = @getSelectedItem()
sanitizedQuery = Utility.trim(@getFilterQuery())
calculatedPath = Utility.getNotePath(sanitizedQuery)
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?
filePath = item.filePath
else if fs.existsSync(calculatedPath)
+6 -4
View File
@@ -1,6 +1,7 @@
path = require 'path'
fs = require 'fs-plus'
{CompositeDisposable, Disposable} = require 'atom'
NoteLink = require './notelink'
module.exports =
config:
@@ -49,8 +50,11 @@ module.exports =
@subscriptions.add atom.workspace.onWillDestroyPaneItem ({item}) => @autosave(item) unless @autodelete(item)
@noteLink = new NoteLink()
deactivate: ->
@subscriptions.dispose()
@noteLink.destroy()
@notationalVelocityView.destroy()
serialize: ->
@@ -66,15 +70,13 @@ module.exports =
return unless paneItem?.getURI?()?
return unless paneItem?.isModified?()
uri = paneItem.getURI()
return unless uri.indexOf(@rootDirectory) is 0
return unless path.extname(uri) in atom.config.get('nvatom.extensions')
return unless Utility.isNote(uri)
paneItem?.save?()
autodelete: (paneItem) ->
return false unless paneItem?.getURI?()?
uri = paneItem.getURI()
return false unless uri.indexOf(@rootDirectory) is 0
return false unless path.extname(uri) in atom.config.get('nvatom.extensions')
return unless Utility.isNote(uri)
return false unless paneItem?.isEmpty()
fs.unlinkSync(uri)
noteName = uri.substring(@rootDirectory.length + 1)
+36
View File
@@ -0,0 +1,36 @@
fs = require 'fs-plus'
{CompositeDisposable} = require 'atom'
Utility = require './utility'
module.exports =
class NoteLink
constructor: ->
@subscriptions = new CompositeDisposable
@subscriptions.add atom.commands.add 'atom-workspace', 'nvatom:openInterlink': => @openInterlink()
destroy: ->
@subscriptions.dispose()
openInterlink: ->
editor = atom.workspace.getActiveTextEditor()
return unless editor?
return unless Utility.isNote(editor.getPath())
noteTitle = @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
return token.value
+15
View File
@@ -0,0 +1,15 @@
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) -> filePath.startsWith(Utility.getNoteDirectory()) and path.extname(filePath) in atom.config.get('nvatom.extensions')
@trim: (str) -> str?.replace /^\s+|\s+$/g, ''
+11 -1
View File
@@ -10,8 +10,18 @@
],
"description": "Notational Velocity for Atom",
"activationCommands": {
"atom-workspace": "nvatom:toggle"
"atom-workspace": [
"nvatom:toggle",
"nvatom:openInterlink"
]
},
"keywords": [
"wiki",
"notational velocity",
"nvatom",
"note",
"notetaking"
],
"repository": "https://github.com/seongjaelee/nvatom",
"license": "MIT",
"engines": {