most menu events mapped; cleanup

This commit is contained in:
2025-06-01 00:49:30 -05:00
parent fbf6933102
commit ae43722881
9 changed files with 279 additions and 29 deletions

View File

@@ -13,10 +13,16 @@ declare global {
chrome: () => Promise<string>,
electron: () => Promise<string>,
},
main: {
onMenuActions: (arg0: any) => Promise<string>,
},
fs: {
getLspConfigData: () => Promise<string>,
getFileContents: (arg0: any) => Promise<string>,
saveFile: (arg0: any, arg1: any) => Promise<string>,
saveFileAs: (arg0: any) => Promise<string>,
getPathForFile: any,
onLoadFiles: (arg0: any) => Promise<string>,
}
}
}

View File

@@ -15,15 +15,15 @@ export const EditorSettings: any = {
enableSnippets: true,
highlightActiveLine: true,
enableMultiselect: true,
tabSize: 4,
useSoftTabs: true,
tabSize: 4,
navigateWithinSoftTabs: true,
tooltipFollowsMouse: true,
wrapBehavioursEnabled: false,
scrollPastEnd: 0.5,
mergeUndoDeltas: false,
showGutter: true,
customScrollbar: true,
navigateWithinSoftTabs: true,
scrollSpeed: 5
}
};

View File

@@ -50,7 +50,7 @@ export class LSPService {
private getLanguageProviderWithClientServer(mode: string) {
let _initializationOptions = {};
if (Object.keys(this.lspConfigData).length !== 0) {
if ( Object.keys(this.lspConfigData).length !== 0 && this.lspConfigData[mode] ) {
_initializationOptions = this.lspConfigData[mode]["initialization-options"];
}

View File

@@ -10,7 +10,6 @@ export class AceEditorBase {
@Input() editorSettings!: typeof EditorSettings;
editor!: any;
uuid!: string;
fontSize: number = 12;
cutBuffer: string = "";
timerId: number = -1;
@@ -19,18 +18,51 @@ export class AceEditorBase {
) {}
protected search() {
console.log(this.editor.getSession()["$modeId"])
}
protected saveFile() {
const text = this.editor.session.getValue();
// window.fs.saveFile(text);
}
protected saveFileAs() {
const text = this.editor.session.getValue();
window.fs.saveFileAs(text);
}
protected zoomIn() {
this.fontSize += 1;
this.editorElm.nativeElement.style.fontSize = `${this.fontSize}px`;
this.editor.setFontSize(
parseInt(this.editor.getFontSize()) + 1
)
}
protected zoomOut() {
this.fontSize -= 1;
this.editorElm.nativeElement.style.fontSize = `${this.fontSize}px`;
this.editor.setFontSize(
parseInt(this.editor.getFontSize()) - 1
)
}
protected search() {
console.log(this.editor.getSession()["$modeId"])
protected cutText() {
let cutText = this.editor.getSelectedText();
this.editor.remove();
navigator.clipboard.writeText(cutText).catch(() => {
console.error("Unable to cut text...");
});
}
protected copyText() {
let copyText = this.editor.getSelectedText();
navigator.clipboard.writeText(copyText).catch(() => {
console.error("Unable to copy text...");
});
}
protected pasteText() {
navigator.clipboard.readText().then((pasteText) => {
this.editor.insert(pasteText, true);
});
}
protected movelinesUp() {
@@ -51,17 +83,15 @@ export class AceEditorBase {
const cursorPosition = this.editor.getCursorPosition();
let lineText = this.editor.session.getLine(cursorPosition.row);
this.cutBuffer += `${lineText}\n`;
this.editor.session.removeFullLines(cursorPosition.row, cursorPosition.row)
this.editor.session.removeFullLines(cursorPosition.row, cursorPosition.row)
this.setBufferClearTimeout();
}
protected pasteCutBuffer() {
if (this.timerId) { clearTimeout(this.timerId); }
const cursorPosition = this.editor.getCursorPosition();
this.editor.session.insert(cursorPosition, this.cutBuffer)
this.editor.insert(this.cutBuffer, true);
this.setBufferClearTimeout();
}

View File

@@ -109,6 +109,20 @@ export class AceEditorComponent extends AceEditorBase {
this.editor.session.destroy();
},
readOnly: true
}, {
name: "saveFile",
bindKey: {win: "ctrl-s", mac: "ctrl-s"},
exec: () => {
this.saveFile();
},
readOnly: true
}, {
name: "saveFileAs",
bindKey: {win: "ctrl-shift-s", mac: "ctrl-shift-s"},
exec: () => {
this.saveFileAs();
},
readOnly: true
}
]);

View File

@@ -51,8 +51,9 @@ export class EditorsComponent {
public ngAfterViewInit(): void {
this.loadSubscribers();
this.loadMainSubscribers();
let editor = this.createEditor();
let editor = this.createEditor();
this.activeEditor = editor.instance.uuid;
this.createEditor();
}
@@ -65,6 +66,55 @@ export class EditorsComponent {
});
}
loadMainSubscribers() {
window.fs.onLoadFiles(async (paths: []) => {
for (let i = 0; i < paths.length; i++) {
let file = new File([], "") as NewtonFile;
await this.addFile(paths[i], file);
this.addTab(file);
}
let session = this.files.get(paths[ paths.length - 1 ]).session;
this.setSession(session);
});
window.main.onMenuActions(async (action: string) => {
let editorComponent = this.getActiveEditorComponent();
let editor = editorComponent.editor;
switch ( action ) {
case "new-file":
break;
case "save-file":
editorComponent.saveFile();
break;
case "save-file-as":
editorComponent.saveFileAs();
break;
case "cut":
editorComponent.cutText();
break;
case "copy":
editorComponent.copyText();
break;
case "paste":
editorComponent.pasteText();
break;
case "zoom-in":
editorComponent.zoomIn()
break;
case "zoom-out":
editorComponent.zoomOut()
break;
case "show-about":
break;
default:
editor.execCommand(action);
}
});
}
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
@@ -79,16 +129,36 @@ export class EditorsComponent {
return component;
}
protected onFileDropped(event: any) {
this.loadFilesList(event).then((session: EditSession | undefined | null) => {
if ( !session ) return;
let editorComponent = this.editors.get(this.activeEditor)?.instance;
let editor = editorComponent.editor;
editor?.setSession(session);
protected onFileDropped(files: any) {
this.loadFilesList(files).then((session: EditSession | undefined | null) => {
this.setSession(session);
});
}
private async setSession(session: EditSession | undefined | null) {
if ( !session ) return;
let editor = this.getActiveEditor();
editor?.setSession(session);
}
private getSession() {
let editorComponent = this.editors.get(this.activeEditor)?.instance;
let editor = editorComponent.editor;
return editor?.getSession();
}
private getActiveEditorComponent(): any {
return this.editors.get(this.activeEditor)?.instance;
}
private getActiveEditor(): any {
let editorComponent = this.editors.get(this.activeEditor)?.instance;
let editor = editorComponent.editor;
return editor;
}
private async loadFilesList(files: Array<NewtonFile>): Promise<EditSession | undefined | null> {
for (let i = 0; i < files.length; i++) {
const file = files[i];
@@ -96,7 +166,7 @@ export class EditorsComponent {
if (!file || !path) continue;
if ( this.files.get(path) ) continue;
await this.addFile(path, file);
this.addTab(file);
}
@@ -104,7 +174,7 @@ export class EditorsComponent {
return files[ files.length - 1 ].session;
}
private async addFile(path: string, file: NewtonFile) {
private async addFile(path: string, file: NewtonFile): Promise<void> {
try {
let pathParts = path.split("/");
file.fname = pathParts[ pathParts.length - 1 ];