-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembeddedEditor.js
90 lines (74 loc) · 2.77 KB
/
embeddedEditor.js
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
88
/// ace Editor ///
// Code from
// https://jsbin.com/taniqikagi/edit?html,js,output
var TextHighlightRules = ace.require("ace/mode/text_highlight_rules").TextHighlightRules;
TextHighlightRules.prototype.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar)
{
var keywords = this.$keywords = Object.create(null);
Object.keys(map).forEach(function(className)
{
var a = map[className];
if (ignoreCase)
a = a.toLowerCase();
var list = a.split(splitChar || "|");
for (var i = list.length; i--; )
keywords[list[i]] = className;
});
// in old versions of opera keywords["__proto__"] sets prototype
// even on objects with __proto__=null
if (Object.getPrototypeOf(keywords))
{
keywords.__proto__ = null;
}
this.$keywordList = Object.keys(keywords);
map = null;
return ignoreCase
? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
: function(value) {return keywords[value] || defaultToken; };
};
var editor = ace.edit("editor", { mode: 'ace/mode/glsl' });
editor.setTheme("ace/theme/monokai");
editor.resize();
function updateKeywords(list) {
var keywords = editor.session.$mode.$highlightRules.$keywords;
list.forEach(function(x)
{
keywords[x[0]] = x[1];
});
editor.session.bgTokenizer.start(0);
}
setTimeout(function() {
updateKeywords([["VAL", "support.type"],
["VAL2", "support.type"],
["VAL3", "support.type"],
["add", "support.function"],
["sub", "support.function"],
["mul", "support.function"],
["recip", "support.function"],
["div", "support.function"],
["d_sq", "support.function"],
["d_sin", "support.function"],
["d_cos", "support.function"],
["d_exp", "support.function"],
["d_log", "support.function"],
["dc_mul", "support.function"],
["dc_sq", "support.function"],
["dc_conj", "support.function"],
["dc_absSq", "support.function"],
["dcr_div", "support.function"],
["dc_recip", "support.function"]
]);
// https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode
//
// "variable.language" : this
// "keyword" : types and keyword
// "constant.language" : max mix clamp dot step
// "keyword.operator"
// "support.type"
//
/*
"keyword.control" : keywordControls,
"storage.type" : storageType,
"storage.modifier" : storageModifiers,
*/
}, 1000); // TODO