WIP context menu added; upgraded ace-linters; integrated auto session register

This commit is contained in:
2025-07-26 00:43:45 -05:00
parent 90c8c9b3ee
commit 822d778008
13 changed files with 134 additions and 33 deletions

View File

@@ -0,0 +1,5 @@
export abstract class ButtonMap {
static LEFT: number = 0;
static MIDDLE: number = 1;
static RIGHT: number = 2;
}

View File

@@ -35,10 +35,7 @@ export class LspManagerService {
this.languageProviders[mode]?.registerEditor(
editor,
{
filePath: editor.session["id"],
joinWorkspaceURI: true
}
editor.session.lspConfig
);
}
@@ -97,8 +94,13 @@ export class LspManagerService {
return;
}
this.languageProviders[mode] = AceLanguageClient.for(servers);
// this.languageProviders[mode].requireFilePath = true;
this.languageProviders[mode] = AceLanguageClient.for(
servers,
{
manualSessionControl: true
}
);
this.languageProviders[mode].changeWorkspaceFolder(this.workspaceFolder);
return this.languageProviders[mode];
}
@@ -108,11 +110,15 @@ export class LspManagerService {
return LanguageProvider.create(worker);
}
public setSessionFilePath(session: any, filePath: string = "") {
if ( !session || !filePath ) return;
let mode = this.getMode(session);
public registerSession(editor: any) {
let mode = this.getMode(editor.session);
if ( !this.languageProviders[mode] ) return;
this.languageProviders[mode].setSessionFilePath(session, filePath);
this.languageProviders[mode].registerSession(
editor.session,
editor,
editor.session.lspConfig
);
}
public getMode(session: any): string {

View File

@@ -111,6 +111,10 @@ export class FilesService {
file.session["id"] = path;
file.session.setUndoManager( new UndoManager() );
file.session.setMode( getModeForPath( file.path ).mode );
file.session["lspConfig"] = {
filePath: path,
joinWorkspaceURI: false
}
this.files.set(file.path, file);
} catch (error) {

View File

@@ -46,6 +46,9 @@ export class CodeViewBase {
public debounceId: number = -1;
public debounceWait: number = 800;
@ViewChild('contextMenu') contextMenu!: ElementRef;
public showContextMenu: boolean = false;
constructor() {
}

View File

@@ -25,4 +25,24 @@
border-style: solid;
border-width: thin;
border-color: rgba(124, 124, 124, 1);
}
}
.contextMenu {
display: inline-table;
z-index: 500;
position: absolute;
min-width: 2em;
padding: 0.2em;
top: 0em;
right: 0em;
}
.contextMenu li:hover {
background-color: rgba(0, 124, 0, 0.64);
cursor: pointer;
}
.contextMenu li {
padding: 0em 0.2em;
}

View File

@@ -1,2 +1,15 @@
<div class="editor" #editor >
</div>
<ul #contextMenu
class="contextMenu"
[hidden]="!showContextMenu"
(blur)="hideContextMenu"
(click)="contextMenuClicked($event)"
>
<li command="cutText">Cut</li>
<li command="copyText">Copy</li>
<li command="pasteText">Paste</li>
<hr/>
<li command="prettyJSON">Prettify JSON</li>
</ul>

View File

@@ -25,6 +25,7 @@ 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';
import { ButtonMap } from '../../common/constants/button.map';
@@ -159,10 +160,30 @@ export class CodeViewComponent extends CodeViewBase {
this.updateInfoBar();
});
this.editor.on("click", () => {
this.editor.on("click", (event) => {
this.updateInfoBar();
});
this.editor.addEventListener("mousedown", (event) => {
if (ButtonMap.LEFT === event.domEvent.button) {
this.showContextMenu = false;
} else if (ButtonMap.RIGHT === event.domEvent.button) {
let menuElm = this.contextMenu.nativeElement;
let pageX = event.domEvent.pageX;
let pageY = event.domEvent.pageY;
const origin = {
left: pageX + 5,
top: pageY - 5
};
menuElm.style.left = `${origin.left}px`;
menuElm.style.top = `${origin.top}px`;
this.showContextMenu = true;
}
});
this.editor.on("input", () => {
this.updateInfoBar();
});
@@ -219,6 +240,28 @@ export class CodeViewComponent extends CodeViewBase {
}
public prettyJSON() {
let data = JSON.parse(this.editor.session.getValue());
this.editor.session.setValue(
JSON.stringify(data, null, 4)
);
}
public hideContextMenu() {
this.showContextMenu = false;
}
public contextMenuClicked(event: any) {
this.showContextMenu = false;
const command = event.target.getAttribute("command");
const args = event.target.getAttribute("args");
if (!command) return;
this[command]( (args) ? args : null );
}
public assignSession(file: NewtonFile) {
if (!file) return;
@@ -229,8 +272,13 @@ export class CodeViewComponent extends CodeViewBase {
public cloneSession(file: NewtonFile) {
if (!file) return;
this.activeFile = file;
let session = this.aceApi.createEditSession(file.session.getValue());
this.activeFile = file;
let session = this.aceApi.createEditSession(file.session.getValue());
session["$config"] = {
"lsp": {
"filePath": file.path
}
}
session.setMode( file.session.getMode()["$id"] );
this.editor.setSession(session);

View File

@@ -101,12 +101,6 @@ export class LspManagerComponent {
public registerEditorToLanguageClient() {
this.lspManagerService.registerEditorToLSPClient(this.editor);
/*
this.lspManagerService.setSessionFilePath(
this.editor.session,
this.activeFile.path
);
*/
}
@@ -148,13 +142,7 @@ export class LspManagerComponent {
this.editor.setSession(message.rawData.editor.getSession())
this.activeFile = message.rawData.activeFile;
/*
this.lspManagerService.setSessionFilePath(
this.editor.session,
this.activeFile.path
);
*/
this.lspManagerService.registerSession(this.editor);
}
private closeFile(message: ServiceMessage) {

View File

@@ -42,6 +42,7 @@
margin-left: 2em;
margin-right: 2em;
font-size: 4em;
align-self: center;
}
.close-button {

View File

@@ -10,6 +10,10 @@ body {
overflow: hidden;
}
ul, li {
list-style: none;
}
/* IDs */