mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Merge pull request #16060 from atom/fix-adding-selections-with-mouse
Don't terminate selection dragging when a modifier key is pressed
This commit is contained in:
@@ -4428,11 +4428,14 @@ describe('TextEditorComponent', () => {
|
||||
const {component, editor} = buildComponent()
|
||||
|
||||
let dragging = false
|
||||
component.handleMouseDragUntilMouseUp({
|
||||
didDrag: (event) => { dragging = true },
|
||||
didStopDragging: () => { dragging = false }
|
||||
})
|
||||
function startDragging () {
|
||||
component.handleMouseDragUntilMouseUp({
|
||||
didDrag: (event) => { dragging = true },
|
||||
didStopDragging: () => { dragging = false }
|
||||
})
|
||||
}
|
||||
|
||||
startDragging()
|
||||
window.dispatchEvent(new MouseEvent('mousemove'))
|
||||
await getNextAnimationFramePromise()
|
||||
expect(dragging).toBe(true)
|
||||
@@ -4448,6 +4451,16 @@ describe('TextEditorComponent', () => {
|
||||
window.dispatchEvent(new MouseEvent('mousemove'))
|
||||
await getNextAnimationFramePromise()
|
||||
expect(dragging).toBe(false)
|
||||
|
||||
// Pressing a modifier key does not terminate dragging, (to ensure we can add new selections with the mouse)
|
||||
startDragging()
|
||||
window.dispatchEvent(new MouseEvent('mousemove'))
|
||||
await getNextAnimationFramePromise()
|
||||
expect(dragging).toBe(true)
|
||||
component.didKeydown({key: 'Control'})
|
||||
component.didKeydown({key: 'Alt'})
|
||||
component.didKeydown({key: 'Meta'})
|
||||
expect(dragging).toBe(true)
|
||||
})
|
||||
|
||||
function getNextAnimationFramePromise () {
|
||||
|
||||
@@ -1666,7 +1666,7 @@ class TextEditorComponent {
|
||||
// Stop dragging when user interacts with the keyboard. This prevents
|
||||
// unwanted selections in the case edits are performed while selecting text
|
||||
// at the same time.
|
||||
if (this.stopDragging) this.stopDragging()
|
||||
if (this.stopDragging && event.key !== 'Control' && event.key !== 'Alt' && event.key !== 'Meta') this.stopDragging()
|
||||
|
||||
if (this.lastKeydownBeforeKeypress != null) {
|
||||
if (this.lastKeydownBeforeKeypress.code === event.code) {
|
||||
|
||||
Reference in New Issue
Block a user