mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 10:12:11 +00:00
Fix keybinding conflict (#1630)
This commit is contained in:
@@ -182,14 +182,3 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
|
|||||||
commandId: 'Workspace.ToggleFocusMode'
|
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'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
|
|||||||
import { computed, Ref, ref, toRaw } from 'vue'
|
import { computed, Ref, ref, toRaw } from 'vue'
|
||||||
import { Keybinding, KeyCombo } from '@/types/keyBindingTypes'
|
import { Keybinding, KeyCombo } from '@/types/keyBindingTypes'
|
||||||
import { useSettingStore } from './settingStore'
|
import { useSettingStore } from './settingStore'
|
||||||
import { CORE_KEYBINDINGS, DEPRECATED_KEYBINDINGS } from './coreKeybindings'
|
import { CORE_KEYBINDINGS } from './coreKeybindings'
|
||||||
import type { ComfyExtension } from '@/types/comfy'
|
import type { ComfyExtension } from '@/types/comfy'
|
||||||
|
|
||||||
export class KeybindingImpl implements Keybinding {
|
export class KeybindingImpl implements Keybinding {
|
||||||
@@ -121,8 +121,7 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
|||||||
|
|
||||||
const keybindingByKeyCombo = computed<Record<string, KeybindingImpl>>(() => {
|
const keybindingByKeyCombo = computed<Record<string, KeybindingImpl>>(() => {
|
||||||
const result: Record<string, KeybindingImpl> = {
|
const result: Record<string, KeybindingImpl> = {
|
||||||
...defaultKeybindings.value,
|
...defaultKeybindings.value
|
||||||
...userKeybindings.value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const keybinding of Object.values(userUnsetKeybindings.value)) {
|
for (const keybinding of Object.values(userUnsetKeybindings.value)) {
|
||||||
@@ -131,7 +130,11 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
|||||||
delete result[serializedCombo]
|
delete result[serializedCombo]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
...userKeybindings.value
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const keybindings = computed<KeybindingImpl[]>(() =>
|
const keybindings = computed<KeybindingImpl[]>(() =>
|
||||||
@@ -215,13 +218,13 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
|||||||
addKeybinding(userKeybindings, keybinding, { existOk: true })
|
addKeybinding(userKeybindings, keybinding, { existOk: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
const deprecatedKeybindings = DEPRECATED_KEYBINDINGS.map(
|
|
||||||
(k) => new KeybindingImpl(k)
|
|
||||||
)
|
|
||||||
function unsetKeybinding(keybinding: KeybindingImpl) {
|
function unsetKeybinding(keybinding: KeybindingImpl) {
|
||||||
const serializedCombo = keybinding.combo.serialize()
|
const serializedCombo = keybinding.combo.serialize()
|
||||||
if (!(serializedCombo in keybindingByKeyCombo.value)) {
|
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)) {
|
if (userKeybindings.value[serializedCombo]?.equals(keybinding)) {
|
||||||
@@ -234,13 +237,7 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deprecatedKeybindings.some((k) => k.equals(keybinding))) {
|
throw new Error(`Unknown keybinding: ${JSON.stringify(keybinding)}`)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
console.warn(
|
|
||||||
`Trying to unset non-exist keybinding: ${JSON.stringify(keybinding)}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -160,4 +160,76 @@ describe('useKeybindingStore', () => {
|
|||||||
defaultKeybinding
|
defaultKeybinding
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should accept same keybinding from default and user', () => {
|
||||||
|
const store = useKeybindingStore()
|
||||||
|
const keybinding = new KeybindingImpl({
|
||||||
|
commandId: 'test.command',
|
||||||
|
combo: { key: 'J', ctrl: true }
|
||||||
|
})
|
||||||
|
// Add default keybinding.
|
||||||
|
// This can happen when we change default keybindings.
|
||||||
|
store.addDefaultKeybinding(keybinding)
|
||||||
|
// Add user keybinding.
|
||||||
|
store.addUserKeybinding(keybinding)
|
||||||
|
|
||||||
|
expect(store.keybindings).toHaveLength(1)
|
||||||
|
expect(store.getKeybinding(keybinding.combo)).toEqual(keybinding)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should keep previously customized keybindings after default keybindings change', () => {
|
||||||
|
// Initially command 'foo' was bound to 'K, Ctrl'. User unset it and bound the
|
||||||
|
// command to 'A, Ctrl'.
|
||||||
|
// Now we change the default keybindings of 'foo' to 'A, Ctrl'.
|
||||||
|
// The user customized keybinding should be kept.
|
||||||
|
const store = useKeybindingStore()
|
||||||
|
|
||||||
|
const userUnsetKeybindings = [
|
||||||
|
new KeybindingImpl({
|
||||||
|
commandId: 'foo',
|
||||||
|
combo: { key: 'K', ctrl: true }
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
||||||
|
const userNewKeybindings = [
|
||||||
|
new KeybindingImpl({
|
||||||
|
commandId: 'foo',
|
||||||
|
combo: { key: 'A', ctrl: true }
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
||||||
|
const newCoreKeybindings = [
|
||||||
|
new KeybindingImpl({
|
||||||
|
commandId: 'foo',
|
||||||
|
combo: { key: 'A', ctrl: true }
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const keybinding of newCoreKeybindings) {
|
||||||
|
store.addDefaultKeybinding(keybinding)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(store.keybindings).toHaveLength(1)
|
||||||
|
expect(store.getKeybinding(userNewKeybindings[0].combo)).toEqual(
|
||||||
|
userNewKeybindings[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
for (const keybinding of userUnsetKeybindings) {
|
||||||
|
store.unsetKeybinding(keybinding)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(store.keybindings).toHaveLength(1)
|
||||||
|
expect(store.getKeybinding(userNewKeybindings[0].combo)).toEqual(
|
||||||
|
userNewKeybindings[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
for (const keybinding of userNewKeybindings) {
|
||||||
|
store.addUserKeybinding(keybinding)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(store.keybindings).toHaveLength(1)
|
||||||
|
expect(store.getKeybinding(userNewKeybindings[0].combo)).toEqual(
|
||||||
|
userNewKeybindings[0]
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user