Add tests for notelinks

This commit is contained in:
Seongjae Lee
2015-09-27 10:39:03 -07:00
parent 9244b0a0b9
commit c5eca919ed
5 changed files with 108 additions and 8 deletions
+7 -5
View File
@@ -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
View File
@@ -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, ''