mirror of
https://github.com/wassname/nvatom.git
synced 2026-06-27 16:10:36 +08:00
Add interlink highlight and jump features
This commit is contained in:
@@ -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'
|
||||
}
|
||||
]
|
||||
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -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
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user