mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-13 09:00:16 +00:00
feat: Warn when binding browser-reserved shortcuts (#9406)
## Summary Show a non-blocking warning in the keybinding edit dialog when users try to bind shortcuts that browsers intercept (e.g. Ctrl+T, Ctrl+W, F12). ## Changes - **What**: Add `RESERVED_BY_BROWSER` set of known browser-intercepted shortcuts, `isBrowserReserved` getter on `KeyComboImpl`, and a warning `<Message>` in the keybinding edit dialog. Users can still save the binding. ## Review Focus Whether the list of browser-reserved shortcuts is comprehensive enough, and whether a non-blocking warning (vs blocking) is the right UX choice. ## Before https://github.com/user-attachments/assets/5abfc062-5ed1-4fcd-b394-ff98221d82a8 ## After https://github.com/user-attachments/assets/12a49e24-051f-4579-894a-164dbf1cb7b7 Fixes #1087 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9406-feat-Warn-when-binding-browser-reserved-shortcuts-31a6d73d36508162a021e88ab76914f6) by [Unito](https://www.unito.io) --------- Co-authored-by: Kelly Yang <124ykl@gmail.com> Co-authored-by: Alexander Brown <drjkl@comfy.org> Co-authored-by: Christian Byrne <cbyrne@comfy.org> Co-authored-by: jaeone94 <89377375+jaeone94@users.noreply.github.com> Co-authored-by: Benjamin Lu <benjaminlu1107@gmail.com> Co-authored-by: Comfy Org PR Bot <snomiao+comfy-pr@gmail.com> Co-authored-by: christian-byrne <72887196+christian-byrne@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: AustinMroz <austin@comfy.org> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Terry Jia <terryjia88@gmail.com> Co-authored-by: Alexander Brown <DrJKL0424@gmail.com> Co-authored-by: Dante <bunggl@naver.com> Co-authored-by: Deep Mehta <42841935+deepme987@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Jin Yi <jin12cc@gmail.com> Co-authored-by: Yourz <crazilou@vip.qq.com> Co-authored-by: pythongosssss <125205205+pythongosssss@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
37c6ddfcd9
commit
ef477d0381
39
src/platform/keybindings/keyCombo.test.ts
Normal file
39
src/platform/keybindings/keyCombo.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { KeyComboImpl } from './keyCombo'
|
||||
|
||||
describe('KeyComboImpl', () => {
|
||||
describe('isBrowserReserved', () => {
|
||||
it.each([
|
||||
{ key: 't', ctrl: true, label: 'Ctrl + t' },
|
||||
{ key: 'w', ctrl: true, label: 'Ctrl + w' },
|
||||
{ key: 'F12', label: 'F12' },
|
||||
{ key: 'n', ctrl: true, shift: true, label: 'Ctrl + Shift + n' },
|
||||
{ key: 'r', ctrl: true, label: 'Ctrl + r' },
|
||||
{ key: 'F5', label: 'F5' }
|
||||
])('returns true for $label', ({ key, ctrl, shift }) => {
|
||||
const combo = new KeyComboImpl({
|
||||
key,
|
||||
ctrl: ctrl ?? false,
|
||||
alt: false,
|
||||
shift: shift ?? false
|
||||
})
|
||||
expect(combo.isBrowserReserved).toBe(true)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ key: 'k', ctrl: true, label: 'Ctrl + k' },
|
||||
{ key: 's', alt: true, label: 'Alt + s' },
|
||||
{ key: 'z', ctrl: true, label: 'Ctrl + z' },
|
||||
{ key: 'F6', label: 'F6' }
|
||||
])('returns false for $label', ({ key, ctrl, alt }) => {
|
||||
const combo = new KeyComboImpl({
|
||||
key,
|
||||
ctrl: ctrl ?? false,
|
||||
alt: alt ?? false,
|
||||
shift: false
|
||||
})
|
||||
expect(combo.isBrowserReserved).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { toRaw } from 'vue'
|
||||
|
||||
import { RESERVED_BY_TEXT_INPUT } from './reserved'
|
||||
import { RESERVED_BY_BROWSER, RESERVED_BY_TEXT_INPUT } from './reserved'
|
||||
import type { KeyCombo } from './types'
|
||||
|
||||
export class KeyComboImpl implements KeyCombo {
|
||||
@@ -61,11 +61,15 @@ export class KeyComboImpl implements KeyCombo {
|
||||
return this.shift && this.modifierCount === 1
|
||||
}
|
||||
|
||||
get isBrowserReserved(): boolean {
|
||||
return RESERVED_BY_BROWSER.has(toNormalizedString(this))
|
||||
}
|
||||
|
||||
get isReservedByTextInput(): boolean {
|
||||
return (
|
||||
!this.hasModifier ||
|
||||
this.isShiftOnly ||
|
||||
RESERVED_BY_TEXT_INPUT.has(this.toString())
|
||||
RESERVED_BY_TEXT_INPUT.has(toNormalizedString(this))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -84,3 +88,12 @@ export class KeyComboImpl implements KeyCombo {
|
||||
return sequences
|
||||
}
|
||||
}
|
||||
|
||||
function toNormalizedString(combo: KeyComboImpl): string {
|
||||
const sequences: string[] = []
|
||||
if (combo.ctrl) sequences.push('Ctrl')
|
||||
if (combo.alt) sequences.push('Alt')
|
||||
if (combo.shift) sequences.push('Shift')
|
||||
sequences.push(combo.key.length === 1 ? combo.key.toLowerCase() : combo.key)
|
||||
return sequences.join(' + ')
|
||||
}
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
export const RESERVED_BY_BROWSER = new Set([
|
||||
'Ctrl + t', // New tab (all browsers)
|
||||
'Ctrl + w', // Close tab (all browsers)
|
||||
'Ctrl + n', // New window (all browsers)
|
||||
'Ctrl + Shift + n', // New incognito/private window (all browsers)
|
||||
'Ctrl + Tab', // Next tab (all browsers)
|
||||
'Ctrl + Shift + Tab', // Previous tab (all browsers)
|
||||
'Ctrl + Shift + Delete', // Clear browsing data (Chrome, Edge, Firefox)
|
||||
'Ctrl + h', // History (all browsers)
|
||||
'Ctrl + j', // Downloads (Chrome, Edge)
|
||||
'Ctrl + d', // Bookmark current page (all browsers)
|
||||
'Ctrl + Shift + b', // Toggle bookmarks bar (Chrome, Edge)
|
||||
'Ctrl + Shift + o', // Bookmarks manager (Chrome, Edge)
|
||||
'Ctrl + Shift + i', // DevTools (all browsers)
|
||||
'Ctrl + Shift + j', // DevTools console (Chrome, Edge)
|
||||
'F5', // Reload page (all browsers)
|
||||
'Ctrl + F5', // Hard reload (all browsers)
|
||||
'Ctrl + r', // Reload page (all browsers)
|
||||
'Ctrl + Shift + r', // Hard reload (all browsers)
|
||||
'F7', // Caret browsing (Firefox, Edge)
|
||||
'F11', // Toggle fullscreen (all browsers)
|
||||
'F12', // DevTools (all browsers)
|
||||
'Alt + F4' // Close window (Windows, all browsers)
|
||||
])
|
||||
|
||||
export const RESERVED_BY_TEXT_INPUT = new Set([
|
||||
'Ctrl + a',
|
||||
'Ctrl + c',
|
||||
|
||||
Reference in New Issue
Block a user