Skip to content

Commit e123295

Browse files
Fix saved keybinding persistence (#2176)
1 parent 613b446 commit e123295

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

browser_tests/dialog.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@playwright/test'
22

3+
import { Keybinding } from '../src/types/keyBindingTypes'
34
import { comfyPageFixture as test } from './fixtures/ComfyPage'
45

56
test.describe('Load workflow warning', () => {
@@ -103,4 +104,52 @@ test.describe('Settings', () => {
103104
expect(await comfyPage.getSetting('Comfy.Graph.ZoomSpeed')).toBe(maxSpeed)
104105
})
105106
})
107+
108+
test('Should persist keybinding setting', async ({ comfyPage }) => {
109+
// Open the settings dialog
110+
await comfyPage.page.keyboard.press('Control+,')
111+
await comfyPage.page.waitForSelector('.settings-container')
112+
113+
// Open the keybinding tab
114+
await comfyPage.page.getByLabel('Keybinding').click()
115+
await comfyPage.page.waitForSelector(
116+
'[placeholder="Search Keybindings..."]'
117+
)
118+
119+
// Focus the 'New Blank Workflow' row
120+
const newBlankWorkflowRow = comfyPage.page.locator('tr', {
121+
has: comfyPage.page.getByRole('cell', { name: 'New Blank Workflow' })
122+
})
123+
await newBlankWorkflowRow.click()
124+
125+
// Click edit button
126+
const editKeybindingButton = newBlankWorkflowRow.locator('.pi-pencil')
127+
await editKeybindingButton.click()
128+
129+
// Set new keybinding
130+
const input = comfyPage.page.getByPlaceholder('Press keys for new binding')
131+
await input.press('Alt+n')
132+
133+
const requestPromise = comfyPage.page.waitForRequest(
134+
'**/api/settings/Comfy.Keybinding.NewBindings'
135+
)
136+
137+
// Save keybinding
138+
const saveButton = comfyPage.page
139+
.getByLabel('Comfy.NewBlankWorkflow')
140+
.getByLabel('Save')
141+
await saveButton.click()
142+
143+
const request = await requestPromise
144+
const expectedSetting: Keybinding = {
145+
commandId: 'Comfy.NewBlankWorkflow',
146+
combo: {
147+
key: 'n',
148+
ctrl: false,
149+
alt: true,
150+
shift: false
151+
}
152+
}
153+
expect(request.postData()).toContain(JSON.stringify(expectedSetting))
154+
})
106155
})

src/services/keybindingService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ export const useKeybindingService = () => {
8484
// Allow setting multiple values at once in settingStore
8585
await settingStore.set(
8686
'Comfy.Keybinding.NewBindings',
87-
Object.values(keybindingStore.userKeybindings.value)
87+
Object.values(keybindingStore.getUserKeybindings())
8888
)
8989
await settingStore.set(
9090
'Comfy.Keybinding.UnsetBindings',
91-
Object.values(keybindingStore.userUnsetKeybindings.value)
91+
Object.values(keybindingStore.getUserUnsetKeybindings())
9292
)
9393
}
9494

src/stores/keybindingStore.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ export const useKeybindingStore = defineStore('keybinding', () => {
105105
*/
106106
const userUnsetKeybindings = ref<Record<string, KeybindingImpl>>({})
107107

108+
/**
109+
* Get user-defined keybindings.
110+
*/
111+
function getUserKeybindings() {
112+
return userKeybindings.value
113+
}
114+
115+
/**
116+
* Get user-defined keybindings that unset default keybindings.
117+
*/
118+
function getUserUnsetKeybindings() {
119+
return userUnsetKeybindings.value
120+
}
121+
108122
const keybindingByKeyCombo = computed<Record<string, KeybindingImpl>>(() => {
109123
const result: Record<string, KeybindingImpl> = {
110124
...defaultKeybindings.value
@@ -262,8 +276,8 @@ export const useKeybindingStore = defineStore('keybinding', () => {
262276

263277
return {
264278
keybindings,
265-
userKeybindings,
266-
userUnsetKeybindings,
279+
getUserKeybindings,
280+
getUserUnsetKeybindings,
267281
getKeybinding,
268282
getKeybindingsByCommandId,
269283
getKeybindingByCommandId,

0 commit comments

Comments
 (0)