Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @findDefinition = ->
  2.     e = getActiveTextEditor()
  3.     e.selectWordsContainingCursors()
  4.     name = e.getSelectedText()
  5.     found = false
  6.     for test in [ "def +" + name + " ?\\(",
  7.             "class +" + name + " ?\\(", "class +" + name + " ?:",
  8.             name + " *=", "^[ \\t]*" + name + ",.+=",
  9.             "import +" + name ]
  10.         rexp = new RegExp(test)
  11.         e.scan(rexp, (o)->
  12.             if o.matchText.length > 0
  13.                 r = e.markBufferRange(o.range)
  14.                 e.selectMarker(r)
  15.                 o.stop()
  16.                 r.destroy()
  17.                 flash(e)
  18.                 found = true
  19.         )
  20.         if found
  21.             return
  22.  
  23.  
  24. flashMarker: null
  25. flash = (editor) ->
  26.     @flashMarker?.destroy()
  27.     cursorPosition = editor.getCursorBufferPosition()
  28.     @flashMarker = editor.markBufferPosition(cursorPosition)
  29.     decorationOptions = {type: 'line', class: 'cursor-history-flash-line'}
  30.     editor.decorateMarker(@flashMarker, decorationOptions)
  31.  
  32.     destroyMarker = =>
  33.         disposable?.destroy()
  34.         disposable = null
  35.         @flashMarker?.destroy()
  36.  
  37.     disposable = editor.onDidChangeCursorPosition(destroyMarker)
  38.     # [NOTE] animation-duration has to be shorter than this value(1sec)
  39.     setTimeout(destroyMarker, 1000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement