File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
packages/core/src/client/webcomponents/components/views-builtin Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff 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+
6173function clearShortcut(commandId : string ) {
6274 commandsCtx .settings .mutate ((state ) => {
6375 state .commandShortcuts [commandId ] = []
@@ -187,9 +199,19 @@ function onEditorKeyDown(e: KeyboardEvent) {
187199function 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
You can’t perform that action at this time.
0 commit comments