Skip to content

Commit 014aac2

Browse files
committed
fix: prevent shortcut editor from creating override when unchanged
Compare edited key against default before saving. Skip writing to commandShortcuts when the value matches the preset, avoiding the false "modified" indicator (reset icon) on unchanged shortcuts.
1 parent e4feaea commit 014aac2

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

packages/core/src/client/webcomponents/components/views-builtin/SettingsShortcuts.vue

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ function isOverridden(id: string): boolean {
5858
return shortcutOverrides.value[id] !== undefined
5959
}
6060
61+
function getDefaultKey(id: string): string | undefined {
62+
for (const cmd of commandsCtx.commands) {
63+
if (cmd.id === id)
64+
return cmd.keybindings?.[0]?.key
65+
if (cmd.children) {
66+
const child = cmd.children.find(c => c.id === id)
67+
if (child)
68+
return child.keybindings?.[0]?.key
69+
}
70+
}
71+
}
72+
6173
function clearShortcut(commandId: string) {
6274
commandsCtx.settings.mutate((state) => {
6375
state.commandShortcuts[commandId] = []
@@ -187,9 +199,19 @@ function onEditorKeyDown(e: KeyboardEvent) {
187199
function saveEditor() {
188200
if (!editorCommandId.value || !editorCanSave.value)
189201
return
190-
commandsCtx.settings.mutate((state) => {
191-
state.commandShortcuts[editorCommandId.value!] = [{ key: editorComposedKey.value }]
192-
})
202+
const defaultKey = getDefaultKey(editorCommandId.value)
203+
if (editorComposedKey.value === defaultKey) {
204+
if (isOverridden(editorCommandId.value)) {
205+
commandsCtx.settings.mutate((state) => {
206+
delete state.commandShortcuts[editorCommandId.value!]
207+
})
208+
}
209+
}
210+
else {
211+
commandsCtx.settings.mutate((state) => {
212+
state.commandShortcuts[editorCommandId.value!] = [{ key: editorComposedKey.value }]
213+
})
214+
}
193215
closeEditor()
194216
}
195217

0 commit comments

Comments
 (0)