Ignore reserved keybindings when typing in text input (#2514)

Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
bymyself
2025-02-12 09:15:19 -07:00
committed by GitHub
parent 150b4341b2
commit 46f0733ae7
4 changed files with 71 additions and 2 deletions

View File

@@ -35,4 +35,20 @@ test.describe('Keybindings', () => {
true
)
})
test('Should not trigger keybinding reserved by text input when typing in input fields', async ({
comfyPage
}) => {
await comfyPage.registerKeybinding({ key: 'Ctrl+v' }, () => {
window['TestCommand'] = true
})
const textBox = comfyPage.widgetTextBox
await textBox.click()
await textBox.press('Control+v')
await expect(textBox).toBeFocused()
expect(await comfyPage.page.evaluate(() => window['TestCommand'])).toBe(
undefined
)
})
})

View File

@@ -0,0 +1,35 @@
export const RESERVED_BY_TEXT_INPUT = new Set([
'Ctrl + a',
'Ctrl + c',
'Ctrl + v',
'Ctrl + x',
'Ctrl + z',
'Ctrl + y',
'Ctrl + p',
'Enter',
'Shift + Enter',
'Ctrl + Backspace',
'Ctrl + Delete',
'Home',
'Ctrl + Home',
'Ctrl + Shift + Home',
'End',
'Ctrl + End',
'Ctrl + Shift + End',
'PageUp',
'PageDown',
'Shift + PageUp',
'Shift + PageDown',
'ArrowLeft',
'Ctrl + ArrowLeft',
'Shift + ArrowLeft',
'Ctrl + Shift + ArrowLeft',
'ArrowRight',
'Ctrl + ArrowRight',
'Shift + ArrowRight',
'Ctrl + Shift + ArrowRight',
'ArrowUp',
'Shift + ArrowUp',
'ArrowDown',
'Shift + ArrowDown'
])

View File

@@ -18,10 +18,10 @@ export const useKeybindingService = () => {
return
}
// Ignore non-modifier keybindings if typing in input fields
// Ignore reserved or non-modifier keybindings if typing in input fields
const target = event.composedPath()[0] as HTMLElement
if (
!keyCombo.hasModifier &&
keyCombo.isReservedByTextInput &&
(target.tagName === 'TEXTAREA' ||
target.tagName === 'INPUT' ||
(target.tagName === 'SPAN' &&

View File

@@ -2,6 +2,7 @@ import _ from 'lodash'
import { defineStore } from 'pinia'
import { Ref, computed, ref, toRaw } from 'vue'
import { RESERVED_BY_TEXT_INPUT } from '@/constants/reservedKeyCombos'
import { KeyCombo, Keybinding } from '@/types/keyBindingTypes'
export class KeybindingImpl implements Keybinding {
@@ -76,6 +77,23 @@ export class KeyComboImpl implements KeyCombo {
return ['Control', 'Meta', 'Alt', 'Shift'].includes(this.key)
}
get modifierCount(): number {
const modifiers = [this.ctrl, this.alt, this.shift]
return modifiers.reduce((acc, cur) => acc + Number(cur), 0)
}
get isShiftOnly(): boolean {
return this.shift && this.modifierCount === 1
}
get isReservedByTextInput(): boolean {
return (
!this.hasModifier ||
this.isShiftOnly ||
RESERVED_BY_TEXT_INPUT.has(this.toString())
)
}
getKeySequences(): string[] {
const sequences: string[] = []
if (this.ctrl) {