mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user