Files
Newton-Editor/src/app/editor/ace/ace-editor.base.ts

105 lines
2.6 KiB
TypeScript
Raw Normal View History

import { Directive, ElementRef, Input, ViewChild } from '@angular/core';
import { EditorSettings } from "../../common/configs/editor.config";
@Directive()
export class AceEditorBase {
@ViewChild('editor') editorElm!: ElementRef;
@Input() editorSettings!: typeof EditorSettings;
editor!: any;
uuid!: string;
cutBuffer: string = "";
timerId: number = -1;
constructor(
) {}
2025-06-01 00:49:30 -05:00
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() {
2025-06-01 00:49:30 -05:00
this.editor.setFontSize(
parseInt(this.editor.getFontSize()) + 1
)
}
protected zoomOut() {
2025-06-01 00:49:30 -05:00
this.editor.setFontSize(
parseInt(this.editor.getFontSize()) - 1
)
}
2025-06-01 00:49:30 -05:00
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() {
this.editor.execCommand("movelinesup");
}
protected movelinesDown() {
this.editor.execCommand("movelinesdown");
}
protected duplicateLines() {
this.editor.execCommand("copylinesdown");
}
protected cutToBuffer() {
if (this.timerId) { clearTimeout(this.timerId); }
const cursorPosition = this.editor.getCursorPosition();
let lineText = this.editor.session.getLine(cursorPosition.row);
this.cutBuffer += `${lineText}\n`;
2025-06-01 00:49:30 -05:00
this.editor.session.removeFullLines(cursorPosition.row, cursorPosition.row)
this.setBufferClearTimeout();
}
protected pasteCutBuffer() {
if (this.timerId) { clearTimeout(this.timerId); }
2025-06-01 00:49:30 -05:00
this.editor.insert(this.cutBuffer, true);
this.setBufferClearTimeout();
}
private setBufferClearTimeout(timeout: number = 5000) {
this.timerId = setTimeout(() => {
this.cutBuffer = "";
this.timerId = -1;
}, timeout);
}
}