mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
Ignore reserved keybindings when typing in text input (#2514)
Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
35
src/constants/reservedKeyCombos.ts
Normal file
35
src/constants/reservedKeyCombos.ts
Normal 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'
|
||||
])
|
||||
@@ -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' &&
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user