Restructured loading of editor modes; changed LSP config loading
This commit is contained in:
parent
27c4cda01a
commit
9e01628ffb
@ -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;
|
||||
}
|
||||
|
@ -19,12 +19,11 @@ export class LspManagerService {
|
||||
|
||||
|
||||
constructor() {
|
||||
this.loadLSPService();
|
||||
}
|
||||
|
||||
|
||||
private loadLSPService() {
|
||||
this.getLspConfigData().then((lspConfigData: string) => {
|
||||
public loadLspConfigData(): Promise<string | void> {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
|
5
src/app/common/types/editor.type.ts
Normal file
5
src/app/common/types/editor.type.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export abstract class EditorType {
|
||||
static MiniMap: string = "mini-map";
|
||||
static ReadOnly: string = "read-only";
|
||||
static Standalone: string = "standalone";
|
||||
}
|
@ -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);
|
||||
|
@ -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) => {
|
||||
|
@ -4,7 +4,7 @@
|
||||
<code-view [isDefault]="true"></code-view>
|
||||
<hr class="col vr-pane-handle" pane-handle />
|
||||
<code-view></code-view>
|
||||
<code-view [isMiniMap]="true"></code-view>
|
||||
<code-view [mode]="'mini-map'"></code-view>
|
||||
</div>
|
||||
|
||||
<div>
|
@ -1,3 +1,4 @@
|
||||
.lsp-config-text {
|
||||
display: grid;
|
||||
min-height: 25em;
|
||||
}
|
@ -19,9 +19,9 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="col">
|
||||
<textarea #lspConfigText class="form-control form-control-sm lsp-config-text" placeholder="LSP Config..."> </textarea>
|
||||
<code-view #editorComponent [mode]="'standalone'" class="lsp-config-text"></code-view>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user