Skip to content

Commit

Permalink
Rename Keybinding.targetSelector to targetElementId (#2169)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
huchenlei and github-actions authored Jan 5, 2025
1 parent 477f4b2 commit 975c224
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/constants/coreKeybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
alt: true
},
commandId: 'Comfy.Canvas.ZoomIn',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
Expand All @@ -104,7 +104,7 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
shift: true
},
commandId: 'Comfy.Canvas.ZoomIn',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
// For number pad '+'
{
Expand All @@ -113,53 +113,53 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
alt: true
},
commandId: 'Comfy.Canvas.ZoomIn',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
key: '-',
alt: true
},
commandId: 'Comfy.Canvas.ZoomOut',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
key: '.'
},
commandId: 'Comfy.Canvas.FitView',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
key: 'p'
},
commandId: 'Comfy.Canvas.ToggleSelected.Pin',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
key: 'c',
alt: true
},
commandId: 'Comfy.Canvas.ToggleSelectedNodes.Collapse',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
key: 'b',
ctrl: true
},
commandId: 'Comfy.Canvas.ToggleSelectedNodes.Bypass',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
key: 'm',
ctrl: true
},
commandId: 'Comfy.Canvas.ToggleSelectedNodes.Mute',
targetSelector: '#graph-canvas'
targetElementId: 'graph-canvas'
},
{
combo: {
Expand Down
6 changes: 6 additions & 0 deletions src/locales/en/nodeDefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
},
"type": {
"name": "type"
},
"device": {
"name": "device"
}
}
},
Expand Down Expand Up @@ -1221,6 +1224,9 @@
},
"type": {
"name": "type"
},
"device": {
"name": "device"
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/locales/fr/nodeDefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
"clip_name": {
"name": "clip_name"
},
"device": {
"name": "appareil"
},
"type": {
"name": "type"
}
Expand Down Expand Up @@ -1219,6 +1222,9 @@
"clip_name2": {
"name": "nom_clip2"
},
"device": {
"name": "appareil"
},
"type": {
"name": "type"
}
Expand Down
6 changes: 6 additions & 0 deletions src/locales/ja/nodeDefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
"clip_name": {
"name": "clip名"
},
"device": {
"name": "デバイス"
},
"type": {
"name": "タイプ"
}
Expand Down Expand Up @@ -1219,6 +1222,9 @@
"clip_name2": {
"name": "clip_name2"
},
"device": {
"name": "デバイス"
},
"type": {
"name": "タイプ"
}
Expand Down
6 changes: 6 additions & 0 deletions src/locales/ko/nodeDefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
"clip_name": {
"name": "CLIP 파일명"
},
"device": {
"name": "장치"
},
"type": {
"name": "유형"
}
Expand Down Expand Up @@ -1219,6 +1222,9 @@
"clip_name2": {
"name": "CLIP 파일명2"
},
"device": {
"name": "장치"
},
"type": {
"name": "유형"
}
Expand Down
6 changes: 6 additions & 0 deletions src/locales/ru/nodeDefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
"clip_name": {
"name": "имя_clip"
},
"device": {
"name": "устройство"
},
"type": {
"name": "тип"
}
Expand Down Expand Up @@ -1219,6 +1222,9 @@
"clip_name2": {
"name": "clip_name2"
},
"device": {
"name": "устройство"
},
"type": {
"name": "тип"
}
Expand Down
6 changes: 6 additions & 0 deletions src/locales/zh/nodeDefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
"clip_name": {
"name": "CLIP名称"
},
"device": {
"name": "设备"
},
"type": {
"name": "类型"
}
Expand Down Expand Up @@ -1219,6 +1222,9 @@
"clip_name2": {
"name": "CLIP名称2"
},
"device": {
"name": "设备"
},
"type": {
"name": "类型"
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export class ComfyApp {
const keyCombo = KeyComboImpl.fromEvent(e)
const keybindingStore = useKeybindingStore()
const keybinding = keybindingStore.getKeybinding(keyCombo)
if (keybinding && keybinding.targetSelector === '#graph-canvas') {
if (keybinding && keybinding.targetElementId === 'graph-canvas') {
useCommandStore().execute(keybinding.commandId)
block_default = true
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/keybindingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useKeybindingService = () => {
}

const keybinding = keybindingStore.getKeybinding(keyCombo)
if (keybinding && keybinding.targetSelector !== '#graph-canvas') {
if (keybinding && keybinding.targetElementId !== 'graph-canvas') {
// Prevent default browser behavior first, then execute the command
event.preventDefault()
await commandStore.execute(keybinding.commandId)
Expand Down
6 changes: 3 additions & 3 deletions src/stores/keybindingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { KeyCombo, Keybinding } from '@/types/keyBindingTypes'
export class KeybindingImpl implements Keybinding {
commandId: string
combo: KeyComboImpl
targetSelector?: string
targetElementId?: string

constructor(obj: Keybinding) {
this.commandId = obj.commandId
this.combo = new KeyComboImpl(obj.combo)
this.targetSelector = obj.targetSelector
this.targetElementId = obj.targetElementId
}

equals(other: unknown): boolean {
Expand All @@ -20,7 +20,7 @@ export class KeybindingImpl implements Keybinding {
return raw instanceof KeybindingImpl
? this.commandId === raw.commandId &&
this.combo.equals(raw.combo) &&
this.targetSelector === raw.targetSelector
this.targetElementId === raw.targetElementId
: false
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/keyBindingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const zKeyCombo = z.object({
export const zKeybinding = z.object({
commandId: z.string(),
combo: zKeyCombo,
// Optional target element CSS selector to limit keybinding to.
// Optional target element ID to limit keybinding to.
// Note: Currently only used to distinguish between global keybindings
// and litegraph canvas keybindings.
// Do NOT use this field in extensions as it has no effect.
targetSelector: z.string().optional()
targetElementId: z.string().optional()
})

// Infer types from schemas
Expand Down

0 comments on commit 975c224

Please sign in to comment.