2025-05-28 02:10:45 +00:00
|
|
|
import { Component, ElementRef, ViewChild, Input } from '@angular/core';
|
|
|
|
|
|
|
|
// Import Ace and its modes/themes so that `ace` global is defined
|
|
|
|
import * as ace from 'ace-builds/src-noconflict/ace';
|
|
|
|
import 'ace-builds/src-noconflict/theme-one_dark';
|
2025-05-28 05:52:55 +00:00
|
|
|
import "ace-builds/src-noconflict/ext-language_tools";
|
|
|
|
|
2025-05-28 02:10:45 +00:00
|
|
|
import { EditorSettings } from "../../common/configs/editor.config";
|
2025-05-30 05:30:54 +00:00
|
|
|
import { ServiceMessage } from '../../common/types/service-message.type';
|
2025-05-28 02:10:45 +00:00
|
|
|
|
|
|
|
import { EditorsService } from '../../common/services/editor/editors.service';
|
2025-05-30 05:30:54 +00:00
|
|
|
import { LSPService } from '../../common/services/lsp.service';
|
2025-05-28 02:10:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ace-editor',
|
|
|
|
standalone: true,
|
|
|
|
imports: [
|
|
|
|
],
|
|
|
|
templateUrl: './ace-editor.component.html',
|
|
|
|
styleUrl: './ace-editor.component.css',
|
|
|
|
host: {
|
2025-05-30 05:30:54 +00:00
|
|
|
'class': 'col'
|
2025-05-28 02:10:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
export class AceEditorComponent {
|
|
|
|
|
|
|
|
@Input() editorSettings!: typeof EditorSettings;
|
|
|
|
@ViewChild('editor') editorElm!: ElementRef;
|
|
|
|
editor!: any;
|
|
|
|
uuid!: string;
|
|
|
|
|
|
|
|
|
2025-05-30 05:30:54 +00:00
|
|
|
constructor(
|
|
|
|
private editorsService: EditorsService,
|
|
|
|
private lspService: LSPService
|
|
|
|
) {}
|
2025-05-28 02:10:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
public ngAfterViewInit(): void {
|
|
|
|
this.loadAce();
|
|
|
|
}
|
|
|
|
|
|
|
|
public loadAce(): void {
|
|
|
|
ace.config.set('basePath', this.editorSettings.BASE_PATH);
|
|
|
|
|
|
|
|
this.editor = ace.edit( this.editorElm.nativeElement );
|
|
|
|
this.editor.setOptions( this.editorSettings.CONFIG );
|
|
|
|
// this.editor.commands.addCommands( this.editorSettings.KEYBINDINGS );
|
|
|
|
|
2025-05-30 05:30:54 +00:00
|
|
|
this.editor.on("focus", () => {
|
|
|
|
this.editorsService.setActiveEditor(this.uuid);
|
|
|
|
});
|
2025-05-28 02:10:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-05-30 05:30:54 +00:00
|
|
|
public registerEditorToLSP() {
|
|
|
|
this.lspService.registerEditor(this.editor);
|
2025-05-28 02:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|