Don't start the animation loop until the mouse starts dragging

Previously, the animation loop would run multiple times prior to the
the mouseup event on click. We only want to select to the current mouse
position if the mouse is actually dragged.
This commit is contained in:
Nathan Sobo
2014-04-07 11:09:44 -06:00
parent c4be3069f7
commit cbad8a56ec

View File

@@ -284,16 +284,28 @@ EditorCompont = React.createClass
@selectToMousePositionUntilMouseUp(event)
selectToMousePositionUntilMouseUp: (event) ->
dragging = true
lastMousePosition = {clientX: event.clientX, clientY: event.clientY}
{editor} = @props
dragging = false
lastMousePosition = {}
animationLoop = =>
requestAnimationFrame =>
if dragging
@selectToMousePosition(lastMousePosition)
animationLoop()
onMouseMove = (event) ->
# Stop dragging when cursor enters dev tools because we can't detect mouseup
dragging = false if event.which is 0
lastMousePosition.clientX = event.clientX
lastMousePosition.clientY = event.clientY
# Start the animation loop when the mouse moves prior to a mouseup event
unless dragging
dragging = true
animationLoop()
# Stop dragging when cursor enters dev tools because we can't detect mouseup
onMouseUp() if event.which is 0
onMouseUp = ->
dragging = false
window.removeEventListener('mousemove', onMouseMove)
@@ -302,14 +314,6 @@ EditorCompont = React.createClass
window.addEventListener('mousemove', onMouseMove)
window.addEventListener('mouseup', onMouseUp)
animationLoop = =>
requestAnimationFrame =>
if dragging
@selectToMousePosition(lastMousePosition)
animationLoop()
animationLoop()
selectToMousePosition: (event) ->
@props.editor.selectToScreenPosition(@screenPositionForMouseEvent(event))