Merge pull request #20375 from majidzeno/issue-20222

fix: shortcuts conflict with browser native shortcuts
This commit is contained in:
Blue F
2022-03-15 13:10:30 -07:00
committed by GitHub
3 changed files with 16 additions and 2 deletions

View File

@@ -821,6 +821,7 @@ describe('Settings', () => {
it('loads preferred editor, available editors and shows spinner', () => {
cy.get('.loading-editors').then(function () {
expect(this.ipc.getUserEditor).to.be.called
cy.contains('File Opener Preference').click()
})
})

View File

@@ -135,5 +135,15 @@ describe('shortcuts', function () {
cy.get('button.stop').trigger('mouseover')
cy.get('.cy-tooltip').should('have.text', 'Stop Running S')
})
it('does not run shortcut if modifier keys are pressed', () => {
['{ctrl+f}', '{alt+f}', '{shift+f}', '{meta+f}'].forEach((text) => {
cy.get('body').type(text)
})
cy.then(() => {
expect(runner.emit).not.to.have.been.calledWith('focus:tests')
})
})
})
})

View File

@@ -1,5 +1,5 @@
// @ts-ignore
import dom from '@packages/driver/src/dom'
import $dom from '@packages/driver/src/dom'
import events from './events'
import appState from './app-state'
import { action } from 'mobx'
@@ -16,7 +16,10 @@ class Shortcuts {
_handleKeyDownEvent (event: KeyboardEvent) {
// if typing into an input, textarea, etc, don't trigger any shortcuts
// @ts-ignore
if (dom.isTextLike(event.target)) return
const isTextLike = $dom.isTextLike(event.target)
const isAnyModifierKeyPressed = event.altKey || event.ctrlKey || event.shiftKey || event.metaKey
if (isAnyModifierKeyPressed || isTextLike) return
switch (event.key) {
case 'r': !appState.studioActive && events.emit('restart')