Expand selections on mouse drag

This commit is contained in:
Nathan Sobo
2017-03-10 14:31:54 -07:00
committed by Antonio Scandurra
parent 6bfe08e9b0
commit 5594c9d82f
2 changed files with 129 additions and 0 deletions

View File

@@ -786,6 +786,53 @@ class TextEditorComponent {
model.getLastSelection().selectLine(null, {autoscroll: false})
break
}
this.handleMouseDragUntilMouseUp(
(event) => {
const screenPosition = this.screenPositionForMouseEvent(event)
model.selectToScreenPosition(screenPosition, {suppressSelectionMerge: true, autoscroll: false})
this.updateSync()
},
() => {
model.finalizeSelections()
model.mergeIntersectingSelections()
this.updateSync()
}
)
}
handleMouseDragUntilMouseUp (didDragCallback, didStopDragging) {
let dragging = false
let lastMousemoveEvent
const animationFrameLoop = () => {
window.requestAnimationFrame(() => {
if (dragging && this.visible) {
didDragCallback(lastMousemoveEvent)
animationFrameLoop()
}
})
}
function didMouseMove (event) {
lastMousemoveEvent = event
if (!dragging) {
dragging = true
animationFrameLoop()
}
}
function didMouseUp () {
window.removeEventListener('mousemove', didMouseMove)
window.removeEventListener('mouseup', didMouseUp)
if (dragging) {
dragging = false
didStopDragging()
}
}
window.addEventListener('mousemove', didMouseMove)
window.addEventListener('mouseup', didMouseUp)
}
screenPositionForMouseEvent ({clientX, clientY}) {