From 3ecc7960e897afc49a725ff0c83a9bf7670b8940 Mon Sep 17 00:00:00 2001 From: sei-tspencer Date: Wed, 30 Oct 2024 12:10:15 -0400 Subject: [PATCH] Dynamically bubble defined hotkeys out of editor and replace meta.p with control.p --- .../component/editor/editor.component.html | 48 +++++-------------- .../component/editor/editor.component.ts | 33 ++++++++++++- .../project-list/project-list.component.html | 2 + src/assets/config/settings.json | 29 ++++++++++- 4 files changed, 75 insertions(+), 37 deletions(-) diff --git a/src/app/editor/component/editor/editor.component.html b/src/app/editor/component/editor/editor.component.html index 4b9f5bdb..caf40efd 100644 --- a/src/app/editor/component/editor/editor.component.html +++ b/src/app/editor/component/editor/editor.component.html @@ -32,7 +32,7 @@ fontIcon="mdi-chevron-double-right" > - +
+
@@ -213,6 +190,7 @@ id="editor" class="code-editor" [options]="editorOptions" + (init)="editorInit($event)" [(ngModel)]="code" (ngModelChange)="codeChangedEventHandler($event)" > diff --git a/src/app/editor/component/editor/editor.component.ts b/src/app/editor/component/editor/editor.component.ts index c0648d08..2903fb13 100644 --- a/src/app/editor/component/editor/editor.component.ts +++ b/src/app/editor/component/editor/editor.component.ts @@ -29,6 +29,7 @@ import { ConfirmDialogService } from 'src/app/sei-cwd-common/confirm-dialog/serv import { CurrentUserQuery } from 'src/app/users/state'; import { FileQuery, FileService } from '../../../files/state'; import { ModuleQuery, ModuleService } from '../../../modules/state'; +import { ComnSettingsService } from '@cmusei/crucible-common'; const SIDEBAR_MIN_WIDTH = 300; @@ -82,7 +83,8 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy { private fileVersionQuery: FileVersionQuery, private currentUserQuery: CurrentUserQuery, private changeDetectorRef: ChangeDetectorRef, - private confirmDialog: ConfirmDialogService + private confirmDialog: ConfirmDialogService, + private settingsService: ComnSettingsService ) {} ngOnInit(): void { @@ -152,6 +154,35 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy { this.isSaved$ = this.fileQuery.selectIsSaved(this.fileId); } + editorInit(editor: any) { + // get the defined hot keys + const hotKeys = this.settingsService.settings.Hotkeys; + const bubbleKeys = []; + // create search strings for the defined hot keys that need to bubble out of the editor + // transforms control.x, alt.x, etc. to ctrl+X, alt+X, etc. + for (const [key, hk] of Object.entries(hotKeys)) { + const parts = (hk as any).keys.split('.'); + if (parts.length === 2) { + if (parts[0] === 'control') parts[0] = 'ctrl'; + bubbleKeys.push(parts[0] + '+' + parts[1].toUpperCase()); + } + } + // get the editor default key bindings + const bindings = + editor._standaloneKeybindingService._getResolver()._defaultKeybindings; + // set the editor key bindings to bubble the defined hot keys that would be intercepted + // by clearing the command and setting bubble to true + bindings.forEach((binding) => { + if ( + binding.keypressParts.length === 1 && + bubbleKeys.some((bk) => bk === binding.keypressParts[0]) + ) { + binding.command = ''; + binding.bubble = true; + } + }); + } + updateEditorOptions(file: ModelFile): void { let writable = false; diff --git a/src/app/project/component/project-home/project-list/project-list.component.html b/src/app/project/component/project-home/project-list/project-list.component.html index a8c35b48..f14dae49 100644 --- a/src/app/project/component/project-home/project-list/project-list.component.html +++ b/src/app/project/component/project-home/project-list/project-list.component.html @@ -89,6 +89,8 @@ + + diff --git a/src/assets/config/settings.json b/src/assets/config/settings.json index a377cc07..36a49e89 100644 --- a/src/assets/config/settings.json +++ b/src/assets/config/settings.json @@ -16,7 +16,7 @@ "AppTopBarText": "Caster", "Hotkeys": { "PROJECT_NEW": { - "keys": "meta.p", + "keys": "control.p", "group": "", "description": "New Project" }, @@ -43,6 +43,33 @@ "group": "Editor", "description": "Save a file", "allowIn": ["INPUT", "TEXTAREA"] + }, + "DISCARD_CHANGES": { + "keys": "control.q", + "group": "Editor", + "description": "Discard changes", + "allowIn": [ + "INPUT", + "TEXTAREA" + ] + }, + "FILE_MODULES": { + "keys": "alt.m", + "group": "Editor", + "description": "Show file modules", + "allowIn": [ + "INPUT", + "TEXTAREA" + ] + }, + "FILE_VERSIONS": { + "keys": "alt.v", + "group": "Editor", + "description": "Show file versions", + "allowIn": [ + "INPUT", + "TEXTAREA" + ] } } }