2019-08-28 06:50:38 +08:00
|
|
|
import { ResizableWidget } from "../../core/gui/ResizableWidget";
|
2019-08-27 01:19:19 +08:00
|
|
|
import { el } from "../../core/gui/dom";
|
2019-09-16 00:34:24 +08:00
|
|
|
import { editor, KeyCode, KeyMod } from "monaco-editor";
|
2019-08-27 01:19:19 +08:00
|
|
|
import { asm_editor_store } from "../stores/AsmEditorStore";
|
2019-09-15 04:25:21 +08:00
|
|
|
import { AsmEditorToolBar } from "./AsmEditorToolBar";
|
2019-09-16 05:16:11 +08:00
|
|
|
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
|
2019-08-27 01:19:19 +08:00
|
|
|
|
|
|
|
editor.defineTheme("phantasmal-world", {
|
|
|
|
base: "vs-dark",
|
|
|
|
inherit: true,
|
|
|
|
rules: [
|
|
|
|
{ token: "", foreground: "e0e0e0", background: "#181818" },
|
|
|
|
{ token: "tag", foreground: "99bbff" },
|
|
|
|
{ token: "keyword", foreground: "d0a0ff", fontStyle: "bold" },
|
|
|
|
{ token: "predefined", foreground: "bbffbb" },
|
|
|
|
{ token: "number", foreground: "ffffaa" },
|
|
|
|
{ token: "number.hex", foreground: "ffffaa" },
|
|
|
|
{ token: "string", foreground: "88ffff" },
|
|
|
|
{ token: "string.escape", foreground: "8888ff" },
|
|
|
|
],
|
|
|
|
colors: {
|
|
|
|
"editor.background": "#181818",
|
|
|
|
"editor.lineHighlightBackground": "#202020",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-08-27 20:50:16 +08:00
|
|
|
const DUMMY_MODEL = editor.createModel("", "psoasm");
|
|
|
|
|
2019-08-28 06:50:38 +08:00
|
|
|
export class AsmEditorView extends ResizableWidget {
|
2019-09-15 04:25:21 +08:00
|
|
|
private readonly tool_bar_view = this.disposable(new AsmEditorToolBar());
|
2019-08-29 03:36:45 +08:00
|
|
|
private readonly editor: IStandaloneCodeEditor;
|
2019-08-27 01:19:19 +08:00
|
|
|
|
2019-09-16 05:16:11 +08:00
|
|
|
readonly element = el.div();
|
|
|
|
|
2019-08-27 01:19:19 +08:00
|
|
|
constructor() {
|
2019-09-16 01:32:34 +08:00
|
|
|
super();
|
2019-08-29 03:36:45 +08:00
|
|
|
|
2019-09-15 04:25:21 +08:00
|
|
|
this.element.append(this.tool_bar_view.element);
|
|
|
|
|
2019-08-29 03:36:45 +08:00
|
|
|
this.editor = this.disposable(
|
|
|
|
editor.create(this.element, {
|
|
|
|
theme: "phantasmal-world",
|
|
|
|
scrollBeyondLastLine: false,
|
|
|
|
autoIndent: true,
|
|
|
|
fontSize: 13,
|
|
|
|
wordBasedSuggestions: false,
|
|
|
|
wordWrap: "on",
|
|
|
|
wrappingIndent: "indent",
|
|
|
|
renderIndentGuides: false,
|
|
|
|
folding: false,
|
|
|
|
}),
|
|
|
|
);
|
2019-08-27 01:19:19 +08:00
|
|
|
|
2019-09-16 00:34:24 +08:00
|
|
|
this.editor.addCommand(KeyMod.CtrlCmd | KeyCode.KEY_Z, () => {});
|
|
|
|
this.editor.addCommand(KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z, () => {});
|
|
|
|
|
2019-08-27 01:19:19 +08:00
|
|
|
this.disposables(
|
|
|
|
asm_editor_store.did_undo.observe(({ value: source }) => {
|
|
|
|
this.editor.trigger(source, "undo", undefined);
|
|
|
|
}),
|
|
|
|
|
|
|
|
asm_editor_store.did_redo.observe(({ value: source }) => {
|
|
|
|
this.editor.trigger(source, "redo", undefined);
|
|
|
|
}),
|
|
|
|
|
|
|
|
asm_editor_store.model.observe(
|
|
|
|
({ value: model }) => {
|
|
|
|
this.editor.updateOptions({ readOnly: model == undefined });
|
2019-08-27 20:50:16 +08:00
|
|
|
this.editor.setModel(model || DUMMY_MODEL);
|
2019-08-27 01:19:19 +08:00
|
|
|
},
|
|
|
|
{ call_now: true },
|
|
|
|
),
|
|
|
|
|
|
|
|
this.editor.onDidFocusEditorWidget(() => asm_editor_store.undo.make_current()),
|
|
|
|
);
|
2019-09-14 21:20:36 +08:00
|
|
|
|
|
|
|
this.finalize_construction(AsmEditorView.prototype);
|
2019-08-27 01:19:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
focus(): void {
|
|
|
|
this.editor.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
resize(width: number, height: number): this {
|
2019-09-17 18:47:03 +08:00
|
|
|
const editor_height = Math.max(0, height - this.tool_bar_view.height);
|
|
|
|
this.editor.layout({ width, height: editor_height });
|
2019-08-27 01:19:19 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|