From 9e01628ffb42d9ddf0d091e2d8112445354ed426 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 6 Jul 2025 15:05:12 -0500 Subject: [PATCH] Restructured loading of editor modes; changed LSP config loading --- .../common/services/editor/editors.service.ts | 3 +- .../editor/lsp-manager/lsp-manager.service.ts | 7 +-- src/app/common/types/editor.type.ts | 5 ++ src/app/editor/code-view/view.base.ts | 11 ++-- src/app/editor/code-view/view.component.ts | 52 +++++++++++-------- src/app/editor/editors.component.html | 2 +- .../lsp-manager/lsp-manager.component.css | 1 + .../lsp-manager/lsp-manager.component.html | 4 +- .../lsp-manager/lsp-manager.component.ts | 23 ++++---- 9 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 src/app/common/types/editor.type.ts diff --git a/src/app/common/services/editor/editors.service.ts b/src/app/common/services/editor/editors.service.ts index 0af256b..c0270db 100644 --- a/src/app/common/services/editor/editors.service.ts +++ b/src/app/common/services/editor/editors.service.ts @@ -7,6 +7,7 @@ import { ServiceMessage } from '../../types/service-message.type'; import { EditorSettings } from "../../configs/editor.config"; import { NewtonFile } from '../../types/file.type'; +import { EditorType } from '../../types/editor.type'; @@ -38,7 +39,7 @@ export class EditorsService { } public set(uuid: string, component: CodeViewComponent) { - if (component.isMiniMap) { + if (component.mode == EditorType.MiniMap) { this.miniMapView = component; return; } diff --git a/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts b/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts index 161b5a1..f9e7491 100644 --- a/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts +++ b/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts @@ -19,12 +19,11 @@ export class LspManagerService { constructor() { - this.loadLSPService(); } - private loadLSPService() { - this.getLspConfigData().then((lspConfigData: string) => { + public loadLspConfigData(): Promise { + return this.getLspConfigData().then((lspConfigData: string) => { this.lspConfigData = JSON.parse(lspConfigData); if (this.lspConfigData["message"]) { @@ -35,6 +34,8 @@ export class LspManagerService { this.lspConfigData = {}; } + + return lspConfigData; }); } diff --git a/src/app/common/types/editor.type.ts b/src/app/common/types/editor.type.ts new file mode 100644 index 0000000..1c109dd --- /dev/null +++ b/src/app/common/types/editor.type.ts @@ -0,0 +1,5 @@ +export abstract class EditorType { + static MiniMap: string = "mini-map"; + static ReadOnly: string = "read-only"; + static Standalone: string = "standalone"; +} \ No newline at end of file diff --git a/src/app/editor/code-view/view.base.ts b/src/app/editor/code-view/view.base.ts index 2ff7fef..4b41fc6 100644 --- a/src/app/editor/code-view/view.base.ts +++ b/src/app/editor/code-view/view.base.ts @@ -19,9 +19,9 @@ import { ServiceMessage } from '../../common/types/service-message.type'; @Directive() export class CodeViewBase { - public uuid: string = uuid.v4(); - @Input() public isDefault: boolean = false; - @Input() public isMiniMap: boolean = false; + public uuid: string = uuid.v4(); + @Input() public isDefault: boolean = false; + @Input() public mode: string = ""; public leftSiblingUUID!: string; public rightSiblingUUID!: string; @@ -185,6 +185,11 @@ export class CodeViewBase { window.main.toggleFullScreen(); } + public setAsReadOnly() { + this.editor.setReadOnly(true); + this.editor.setShowPrintMargin(false); + } + public setAsMiniMapView() { this.editor.renderer.showLineNumbers = false; this.editor.renderer.setShowGutter(false); diff --git a/src/app/editor/code-view/view.component.ts b/src/app/editor/code-view/view.component.ts index fc9b388..543394c 100644 --- a/src/app/editor/code-view/view.component.ts +++ b/src/app/editor/code-view/view.component.ts @@ -16,6 +16,7 @@ import "ace-builds/src-min-noconflict/theme-gruvbox"; import { CodeViewBase } from './view.base'; import { NewtonFile } from '../../common/types/file.type'; +import { EditorType } from '../../common/types/editor.type'; import { ServiceMessage } from '../../common/types/service-message.type'; @@ -47,26 +48,7 @@ export class CodeViewComponent extends CodeViewBase { private loadAce(): void { this.configAceAndBindToElement() - - if (this.isDefault) { - this.editorsService.setActiveEditor(this.uuid); - this.addActiveStyling(); - this.editor.focus(); - } - - if (this.isMiniMap) { - this.setAsMiniMapView(); - return; - } - - let message = new ServiceMessage(); - message.action = "register-editor"; - message.rawData = this; - - this.lspManagerService.sendMessage(message); - - this.loadAceKeyBindings(); - this.loadAceEventBindings(); + this.setupRequestedMode(); } private configAceAndBindToElement(): void { @@ -76,10 +58,34 @@ export class CodeViewComponent extends CodeViewBase { this.editor = ace.edit( this.editorElm.nativeElement ); this.editor.setOptions( this.editorSettings.CONFIG ); - this.editorsService.set(this.uuid, this); + + if (this.isDefault) { + this.editorsService.set(this.uuid, this); + this.editorsService.setActiveEditor(this.uuid); + this.addActiveStyling(); + this.editor.focus(); + } } - private loadAceKeyBindings(): void { + private setupRequestedMode() { + switch(this.mode) { + case EditorType.Standalone: + // Note: Ace editor without any additional Newton setup... + break; + case EditorType.MiniMap: + this.setAsMiniMapView(); + break; + case EditorType.ReadOnly: + this.setAsReadOnly(); + break; + default: + this.loadNewtonKeyBindings(); + this.loadNewtonEventBindings(); + break; + } + } + + private loadNewtonKeyBindings(): void { let keyBindings = []; for (let i = 0; i < this.editorSettings.KEYBINDINGS.length; i++) { let keyBinding = this.editorSettings.KEYBINDINGS[i]; @@ -111,7 +117,7 @@ export class CodeViewComponent extends CodeViewBase { this.editor.commands.addCommands( keyBindings ); } - private loadAceEventBindings(): void { + private loadNewtonEventBindings(): void { // Note: https://ajaxorg.github.io/ace-api-docs/interfaces/ace.Ace.EditorEvents.html this.editor.on("focus", (e) => { diff --git a/src/app/editor/editors.component.html b/src/app/editor/editors.component.html index c4e7150..5e033cd 100644 --- a/src/app/editor/editors.component.html +++ b/src/app/editor/editors.component.html @@ -4,7 +4,7 @@
- +
\ No newline at end of file diff --git a/src/app/editor/lsp-manager/lsp-manager.component.css b/src/app/editor/lsp-manager/lsp-manager.component.css index 58463c1..d40084e 100644 --- a/src/app/editor/lsp-manager/lsp-manager.component.css +++ b/src/app/editor/lsp-manager/lsp-manager.component.css @@ -1,3 +1,4 @@ .lsp-config-text { + display: grid; min-height: 25em; } \ No newline at end of file diff --git a/src/app/editor/lsp-manager/lsp-manager.component.html b/src/app/editor/lsp-manager/lsp-manager.component.html index 1f9227a..a7ddbfb 100644 --- a/src/app/editor/lsp-manager/lsp-manager.component.html +++ b/src/app/editor/lsp-manager/lsp-manager.component.html @@ -19,9 +19,9 @@
- +
-
+ \ No newline at end of file diff --git a/src/app/editor/lsp-manager/lsp-manager.component.ts b/src/app/editor/lsp-manager/lsp-manager.component.ts index 176e77a..c057cb5 100644 --- a/src/app/editor/lsp-manager/lsp-manager.component.ts +++ b/src/app/editor/lsp-manager/lsp-manager.component.ts @@ -3,6 +3,8 @@ import { Subject, takeUntil } from 'rxjs'; import { LspManagerService } from '../../common/services/editor/lsp-manager/lsp-manager.service'; +import { CodeViewComponent } from '../code-view/view.component'; + import { ServiceMessage } from '../../common/types/service-message.type'; @@ -11,6 +13,7 @@ import { ServiceMessage } from '../../common/types/service-message.type'; selector: 'lsp-manager', standalone: true, imports: [ + CodeViewComponent ], templateUrl: './lsp-manager.component.html', styleUrl: './lsp-manager.component.css', @@ -25,8 +28,8 @@ export class LspManagerComponent { private lspManagerService: LspManagerService = inject(LspManagerService); @HostBinding("class.hidden") isHidden: boolean = true; - @ViewChild('lspConfigText') lspConfigText!: ElementRef; - private editors: any = {}; + @ViewChild('editorComponent') editorComponent!: CodeViewComponent; + lspTextEditor!: any; private editor: any; @@ -35,7 +38,12 @@ export class LspManagerComponent { private ngAfterViewInit(): void { - this.lspConfigText.nativeElement.value = this.lspManagerService.lspConfigData; + this.lspTextEditor = this.editorComponent.editor; + + this.lspManagerService.loadLspConfigData().then((lspConfigData) => { + this.lspTextEditor.session.setMode("ace/mode/json"); + this.lspTextEditor.session.setValue(lspConfigData); + }); this.loadSubscribers(); } @@ -53,8 +61,6 @@ export class LspManagerComponent { this.toggleLspManager(message); } else if (message.action === "set-active-editor") { this.setActiveEditor(message); - } else if (message.action === "register-editor") { - this.registerEditor(message); } }); } @@ -76,12 +82,7 @@ export class LspManagerComponent { } private setActiveEditor(message: ServiceMessage) { - this.editor = this.editors[message.editorUUID]; - } - - private registerEditor(message: ServiceMessage) { - let _editor = message.rawData; - this.editors[_editor.uuid] = _editor.editor; + this.editor = message.rawData; } } \ No newline at end of file