mirror of
https://github.com/wassname/nvatom.git
synced 2026-08-12 12:10:23 +08:00
Add tests for notelinks
This commit is contained in:
+7
-5
@@ -6,17 +6,17 @@ module.exports =
|
||||
class NoteLink
|
||||
constructor: ->
|
||||
@subscriptions = new CompositeDisposable
|
||||
@subscriptions.add atom.commands.add 'atom-workspace', 'nvatom:openInterlink': => @openInterlink()
|
||||
@subscriptions.add atom.commands.add 'atom-workspace', 'nvatom:openInterlink': => NoteLink.openInterlink()
|
||||
|
||||
destroy: ->
|
||||
@subscriptions.dispose()
|
||||
|
||||
openInterlink: ->
|
||||
@openInterlink: ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
return unless editor?
|
||||
return unless Utility.isNote(editor.getPath())
|
||||
|
||||
noteTitle = @getInterlinkUnderCursor(editor)
|
||||
noteTitle = NoteLink.getInterlinkUnderCursor(editor)
|
||||
return unless noteTitle?
|
||||
return unless noteTitle.length
|
||||
|
||||
@@ -26,11 +26,13 @@ class NoteLink
|
||||
fs.writeFileSync(notePath, '')
|
||||
atom.workspace.open(notePath)
|
||||
|
||||
getInterlinkUnderCursor: (editor) ->
|
||||
@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
|
||||
interlink = Utility.trim(token.value)
|
||||
return unless interlink.length
|
||||
return interlink
|
||||
|
||||
+3
-1
@@ -10,6 +10,8 @@ class Utility
|
||||
|
||||
@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')
|
||||
@isNote: (filePath) ->
|
||||
filePath = fs.normalize(filePath)
|
||||
return filePath.startsWith(Utility.getNoteDirectory()) and path.extname(filePath) in atom.config.get('nvatom.extensions')
|
||||
|
||||
@trim: (str) -> str?.replace /^\s+|\s+$/g, ''
|
||||
|
||||
Reference in New Issue
Block a user