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-11-14 03:12:43 +08:00
|
|
|
import { editor, KeyCode, KeyMod, Range } 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-10-06 03:11:58 +08:00
|
|
|
import { EditorHistory } from "./EditorHistory";
|
2019-09-16 05:16:11 +08:00
|
|
|
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
|
2019-11-14 03:12:43 +08:00
|
|
|
import "./AsmEditorView.css";
|
|
|
|
import { ListChangeType } from "../../core/observable/property/list/ListProperty";
|
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-10-06 03:11:58 +08:00
|
|
|
private readonly history: EditorHistory;
|
2019-11-14 03:12:43 +08:00
|
|
|
private editor_decoration_ids: string[] = [];
|
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-11-14 03:12:43 +08:00
|
|
|
glyphMargin: true,
|
2019-08-29 03:36:45 +08:00
|
|
|
}),
|
|
|
|
);
|
2019-08-27 01:19:19 +08:00
|
|
|
|
2019-10-06 03:11:58 +08:00
|
|
|
this.history = this.disposable(new EditorHistory(this.editor));
|
|
|
|
|
|
|
|
// Commands and actions.
|
2019-09-16 00:34:24 +08:00
|
|
|
this.editor.addCommand(KeyMod.CtrlCmd | KeyCode.KEY_Z, () => {});
|
2019-10-06 03:11:58 +08:00
|
|
|
|
2019-09-16 00:34:24 +08:00
|
|
|
this.editor.addCommand(KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z, () => {});
|
2019-10-06 03:11:58 +08:00
|
|
|
|
2019-10-01 23:41:28 +08:00
|
|
|
const quick_command = this.editor.getAction("editor.action.quickCommand");
|
2019-09-16 00:34:24 +08:00
|
|
|
|
2019-10-06 03:11:58 +08:00
|
|
|
this.disposables(
|
|
|
|
this.editor.addAction({
|
|
|
|
id: "editor.action.quickCommand",
|
|
|
|
label: "Command Palette",
|
|
|
|
keybindings: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_P],
|
|
|
|
run: () => quick_command.run(),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Undo/Redo
|
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-10-06 03:11:58 +08:00
|
|
|
this.history.reset();
|
2019-08-27 01:19:19 +08:00
|
|
|
},
|
|
|
|
{ call_now: true },
|
|
|
|
),
|
|
|
|
|
2019-11-14 03:12:43 +08:00
|
|
|
asm_editor_store.breakpoints.observe_list(change => {
|
|
|
|
if (change.type === ListChangeType.ListChange) {
|
|
|
|
// update breakpoint icons
|
|
|
|
this.editor_decoration_ids = this.editor.deltaDecorations(
|
|
|
|
this.editor_decoration_ids,
|
|
|
|
asm_editor_store.breakpoints.val.map(line_num => ({
|
|
|
|
range: new Range(line_num, 0, line_num, 0),
|
|
|
|
options: {
|
|
|
|
glyphMarginClassName:
|
|
|
|
"quest_editor_AsmEditorView_breakpoint-enabled",
|
|
|
|
glyphMarginHoverMessage: {
|
|
|
|
value: "Breakpoint"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2019-08-27 01:19:19 +08:00
|
|
|
this.editor.onDidFocusEditorWidget(() => asm_editor_store.undo.make_current()),
|
2019-11-14 03:12:43 +08:00
|
|
|
|
|
|
|
this.editor.onMouseDown(e => {
|
|
|
|
switch (e.target.type) {
|
|
|
|
case editor.MouseTargetType.GUTTER_GLYPH_MARGIN:
|
|
|
|
const pos = e.target.position;
|
|
|
|
if (!pos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
asm_editor_store.toggle_breakpoint(pos.lineNumber);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
2019-08-27 01:19:19 +08:00
|
|
|
);
|
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;
|
|
|
|
}
|
|
|
|
}
|