From ebfe50aafc63148b9e837d246f2deebf0378e709 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 13 Mar 2014 10:33:18 -0700 Subject: [PATCH] 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 --- src/editor-view.coffee | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 92e1cd60e..0ff3a07f3 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -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