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:
Nathan Sobo
2017-11-01 10:15:47 -06:00
committed by GitHub
2 changed files with 18 additions and 5 deletions

View File

@@ -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 () {

View File

@@ -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) {