Keep mouse move handler from going out of control

Previously the editor could be hidden and the mouse move handler
would start logging errors since it will still trying to compute
positions based on the move events still firing on the document.

Now the display property is checked in the handler and also the selection
is finalized when a move event occurs and the button is no longer pressed.

Closes #1755
This commit is contained in:
Kevin Sawicki
2014-03-13 10:33:18 -07:00
parent de58936ed1
commit ebfe50aafc

View File

@@ -461,21 +461,29 @@ class EditorView extends View
selectOnMousemoveUntilMouseup: ->
lastMoveEvent = null
moveHandler = (event = lastMoveEvent) =>
if event
@editor.selectToScreenPosition(@screenPositionFromMouseEvent(event))
lastMoveEvent = event
$(document).on "mousemove.editor-#{@id}", moveHandler
interval = setInterval(moveHandler, 20)
$(document).one "mouseup.editor-#{@id}", =>
finalizeSelections = =>
clearInterval(interval)
$(document).off 'mousemove', moveHandler
$(document).off 'mouseup', finalizeSelections
@editor.mergeIntersectingSelections(isReversed: @editor.getLastSelection().isReversed())
@editor.finalizeSelections()
@syncCursorAnimations()
moveHandler = (event = lastMoveEvent) =>
return unless event?
if event.which is 1 and @[0].style.display isnt 'none'
@editor.selectToScreenPosition(@screenPositionFromMouseEvent(event))
lastMoveEvent = event
else
finalizeSelections()
$(document).on "mousemove.editor-#{@id}", moveHandler
interval = setInterval(moveHandler, 20)
$(document).one "mouseup.editor-#{@id}", finalizeSelections
afterAttach: (onDom) ->
return unless onDom