mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 19:21:54 +00:00
Reland 'Bind Ctrl+s to Comfy.SaveWorkflow' (#1618)
This commit is contained in:
@@ -59,7 +59,7 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
|
|||||||
key: 's',
|
key: 's',
|
||||||
ctrl: true
|
ctrl: true
|
||||||
},
|
},
|
||||||
commandId: 'Comfy.ExportWorkflow'
|
commandId: 'Comfy.SaveWorkflow'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
combo: {
|
combo: {
|
||||||
@@ -182,3 +182,14 @@ 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 } from './coreKeybindings'
|
import { CORE_KEYBINDINGS, DEPRECATED_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 {
|
||||||
@@ -215,6 +215,9 @@ 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)) {
|
||||||
@@ -231,7 +234,13 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`NOT_REACHED`)
|
if (deprecatedKeybindings.some((k) => k.equals(keybinding))) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn(
|
||||||
|
`Trying to unset non-exist keybinding: ${JSON.stringify(keybinding)}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -126,14 +126,14 @@ describe('useKeybindingStore', () => {
|
|||||||
expect(store.getKeybinding(keybinding2.combo)).toEqual(keybinding2)
|
expect(store.getKeybinding(keybinding2.combo)).toEqual(keybinding2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an error when unsetting non-existent keybindings', () => {
|
it('should not throw an error when unsetting non-existent keybindings', () => {
|
||||||
const store = useKeybindingStore()
|
const store = useKeybindingStore()
|
||||||
const keybinding = new KeybindingImpl({
|
const keybinding = new KeybindingImpl({
|
||||||
commandId: 'test.command',
|
commandId: 'test.command',
|
||||||
combo: { key: 'H', alt: true, shift: true }
|
combo: { key: 'H', alt: true, shift: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(() => store.unsetKeybinding(keybinding)).toThrow()
|
expect(() => store.unsetKeybinding(keybinding)).not.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove unset keybinding when adding back a default keybinding', () => {
|
it('should remove unset keybinding when adding back a default keybinding', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user