Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ function isOverridden(id: string): boolean {
return shortcutOverrides.value[id] !== undefined
}

function getDefaultKey(id: string): string | undefined {
for (const cmd of commandsCtx.commands) {
if (cmd.id === id)
return cmd.keybindings?.[0]?.key
if (cmd.children) {
const child = cmd.children.find(c => c.id === id)
if (child)
return child.keybindings?.[0]?.key
}
}
}

function clearShortcut(commandId: string) {
commandsCtx.settings.mutate((state) => {
state.commandShortcuts[commandId] = []
Expand Down Expand Up @@ -187,9 +199,19 @@ function onEditorKeyDown(e: KeyboardEvent) {
function saveEditor() {
if (!editorCommandId.value || !editorCanSave.value)
return
commandsCtx.settings.mutate((state) => {
state.commandShortcuts[editorCommandId.value!] = [{ key: editorComposedKey.value }]
})
const defaultKey = getDefaultKey(editorCommandId.value)
if (editorComposedKey.value === defaultKey) {
if (isOverridden(editorCommandId.value)) {
commandsCtx.settings.mutate((state) => {
delete state.commandShortcuts[editorCommandId.value!]
})
}
}
else {
commandsCtx.settings.mutate((state) => {
state.commandShortcuts[editorCommandId.value!] = [{ key: editorComposedKey.value }]
})
}
closeEditor()
}

Expand Down
Loading