 
   mousedownHandler: (event) =>
     # event.stopPropagation()
-    if @subjectAndRange != null
-      @clickCallback(@editor, @subjectAndRange.subject, @lastBufferPosition)
+    if @subjectAndMarkerRange != null
+      @clickCallback(@editor, @subjectAndMarkerRange.subject, @lastBufferPosition)
     @clearMarker()
 
   keyupHandler: (event) =>

    @clickCallback = clickCallback
    @editorView = atom.views.getView(editor)
    @marker = null
    @lastBufferPosition = null
    @subjectAndRange = null
    @disposables = new CompositeDisposable
    @handleEvents()

  dispose: ->
    @disposables.dispose()

  handleEvents: ->
    @disposables.add @addEventHandler(@editorView, 'mousedown', @mousedownHandler)
    @disposables.add @addEventHandler(@editorView, 'keyup',     @keyupHandler)
    @disposables.add @addEventHandler(@editorView, 'mousemove', @mousemoveHandler)

  addEventHandler: (editorView, eventName, handler) ->
    editorView.addEventListener eventName, handler

    if event.altKey
      component = @editorView.component
      screenPosition = component.screenPositionForMouseEvent({clientX: event.clientX, clientY: event.clientY})
      if @lastScreenPosition != null && screenPosition.compare(@lastScreenPosition) == 0
        return

      @lastScreenPosition = screenPosition
      bufferPosition = @editor.bufferPositionForScreenPosition(screenPosition)

      if @lastBufferPosition != null && bufferPosition.compare(@lastBufferPosition) == 0
        return
      @lastBufferPosition = bufferPosition

      subjectAndMarkerRange = @getSubjectAndMarkerRange(@editor, bufferPosition)

      if subjectAndMarkerRange == null
        @clearMarker()
        return

      if @marker != null && @marker.getBufferRange().compare(subjectAndMarkerRange.range) == 0
        return

      @clearMarker()
      @createMarker(subjectAndMarkerRange)

  createMarker: (subjectAndMarkerRange) ->
    @editorView.classList.add('keyclick');
    @marker = @editor.markBufferRange(subjectAndMarkerRange.range, { invalidate: 'never' });
    @subjectAndMarkerRange = subjectAndMarkerRange
    @editor.decorateMarker(@marker, { type: 'highlight', 'class': 'keyclick' });

  clearMarker: ->
    @marker?.destroy()
    @marker = null
    @subjectAndMarkerRange = null
    @lastBufferPosition = null
    @editorView.classList.remove('keyclick')
