Handle editor destruction when dragging.

Closes #4622
Esse commit está contido em:
Ben Ogle
2014-12-16 14:27:11 -08:00
commit 09a0773043
2 arquivos alterados com 23 adições e 2 exclusões
+16
Ver Arquivo
@@ -1612,6 +1612,22 @@ describe "TextEditorComponent", ->
expect(nextAnimationFrame).toBe noAnimationFrame expect(nextAnimationFrame).toBe noAnimationFrame
expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [6, 8]] expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [6, 8]]
describe "when the editor is destroyed while dragging", ->
it "cleans up the handlers for window.mouseup and window.mousemove", ->
linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([2, 4]), which: 1))
linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([6, 8]), which: 1))
nextAnimationFrame()
spyOn(window, 'removeEventListener').andCallThrough()
linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([6, 10]), which: 1))
editor.destroy()
nextAnimationFrame()
call.args.pop() for call in window.removeEventListener.calls
expect(window.removeEventListener).toHaveBeenCalledWith('mouseup')
expect(window.removeEventListener).toHaveBeenCalledWith('mousemove')
describe "when a line is folded", -> describe "when a line is folded", ->
beforeEach -> beforeEach ->
editor.foldBufferRow 4 editor.foldBufferRow 4
+7 -2
Ver Arquivo
@@ -750,10 +750,12 @@ TextEditorComponent = React.createClass
lastMousePosition = {} lastMousePosition = {}
animationLoop = => animationLoop = =>
@requestAnimationFrame => @requestAnimationFrame =>
if dragging if dragging and @isMounted()
screenPosition = @screenPositionForMouseEvent(lastMousePosition) screenPosition = @screenPositionForMouseEvent(lastMousePosition)
dragHandler(screenPosition) dragHandler(screenPosition)
animationLoop() animationLoop()
else if not @isMounted()
stopDragging()
onMouseMove = (event) -> onMouseMove = (event) ->
lastMousePosition.clientX = event.clientX lastMousePosition.clientX = event.clientX
@@ -768,10 +770,13 @@ TextEditorComponent = React.createClass
onMouseUp() if event.which is 0 onMouseUp() if event.which is 0
onMouseUp = -> onMouseUp = ->
stopDragging()
editor.finalizeSelections()
stopDragging = ->
dragging = false dragging = false
window.removeEventListener('mousemove', onMouseMove) window.removeEventListener('mousemove', onMouseMove)
window.removeEventListener('mouseup', onMouseUp) window.removeEventListener('mouseup', onMouseUp)
editor.finalizeSelections()
window.addEventListener('mousemove', onMouseMove) window.addEventListener('mousemove', onMouseMove)
window.addEventListener('mouseup', onMouseUp) window.addEventListener('mouseup', onMouseUp)