Fix keybinding conflict (#1630)

This commit is contained in:
Chenlei Hu
2024-11-21 11:49:57 -05:00
committed by GitHub
parent 479d1b28c7
commit 886c40a69a
3 changed files with 84 additions and 26 deletions

View File

@@ -182,14 +182,3 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
commandId: 'Workspace.ToggleFocusMode'
}
]
export const DEPRECATED_KEYBINDINGS: Keybinding[] = [
// Ctrl+S is now used for saving the workflow after v1.4.6.
{
combo: {
key: 's',
ctrl: true
},
commandId: 'Comfy.ExportWorkflow'
}
]

View File

@@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
import { computed, Ref, ref, toRaw } from 'vue'
import { Keybinding, KeyCombo } from '@/types/keyBindingTypes'
import { useSettingStore } from './settingStore'
import { CORE_KEYBINDINGS, DEPRECATED_KEYBINDINGS } from './coreKeybindings'
import { CORE_KEYBINDINGS } from './coreKeybindings'
import type { ComfyExtension } from '@/types/comfy'
export class KeybindingImpl implements Keybinding {
@@ -121,8 +121,7 @@ export const useKeybindingStore = defineStore('keybinding', () => {
const keybindingByKeyCombo = computed<Record<string, KeybindingImpl>>(() => {
const result: Record<string, KeybindingImpl> = {
...defaultKeybindings.value,
...userKeybindings.value
...defaultKeybindings.value
}
for (const keybinding of Object.values(userUnsetKeybindings.value)) {
@@ -131,7 +130,11 @@ export const useKeybindingStore = defineStore('keybinding', () => {
delete result[serializedCombo]
}
}
return result
return {
...result,
...userKeybindings.value
}
})
const keybindings = computed<KeybindingImpl[]>(() =>
@@ -215,13 +218,13 @@ export const useKeybindingStore = defineStore('keybinding', () => {
addKeybinding(userKeybindings, keybinding, { existOk: true })
}
const deprecatedKeybindings = DEPRECATED_KEYBINDINGS.map(
(k) => new KeybindingImpl(k)
)
function unsetKeybinding(keybinding: KeybindingImpl) {
const serializedCombo = keybinding.combo.serialize()
if (!(serializedCombo in keybindingByKeyCombo.value)) {
throw new Error(`Keybinding on ${keybinding.combo} does not exist`)
console.warn(
`Trying to unset non-exist keybinding: ${JSON.stringify(keybinding)}`
)
return
}
if (userKeybindings.value[serializedCombo]?.equals(keybinding)) {
@@ -234,13 +237,7 @@ export const useKeybindingStore = defineStore('keybinding', () => {
return
}
if (deprecatedKeybindings.some((k) => k.equals(keybinding))) {
return
}
console.warn(
`Trying to unset non-exist keybinding: ${JSON.stringify(keybinding)}`
)
throw new Error(`Unknown keybinding: ${JSON.stringify(keybinding)}`)
}
/**