 
     offset = $textLayer.offset()
     if highlightStartPosition.left is e.pageX - offset.left and highlightStartPosition.top is e.pageY - offset.top
-      hideHiglight $textLayer
+      closeHighlight publication, page, $textLayer, highlightStartIndex, highlightEndIndex
+    else
+      openHihglight publication, page, $textLayer, highlightStartIndex, highlightEndIndex
 
     highlightStartPosition = null
     highlightStartIndex = -1
+    highlightEndIndex = -1
 
   $textLayer.mouseleave (e) ->
     return if highlightStartIndex is -1


  return if start is -1 or end is -1

  [start, end] = [Math.min(start, end), Math.max(start, end)]

  $textLayer.children().slice(start, end + 1).css
    'background-color': 'rgba(255,0,0,0.3)'


  dims

normalizeStartEnd = (start, end) ->
  [Math.min(start, end), Math.max(start, end)]

hideHiglight = ($textLayer) ->
  $textLayer.children().css
    'background-color': 'rgba(0,0,0,0)'
