forked from oxy-compsci/brick-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-editor.js
More file actions
87 lines (80 loc) · 2.94 KB
/
create-editor.js
File metadata and controls
87 lines (80 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* global require, monaco, editor, deleteHandler, backspaceHandler, onDidChangeCursorSelection, blockDict */
// create monaco editor
require.config({
paths: {
"vs": "../node_modules/monaco-editor/min/vs"
}
});
require(["vs/editor/editor.main"], function () {
var jsCode = [
"\"use strict\";",
"function Person(age) {",
" if (age) {",
" this.age = age;",
" }",
"}",
"// comment",
"Person.prototype.getAge = function () {",
" return this.age;",
"};"
].join("\n");
// defines a custom theme with varied color text
monaco.editor.defineTheme("normal", {
base: "vs-dark", // can also be vs-dark or hc-black
inherit: true, // can also be false to completely replace the builtin rules
// set comment color
rules: [
{ token: "comment.js", foreground: "ff0066", fontStyle: "bold" },
],
// set editor background color
colors: {
//"editor.background": "#EDF9FA",
"editor.lineHighlightBackground": "#800060",
}
});
monaco.editor.defineTheme("flash", {
base: "vs-dark", // can also be vs-dark or hc-black
inherit: true, // can also be false to completely replace the builtin rules
// set comment color
rules: [
{ token: "comment.js", foreground: "ff0066", fontStyle: "bold" },
],
// set editor background color
colors: {
"editor.background": "#262673",
"editor.lineHighlightBackground": "#800060",
}
});
// eslint-disable-next-line no-global-assign
editor = monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "typescript",
theme: "normal",
formatOnType: true,
formatOnPaste: true,
});
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
/* Disable allowNonTsExtensions to remove keywords from autocomplete
* This introduces an error in the console. Unknown if this will have a negative impact when compiling.
*/
allowNonTsExtensions: false,
noLib: true
});
monaco.languages.registerCompletionItemProvider("typescript", {
provideCompletionItems: function() {
var autocomplete = [];
for (var i = 0; i < blockDict.length; i++) {
autocomplete[i] = {
label: blockDict[i].blockName,
kind: "monaco.languages.CompletionItemKind.Function",
documentation: blockDict.documentation,
insertText: blockDict[i].code
};
}
return autocomplete;
}
});
editor.addCommand(monaco.KeyCode.Backspace, backspaceHandler);
editor.addCommand(monaco.KeyCode.Delete, deleteHandler);
editor.onDidChangeCursorSelection(onDidChangeCursorSelection);
});