mirror of
https://github.com/atom/atom.git
synced 2026-02-10 22:55:09 -05:00
Expand selections on mouse drag
This commit is contained in:
committed by
Antonio Scandurra
parent
6bfe08e9b0
commit
5594c9d82f
@@ -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}) {
|
||||
|
||||
Reference in New Issue
Block a user