From ea6c9e7ca5f2a265194111316298e5452c4883e8 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 7 Jan 2025 10:33:23 -0500 Subject: [PATCH] Replace unset unknown keybinding error with warn (#2186) --- src/stores/keybindingStore.ts | 2 +- tests-ui/tests/store/keybindingStore.test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/stores/keybindingStore.ts b/src/stores/keybindingStore.ts index bcdc2cf2bd..90cf229448 100644 --- a/src/stores/keybindingStore.ts +++ b/src/stores/keybindingStore.ts @@ -227,7 +227,7 @@ export const useKeybindingStore = defineStore('keybinding', () => { return } - throw new Error(`Unknown keybinding: ${JSON.stringify(keybinding)}`) + console.warn(`Unset unknown keybinding: ${JSON.stringify(keybinding)}`) } /** diff --git a/tests-ui/tests/store/keybindingStore.test.ts b/tests-ui/tests/store/keybindingStore.test.ts index dfcd3789a6..3b30c40514 100644 --- a/tests-ui/tests/store/keybindingStore.test.ts +++ b/tests-ui/tests/store/keybindingStore.test.ts @@ -149,6 +149,24 @@ describe('useKeybindingStore', () => { expect(() => store.unsetKeybinding(keybinding)).not.toThrow() }) + it('should not throw an error when unsetting unknown keybinding', () => { + const store = useKeybindingStore() + const keybinding = new KeybindingImpl({ + commandId: 'test.command', + combo: { key: 'I', ctrl: true } + }) + store.addUserKeybinding(keybinding) + + expect(() => + store.unsetKeybinding( + new KeybindingImpl({ + commandId: 'test.foo', + combo: { key: 'I', ctrl: true } + }) + ) + ).not.toThrow() + }) + it('should remove unset keybinding when adding back a default keybinding', () => { const store = useKeybindingStore() const defaultKeybinding = new KeybindingImpl({