@tailor-cms/ce-html-edit 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1737 @@
1
+ import "./style.css";
2
+ ace.define("ace/snippets", ["require", "exports", "module", "ace/lib/oop", "ace/lib/event_emitter", "ace/lib/lang", "ace/range", "ace/anchor", "ace/keyboard/hash_handler", "ace/tokenizer", "ace/lib/dom", "ace/editor"], function(acequire, exports, module) {
3
+ var oop = acequire("./lib/oop");
4
+ var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
5
+ var lang = acequire("./lib/lang");
6
+ var Range = acequire("./range").Range;
7
+ var Anchor = acequire("./anchor").Anchor;
8
+ var HashHandler = acequire("./keyboard/hash_handler").HashHandler;
9
+ var Tokenizer = acequire("./tokenizer").Tokenizer;
10
+ var comparePoints = Range.comparePoints;
11
+ var SnippetManager = function() {
12
+ this.snippetMap = {};
13
+ this.snippetNameMap = {};
14
+ };
15
+ (function() {
16
+ oop.implement(this, EventEmitter);
17
+ this.getTokenizer = function() {
18
+ function TabstopToken(str, _, stack) {
19
+ str = str.substr(1);
20
+ if (/^\d+$/.test(str) && !stack.inFormatString)
21
+ return [{ tabstopId: parseInt(str, 10) }];
22
+ return [{ text: str }];
23
+ }
24
+ function escape(ch) {
25
+ return "(?:[^\\\\" + ch + "]|\\\\.)";
26
+ }
27
+ SnippetManager.$tokenizer = new Tokenizer({
28
+ start: [
29
+ { regex: /:/, onMatch: function(val, state, stack) {
30
+ if (stack.length && stack[0].expectIf) {
31
+ stack[0].expectIf = false;
32
+ stack[0].elseBranch = stack[0];
33
+ return [stack[0]];
34
+ }
35
+ return ":";
36
+ } },
37
+ { regex: /\\./, onMatch: function(val, state, stack) {
38
+ var ch = val[1];
39
+ if (ch == "}" && stack.length) {
40
+ val = ch;
41
+ } else if ("`$\\".indexOf(ch) != -1) {
42
+ val = ch;
43
+ } else if (stack.inFormatString) {
44
+ if (ch == "n")
45
+ val = "\n";
46
+ else if (ch == "t")
47
+ val = "\n";
48
+ else if ("ulULE".indexOf(ch) != -1) {
49
+ val = { changeCase: ch, local: ch > "a" };
50
+ }
51
+ }
52
+ return [val];
53
+ } },
54
+ { regex: /}/, onMatch: function(val, state, stack) {
55
+ return [stack.length ? stack.shift() : val];
56
+ } },
57
+ { regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken },
58
+ { regex: /\$\{[\dA-Z_a-z]+/, onMatch: function(str, state, stack) {
59
+ var t = TabstopToken(str.substr(1), state, stack);
60
+ stack.unshift(t[0]);
61
+ return t;
62
+ }, next: "snippetVar" },
63
+ { regex: /\n/, token: "newline", merge: false }
64
+ ],
65
+ snippetVar: [
66
+ { regex: "\\|" + escape("\\|") + "*\\|", onMatch: function(val, state, stack) {
67
+ stack[0].choices = val.slice(1, -1).split(",");
68
+ }, next: "start" },
69
+ {
70
+ regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
71
+ onMatch: function(val, state, stack) {
72
+ var ts = stack[0];
73
+ ts.fmtString = val;
74
+ val = this.splitRegex.exec(val);
75
+ ts.guard = val[1];
76
+ ts.fmt = val[2];
77
+ ts.flag = val[3];
78
+ return "";
79
+ },
80
+ next: "start"
81
+ },
82
+ { regex: "`" + escape("`") + "*`", onMatch: function(val, state, stack) {
83
+ stack[0].code = val.splice(1, -1);
84
+ return "";
85
+ }, next: "start" },
86
+ { regex: "\\?", onMatch: function(val, state, stack) {
87
+ if (stack[0])
88
+ stack[0].expectIf = true;
89
+ }, next: "start" },
90
+ { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start" }
91
+ ],
92
+ formatString: [
93
+ { regex: "/(" + escape("/") + "+)/", token: "regex" },
94
+ { regex: "", onMatch: function(val, state, stack) {
95
+ stack.inFormatString = true;
96
+ }, next: "start" }
97
+ ]
98
+ });
99
+ SnippetManager.prototype.getTokenizer = function() {
100
+ return SnippetManager.$tokenizer;
101
+ };
102
+ return SnippetManager.$tokenizer;
103
+ };
104
+ this.tokenizeTmSnippet = function(str, startState) {
105
+ return this.getTokenizer().getLineTokens(str, startState).tokens.map(function(x) {
106
+ return x.value || x;
107
+ });
108
+ };
109
+ this.$getDefaultValue = function(editor, name) {
110
+ if (/^[A-Z]\d+$/.test(name)) {
111
+ var i = name.substr(1);
112
+ return (this.variables[name[0] + "__"] || {})[i];
113
+ }
114
+ if (/^\d+$/.test(name)) {
115
+ return (this.variables.__ || {})[name];
116
+ }
117
+ name = name.replace(/^TM_/, "");
118
+ if (!editor)
119
+ return;
120
+ var s = editor.session;
121
+ switch (name) {
122
+ case "CURRENT_WORD":
123
+ var r = s.getWordRange();
124
+ case "SELECTION":
125
+ case "SELECTED_TEXT":
126
+ return s.getTextRange(r);
127
+ case "CURRENT_LINE":
128
+ return s.getLine(editor.getCursorPosition().row);
129
+ case "PREV_LINE":
130
+ return s.getLine(editor.getCursorPosition().row - 1);
131
+ case "LINE_INDEX":
132
+ return editor.getCursorPosition().column;
133
+ case "LINE_NUMBER":
134
+ return editor.getCursorPosition().row + 1;
135
+ case "SOFT_TABS":
136
+ return s.getUseSoftTabs() ? "YES" : "NO";
137
+ case "TAB_SIZE":
138
+ return s.getTabSize();
139
+ case "FILENAME":
140
+ case "FILEPATH":
141
+ return "";
142
+ case "FULLNAME":
143
+ return "Ace";
144
+ }
145
+ };
146
+ this.variables = {};
147
+ this.getVariableValue = function(editor, varName) {
148
+ if (this.variables.hasOwnProperty(varName))
149
+ return this.variables[varName](editor, varName) || "";
150
+ return this.$getDefaultValue(editor, varName) || "";
151
+ };
152
+ this.tmStrFormat = function(str, ch, editor) {
153
+ var flag = ch.flag || "";
154
+ var re = ch.guard;
155
+ re = new RegExp(re, flag.replace(/[^gi]/, ""));
156
+ var fmtTokens = this.tokenizeTmSnippet(ch.fmt, "formatString");
157
+ var _self = this;
158
+ var formatted = str.replace(re, function() {
159
+ _self.variables.__ = arguments;
160
+ var fmtParts = _self.resolveVariables(fmtTokens, editor);
161
+ var gChangeCase = "E";
162
+ for (var i = 0; i < fmtParts.length; i++) {
163
+ var ch2 = fmtParts[i];
164
+ if (typeof ch2 == "object") {
165
+ fmtParts[i] = "";
166
+ if (ch2.changeCase && ch2.local) {
167
+ var next = fmtParts[i + 1];
168
+ if (next && typeof next == "string") {
169
+ if (ch2.changeCase == "u")
170
+ fmtParts[i] = next[0].toUpperCase();
171
+ else
172
+ fmtParts[i] = next[0].toLowerCase();
173
+ fmtParts[i + 1] = next.substr(1);
174
+ }
175
+ } else if (ch2.changeCase) {
176
+ gChangeCase = ch2.changeCase;
177
+ }
178
+ } else if (gChangeCase == "U") {
179
+ fmtParts[i] = ch2.toUpperCase();
180
+ } else if (gChangeCase == "L") {
181
+ fmtParts[i] = ch2.toLowerCase();
182
+ }
183
+ }
184
+ return fmtParts.join("");
185
+ });
186
+ this.variables.__ = null;
187
+ return formatted;
188
+ };
189
+ this.resolveVariables = function(snippet, editor) {
190
+ var result = [];
191
+ for (var i = 0; i < snippet.length; i++) {
192
+ var ch = snippet[i];
193
+ if (typeof ch == "string") {
194
+ result.push(ch);
195
+ } else if (typeof ch != "object") {
196
+ continue;
197
+ } else if (ch.skip) {
198
+ gotoNext(ch);
199
+ } else if (ch.processed < i) {
200
+ continue;
201
+ } else if (ch.text) {
202
+ var value = this.getVariableValue(editor, ch.text);
203
+ if (value && ch.fmtString)
204
+ value = this.tmStrFormat(value, ch);
205
+ ch.processed = i;
206
+ if (ch.expectIf == null) {
207
+ if (value) {
208
+ result.push(value);
209
+ gotoNext(ch);
210
+ }
211
+ } else {
212
+ if (value) {
213
+ ch.skip = ch.elseBranch;
214
+ } else
215
+ gotoNext(ch);
216
+ }
217
+ } else if (ch.tabstopId != null) {
218
+ result.push(ch);
219
+ } else if (ch.changeCase != null) {
220
+ result.push(ch);
221
+ }
222
+ }
223
+ function gotoNext(ch2) {
224
+ var i1 = snippet.indexOf(ch2, i + 1);
225
+ if (i1 != -1)
226
+ i = i1;
227
+ }
228
+ return result;
229
+ };
230
+ this.insertSnippetForSelection = function(editor, snippetText) {
231
+ var cursor = editor.getCursorPosition();
232
+ var line = editor.session.getLine(cursor.row);
233
+ var tabString = editor.session.getTabString();
234
+ var indentString = line.match(/^\s*/)[0];
235
+ if (cursor.column < indentString.length)
236
+ indentString = indentString.slice(0, cursor.column);
237
+ snippetText = snippetText.replace(/\r/g, "");
238
+ var tokens = this.tokenizeTmSnippet(snippetText);
239
+ tokens = this.resolveVariables(tokens, editor);
240
+ tokens = tokens.map(function(x) {
241
+ if (x == "\n")
242
+ return x + indentString;
243
+ if (typeof x == "string")
244
+ return x.replace(/\t/g, tabString);
245
+ return x;
246
+ });
247
+ var tabstops = [];
248
+ tokens.forEach(function(p2, i2) {
249
+ if (typeof p2 != "object")
250
+ return;
251
+ var id2 = p2.tabstopId;
252
+ var ts2 = tabstops[id2];
253
+ if (!ts2) {
254
+ ts2 = tabstops[id2] = [];
255
+ ts2.index = id2;
256
+ ts2.value = "";
257
+ }
258
+ if (ts2.indexOf(p2) !== -1)
259
+ return;
260
+ ts2.push(p2);
261
+ var i12 = tokens.indexOf(p2, i2 + 1);
262
+ if (i12 === -1)
263
+ return;
264
+ var value = tokens.slice(i2 + 1, i12);
265
+ var isNested = value.some(function(t) {
266
+ return typeof t === "object";
267
+ });
268
+ if (isNested && !ts2.value) {
269
+ ts2.value = value;
270
+ } else if (value.length && (!ts2.value || typeof ts2.value !== "string")) {
271
+ ts2.value = value.join("");
272
+ }
273
+ });
274
+ tabstops.forEach(function(ts2) {
275
+ ts2.length = 0;
276
+ });
277
+ var expanding = {};
278
+ function copyValue(val) {
279
+ var copy = [];
280
+ for (var i2 = 0; i2 < val.length; i2++) {
281
+ var p2 = val[i2];
282
+ if (typeof p2 == "object") {
283
+ if (expanding[p2.tabstopId])
284
+ continue;
285
+ var j = val.lastIndexOf(p2, i2 - 1);
286
+ p2 = copy[j] || { tabstopId: p2.tabstopId };
287
+ }
288
+ copy[i2] = p2;
289
+ }
290
+ return copy;
291
+ }
292
+ for (var i = 0; i < tokens.length; i++) {
293
+ var p = tokens[i];
294
+ if (typeof p != "object")
295
+ continue;
296
+ var id = p.tabstopId;
297
+ var i1 = tokens.indexOf(p, i + 1);
298
+ if (expanding[id]) {
299
+ if (expanding[id] === p)
300
+ expanding[id] = null;
301
+ continue;
302
+ }
303
+ var ts = tabstops[id];
304
+ var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
305
+ arg.unshift(i + 1, Math.max(0, i1 - i));
306
+ arg.push(p);
307
+ expanding[id] = p;
308
+ tokens.splice.apply(tokens, arg);
309
+ if (ts.indexOf(p) === -1)
310
+ ts.push(p);
311
+ }
312
+ var row = 0, column = 0;
313
+ var text = "";
314
+ tokens.forEach(function(t) {
315
+ if (typeof t === "string") {
316
+ var lines = t.split("\n");
317
+ if (lines.length > 1) {
318
+ column = lines[lines.length - 1].length;
319
+ row += lines.length - 1;
320
+ } else
321
+ column += t.length;
322
+ text += t;
323
+ } else {
324
+ if (!t.start)
325
+ t.start = { row, column };
326
+ else
327
+ t.end = { row, column };
328
+ }
329
+ });
330
+ var range = editor.getSelectionRange();
331
+ var end = editor.session.replace(range, text);
332
+ var tabstopManager = new TabstopManager(editor);
333
+ var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
334
+ tabstopManager.addTabstops(tabstops, range.start, end, selectionId);
335
+ };
336
+ this.insertSnippet = function(editor, snippetText) {
337
+ var self = this;
338
+ if (editor.inVirtualSelectionMode)
339
+ return self.insertSnippetForSelection(editor, snippetText);
340
+ editor.forEachSelection(function() {
341
+ self.insertSnippetForSelection(editor, snippetText);
342
+ }, null, { keepOrder: true });
343
+ if (editor.tabstopManager)
344
+ editor.tabstopManager.tabNext();
345
+ };
346
+ this.$getScope = function(editor) {
347
+ var scope = editor.session.$mode.$id || "";
348
+ scope = scope.split("/").pop();
349
+ if (scope === "html" || scope === "php") {
350
+ if (scope === "php" && !editor.session.$mode.inlinePhp)
351
+ scope = "html";
352
+ var c = editor.getCursorPosition();
353
+ var state = editor.session.getState(c.row);
354
+ if (typeof state === "object") {
355
+ state = state[0];
356
+ }
357
+ if (state.substring) {
358
+ if (state.substring(0, 3) == "js-")
359
+ scope = "javascript";
360
+ else if (state.substring(0, 4) == "css-")
361
+ scope = "css";
362
+ else if (state.substring(0, 4) == "php-")
363
+ scope = "php";
364
+ }
365
+ }
366
+ return scope;
367
+ };
368
+ this.getActiveScopes = function(editor) {
369
+ var scope = this.$getScope(editor);
370
+ var scopes = [scope];
371
+ var snippetMap = this.snippetMap;
372
+ if (snippetMap[scope] && snippetMap[scope].includeScopes) {
373
+ scopes.push.apply(scopes, snippetMap[scope].includeScopes);
374
+ }
375
+ scopes.push("_");
376
+ return scopes;
377
+ };
378
+ this.expandWithTab = function(editor, options) {
379
+ var self = this;
380
+ var result = editor.forEachSelection(function() {
381
+ return self.expandSnippetForSelection(editor, options);
382
+ }, null, { keepOrder: true });
383
+ if (result && editor.tabstopManager)
384
+ editor.tabstopManager.tabNext();
385
+ return result;
386
+ };
387
+ this.expandSnippetForSelection = function(editor, options) {
388
+ var cursor = editor.getCursorPosition();
389
+ var line = editor.session.getLine(cursor.row);
390
+ var before = line.substring(0, cursor.column);
391
+ var after = line.substr(cursor.column);
392
+ var snippetMap = this.snippetMap;
393
+ var snippet;
394
+ this.getActiveScopes(editor).some(function(scope) {
395
+ var snippets = snippetMap[scope];
396
+ if (snippets)
397
+ snippet = this.findMatchingSnippet(snippets, before, after);
398
+ return !!snippet;
399
+ }, this);
400
+ if (!snippet)
401
+ return false;
402
+ if (options && options.dryRun)
403
+ return true;
404
+ editor.session.doc.removeInLine(
405
+ cursor.row,
406
+ cursor.column - snippet.replaceBefore.length,
407
+ cursor.column + snippet.replaceAfter.length
408
+ );
409
+ this.variables.M__ = snippet.matchBefore;
410
+ this.variables.T__ = snippet.matchAfter;
411
+ this.insertSnippetForSelection(editor, snippet.content);
412
+ this.variables.M__ = this.variables.T__ = null;
413
+ return true;
414
+ };
415
+ this.findMatchingSnippet = function(snippetList, before, after) {
416
+ for (var i = snippetList.length; i--; ) {
417
+ var s = snippetList[i];
418
+ if (s.startRe && !s.startRe.test(before))
419
+ continue;
420
+ if (s.endRe && !s.endRe.test(after))
421
+ continue;
422
+ if (!s.startRe && !s.endRe)
423
+ continue;
424
+ s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
425
+ s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
426
+ s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
427
+ s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
428
+ return s;
429
+ }
430
+ };
431
+ this.snippetMap = {};
432
+ this.snippetNameMap = {};
433
+ this.register = function(snippets, scope) {
434
+ var snippetMap = this.snippetMap;
435
+ var snippetNameMap = this.snippetNameMap;
436
+ var self = this;
437
+ if (!snippets)
438
+ snippets = [];
439
+ function wrapRegexp(src) {
440
+ if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
441
+ src = "(?:" + src + ")";
442
+ return src || "";
443
+ }
444
+ function guardedRegexp(re, guard, opening) {
445
+ re = wrapRegexp(re);
446
+ guard = wrapRegexp(guard);
447
+ if (opening) {
448
+ re = guard + re;
449
+ if (re && re[re.length - 1] != "$")
450
+ re = re + "$";
451
+ } else {
452
+ re = re + guard;
453
+ if (re && re[0] != "^")
454
+ re = "^" + re;
455
+ }
456
+ return new RegExp(re);
457
+ }
458
+ function addSnippet(s) {
459
+ if (!s.scope)
460
+ s.scope = scope || "_";
461
+ scope = s.scope;
462
+ if (!snippetMap[scope]) {
463
+ snippetMap[scope] = [];
464
+ snippetNameMap[scope] = {};
465
+ }
466
+ var map = snippetNameMap[scope];
467
+ if (s.name) {
468
+ var old = map[s.name];
469
+ if (old)
470
+ self.unregister(old);
471
+ map[s.name] = s;
472
+ }
473
+ snippetMap[scope].push(s);
474
+ if (s.tabTrigger && !s.trigger) {
475
+ if (!s.guard && /^\w/.test(s.tabTrigger))
476
+ s.guard = "\\b";
477
+ s.trigger = lang.escapeRegExp(s.tabTrigger);
478
+ }
479
+ if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard)
480
+ return;
481
+ s.startRe = guardedRegexp(s.trigger, s.guard, true);
482
+ s.triggerRe = new RegExp(s.trigger, "", true);
483
+ s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
484
+ s.endTriggerRe = new RegExp(s.endTrigger, "", true);
485
+ }
486
+ if (snippets && snippets.content)
487
+ addSnippet(snippets);
488
+ else if (Array.isArray(snippets))
489
+ snippets.forEach(addSnippet);
490
+ this._signal("registerSnippets", { scope });
491
+ };
492
+ this.unregister = function(snippets, scope) {
493
+ var snippetMap = this.snippetMap;
494
+ var snippetNameMap = this.snippetNameMap;
495
+ function removeSnippet(s) {
496
+ var nameMap = snippetNameMap[s.scope || scope];
497
+ if (nameMap && nameMap[s.name]) {
498
+ delete nameMap[s.name];
499
+ var map = snippetMap[s.scope || scope];
500
+ var i = map && map.indexOf(s);
501
+ if (i >= 0)
502
+ map.splice(i, 1);
503
+ }
504
+ }
505
+ if (snippets.content)
506
+ removeSnippet(snippets);
507
+ else if (Array.isArray(snippets))
508
+ snippets.forEach(removeSnippet);
509
+ };
510
+ this.parseSnippetFile = function(str) {
511
+ str = str.replace(/\r/g, "");
512
+ var list = [], snippet = {};
513
+ var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
514
+ var m;
515
+ while (m = re.exec(str)) {
516
+ if (m[1]) {
517
+ try {
518
+ snippet = JSON.parse(m[1]);
519
+ list.push(snippet);
520
+ } catch (e) {
521
+ }
522
+ }
523
+ if (m[4]) {
524
+ snippet.content = m[4].replace(/^\t/gm, "");
525
+ list.push(snippet);
526
+ snippet = {};
527
+ } else {
528
+ var key = m[2], val = m[3];
529
+ if (key == "regex") {
530
+ var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
531
+ snippet.guard = guardRe.exec(val)[1];
532
+ snippet.trigger = guardRe.exec(val)[1];
533
+ snippet.endTrigger = guardRe.exec(val)[1];
534
+ snippet.endGuard = guardRe.exec(val)[1];
535
+ } else if (key == "snippet") {
536
+ snippet.tabTrigger = val.match(/^\S*/)[0];
537
+ if (!snippet.name)
538
+ snippet.name = val;
539
+ } else {
540
+ snippet[key] = val;
541
+ }
542
+ }
543
+ }
544
+ return list;
545
+ };
546
+ this.getSnippetByName = function(name, editor) {
547
+ var snippetMap = this.snippetNameMap;
548
+ var snippet;
549
+ this.getActiveScopes(editor).some(function(scope) {
550
+ var snippets = snippetMap[scope];
551
+ if (snippets)
552
+ snippet = snippets[name];
553
+ return !!snippet;
554
+ }, this);
555
+ return snippet;
556
+ };
557
+ }).call(SnippetManager.prototype);
558
+ var TabstopManager = function(editor) {
559
+ if (editor.tabstopManager)
560
+ return editor.tabstopManager;
561
+ editor.tabstopManager = this;
562
+ this.$onChange = this.onChange.bind(this);
563
+ this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
564
+ this.$onChangeSession = this.onChangeSession.bind(this);
565
+ this.$onAfterExec = this.onAfterExec.bind(this);
566
+ this.attach(editor);
567
+ };
568
+ (function() {
569
+ this.attach = function(editor) {
570
+ this.index = 0;
571
+ this.ranges = [];
572
+ this.tabstops = [];
573
+ this.$openTabstops = null;
574
+ this.selectedTabstop = null;
575
+ this.editor = editor;
576
+ this.editor.on("change", this.$onChange);
577
+ this.editor.on("changeSelection", this.$onChangeSelection);
578
+ this.editor.on("changeSession", this.$onChangeSession);
579
+ this.editor.commands.on("afterExec", this.$onAfterExec);
580
+ this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
581
+ };
582
+ this.detach = function() {
583
+ this.tabstops.forEach(this.removeTabstopMarkers, this);
584
+ this.ranges = null;
585
+ this.tabstops = null;
586
+ this.selectedTabstop = null;
587
+ this.editor.removeListener("change", this.$onChange);
588
+ this.editor.removeListener("changeSelection", this.$onChangeSelection);
589
+ this.editor.removeListener("changeSession", this.$onChangeSession);
590
+ this.editor.commands.removeListener("afterExec", this.$onAfterExec);
591
+ this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
592
+ this.editor.tabstopManager = null;
593
+ this.editor = null;
594
+ };
595
+ this.onChange = function(delta) {
596
+ var isRemove = delta.action[0] == "r";
597
+ var start = delta.start;
598
+ var end = delta.end;
599
+ var startRow = start.row;
600
+ var endRow = end.row;
601
+ var lineDif = endRow - startRow;
602
+ var colDiff = end.column - start.column;
603
+ if (isRemove) {
604
+ lineDif = -lineDif;
605
+ colDiff = -colDiff;
606
+ }
607
+ if (!this.$inChange && isRemove) {
608
+ var ts = this.selectedTabstop;
609
+ var changedOutside = ts && !ts.some(function(r2) {
610
+ return comparePoints(r2.start, start) <= 0 && comparePoints(r2.end, end) >= 0;
611
+ });
612
+ if (changedOutside)
613
+ return this.detach();
614
+ }
615
+ var ranges = this.ranges;
616
+ for (var i = 0; i < ranges.length; i++) {
617
+ var r = ranges[i];
618
+ if (r.end.row < start.row)
619
+ continue;
620
+ if (isRemove && comparePoints(start, r.start) < 0 && comparePoints(end, r.end) > 0) {
621
+ this.removeRange(r);
622
+ i--;
623
+ continue;
624
+ }
625
+ if (r.start.row == startRow && r.start.column > start.column)
626
+ r.start.column += colDiff;
627
+ if (r.end.row == startRow && r.end.column >= start.column)
628
+ r.end.column += colDiff;
629
+ if (r.start.row >= startRow)
630
+ r.start.row += lineDif;
631
+ if (r.end.row >= startRow)
632
+ r.end.row += lineDif;
633
+ if (comparePoints(r.start, r.end) > 0)
634
+ this.removeRange(r);
635
+ }
636
+ if (!ranges.length)
637
+ this.detach();
638
+ };
639
+ this.updateLinkedFields = function() {
640
+ var ts = this.selectedTabstop;
641
+ if (!ts || !ts.hasLinkedRanges)
642
+ return;
643
+ this.$inChange = true;
644
+ var session = this.editor.session;
645
+ var text = session.getTextRange(ts.firstNonLinked);
646
+ for (var i = ts.length; i--; ) {
647
+ var range = ts[i];
648
+ if (!range.linked)
649
+ continue;
650
+ var fmt = exports.snippetManager.tmStrFormat(text, range.original);
651
+ session.replace(range, fmt);
652
+ }
653
+ this.$inChange = false;
654
+ };
655
+ this.onAfterExec = function(e) {
656
+ if (e.command && !e.command.readOnly)
657
+ this.updateLinkedFields();
658
+ };
659
+ this.onChangeSelection = function() {
660
+ if (!this.editor)
661
+ return;
662
+ var lead = this.editor.selection.lead;
663
+ var anchor = this.editor.selection.anchor;
664
+ var isEmpty = this.editor.selection.isEmpty();
665
+ for (var i = this.ranges.length; i--; ) {
666
+ if (this.ranges[i].linked)
667
+ continue;
668
+ var containsLead = this.ranges[i].contains(lead.row, lead.column);
669
+ var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
670
+ if (containsLead && containsAnchor)
671
+ return;
672
+ }
673
+ this.detach();
674
+ };
675
+ this.onChangeSession = function() {
676
+ this.detach();
677
+ };
678
+ this.tabNext = function(dir) {
679
+ var max = this.tabstops.length;
680
+ var index = this.index + (dir || 1);
681
+ index = Math.min(Math.max(index, 1), max);
682
+ if (index == max)
683
+ index = 0;
684
+ this.selectTabstop(index);
685
+ if (index === 0)
686
+ this.detach();
687
+ };
688
+ this.selectTabstop = function(index) {
689
+ this.$openTabstops = null;
690
+ var ts = this.tabstops[this.index];
691
+ if (ts)
692
+ this.addTabstopMarkers(ts);
693
+ this.index = index;
694
+ ts = this.tabstops[this.index];
695
+ if (!ts || !ts.length)
696
+ return;
697
+ this.selectedTabstop = ts;
698
+ if (!this.editor.inVirtualSelectionMode) {
699
+ var sel = this.editor.multiSelect;
700
+ sel.toSingleRange(ts.firstNonLinked.clone());
701
+ for (var i = ts.length; i--; ) {
702
+ if (ts.hasLinkedRanges && ts[i].linked)
703
+ continue;
704
+ sel.addRange(ts[i].clone(), true);
705
+ }
706
+ if (sel.ranges[0])
707
+ sel.addRange(sel.ranges[0].clone());
708
+ } else {
709
+ this.editor.selection.setRange(ts.firstNonLinked);
710
+ }
711
+ this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
712
+ };
713
+ this.addTabstops = function(tabstops, start, end) {
714
+ if (!this.$openTabstops)
715
+ this.$openTabstops = [];
716
+ if (!tabstops[0]) {
717
+ var p = Range.fromPoints(end, end);
718
+ moveRelative(p.start, start);
719
+ moveRelative(p.end, start);
720
+ tabstops[0] = [p];
721
+ tabstops[0].index = 0;
722
+ }
723
+ var i = this.index;
724
+ var arg = [i + 1, 0];
725
+ var ranges = this.ranges;
726
+ tabstops.forEach(function(ts, index) {
727
+ var dest = this.$openTabstops[index] || ts;
728
+ for (var i2 = ts.length; i2--; ) {
729
+ var p2 = ts[i2];
730
+ var range = Range.fromPoints(p2.start, p2.end || p2.start);
731
+ movePoint(range.start, start);
732
+ movePoint(range.end, start);
733
+ range.original = p2;
734
+ range.tabstop = dest;
735
+ ranges.push(range);
736
+ if (dest != ts)
737
+ dest.unshift(range);
738
+ else
739
+ dest[i2] = range;
740
+ if (p2.fmtString) {
741
+ range.linked = true;
742
+ dest.hasLinkedRanges = true;
743
+ } else if (!dest.firstNonLinked)
744
+ dest.firstNonLinked = range;
745
+ }
746
+ if (!dest.firstNonLinked)
747
+ dest.hasLinkedRanges = false;
748
+ if (dest === ts) {
749
+ arg.push(dest);
750
+ this.$openTabstops[index] = dest;
751
+ }
752
+ this.addTabstopMarkers(dest);
753
+ }, this);
754
+ if (arg.length > 2) {
755
+ if (this.tabstops.length)
756
+ arg.push(arg.splice(2, 1)[0]);
757
+ this.tabstops.splice.apply(this.tabstops, arg);
758
+ }
759
+ };
760
+ this.addTabstopMarkers = function(ts) {
761
+ var session = this.editor.session;
762
+ ts.forEach(function(range) {
763
+ if (!range.markerId)
764
+ range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
765
+ });
766
+ };
767
+ this.removeTabstopMarkers = function(ts) {
768
+ var session = this.editor.session;
769
+ ts.forEach(function(range) {
770
+ session.removeMarker(range.markerId);
771
+ range.markerId = null;
772
+ });
773
+ };
774
+ this.removeRange = function(range) {
775
+ var i = range.tabstop.indexOf(range);
776
+ range.tabstop.splice(i, 1);
777
+ i = this.ranges.indexOf(range);
778
+ this.ranges.splice(i, 1);
779
+ this.editor.session.removeMarker(range.markerId);
780
+ if (!range.tabstop.length) {
781
+ i = this.tabstops.indexOf(range.tabstop);
782
+ if (i != -1)
783
+ this.tabstops.splice(i, 1);
784
+ if (!this.tabstops.length)
785
+ this.detach();
786
+ }
787
+ };
788
+ this.keyboardHandler = new HashHandler();
789
+ this.keyboardHandler.bindKeys({
790
+ "Tab": function(ed) {
791
+ if (exports.snippetManager && exports.snippetManager.expandWithTab(ed)) {
792
+ return;
793
+ }
794
+ ed.tabstopManager.tabNext(1);
795
+ },
796
+ "Shift-Tab": function(ed) {
797
+ ed.tabstopManager.tabNext(-1);
798
+ },
799
+ "Esc": function(ed) {
800
+ ed.tabstopManager.detach();
801
+ },
802
+ "Return": function(ed) {
803
+ return false;
804
+ }
805
+ });
806
+ }).call(TabstopManager.prototype);
807
+ Anchor.prototype.onChange;
808
+ var movePoint = function(point, diff) {
809
+ if (point.row == 0)
810
+ point.column += diff.column;
811
+ point.row += diff.row;
812
+ };
813
+ var moveRelative = function(point, start) {
814
+ if (point.row == start.row)
815
+ point.column -= start.column;
816
+ point.row -= start.row;
817
+ };
818
+ acequire("./lib/dom").importCssString(".ace_snippet-marker { -moz-box-sizing: border-box; box-sizing: border-box; background: rgba(194, 193, 208, 0.09); border: 1px dotted rgba(211, 208, 235, 0.62); position: absolute;}");
819
+ exports.snippetManager = new SnippetManager();
820
+ var Editor = acequire("./editor").Editor;
821
+ (function() {
822
+ this.insertSnippet = function(content, options) {
823
+ return exports.snippetManager.insertSnippet(this, content, options);
824
+ };
825
+ this.expandSnippet = function(options) {
826
+ return exports.snippetManager.expandWithTab(this, options);
827
+ };
828
+ }).call(Editor.prototype);
829
+ });
830
+ ace.define("ace/autocomplete/popup", ["require", "exports", "module", "ace/virtual_renderer", "ace/editor", "ace/range", "ace/lib/event", "ace/lib/lang", "ace/lib/dom"], function(acequire, exports, module) {
831
+ var Renderer = acequire("../virtual_renderer").VirtualRenderer;
832
+ var Editor = acequire("../editor").Editor;
833
+ var Range = acequire("../range").Range;
834
+ var event = acequire("../lib/event");
835
+ var lang = acequire("../lib/lang");
836
+ var dom = acequire("../lib/dom");
837
+ var $singleLineEditor = function(el) {
838
+ var renderer = new Renderer(el);
839
+ renderer.$maxLines = 4;
840
+ var editor = new Editor(renderer);
841
+ editor.setHighlightActiveLine(false);
842
+ editor.setShowPrintMargin(false);
843
+ editor.renderer.setShowGutter(false);
844
+ editor.renderer.setHighlightGutterLine(false);
845
+ editor.$mouseHandler.$focusWaitTimout = 0;
846
+ editor.$highlightTagPending = true;
847
+ return editor;
848
+ };
849
+ var AcePopup = function(parentNode) {
850
+ var el = dom.createElement("div");
851
+ var popup = new $singleLineEditor(el);
852
+ if (parentNode)
853
+ parentNode.appendChild(el);
854
+ el.style.display = "none";
855
+ popup.renderer.content.style.cursor = "default";
856
+ popup.renderer.setStyle("ace_autocomplete");
857
+ popup.setOption("displayIndentGuides", false);
858
+ popup.setOption("dragDelay", 150);
859
+ var noop = function() {
860
+ };
861
+ popup.focus = noop;
862
+ popup.$isFocused = true;
863
+ popup.renderer.$cursorLayer.restartTimer = noop;
864
+ popup.renderer.$cursorLayer.element.style.opacity = 0;
865
+ popup.renderer.$maxLines = 8;
866
+ popup.renderer.$keepTextAreaAtCursor = false;
867
+ popup.setHighlightActiveLine(false);
868
+ popup.session.highlight("");
869
+ popup.session.$searchHighlight.clazz = "ace_highlight-marker";
870
+ popup.on("mousedown", function(e) {
871
+ var pos = e.getDocumentPosition();
872
+ popup.selection.moveToPosition(pos);
873
+ selectionMarker.start.row = selectionMarker.end.row = pos.row;
874
+ e.stop();
875
+ });
876
+ var lastMouseEvent;
877
+ var hoverMarker = new Range(-1, 0, -1, Infinity);
878
+ var selectionMarker = new Range(-1, 0, -1, Infinity);
879
+ selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
880
+ popup.setSelectOnHover = function(val) {
881
+ if (!val) {
882
+ hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
883
+ } else if (hoverMarker.id) {
884
+ popup.session.removeMarker(hoverMarker.id);
885
+ hoverMarker.id = null;
886
+ }
887
+ };
888
+ popup.setSelectOnHover(false);
889
+ popup.on("mousemove", function(e) {
890
+ if (!lastMouseEvent) {
891
+ lastMouseEvent = e;
892
+ return;
893
+ }
894
+ if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
895
+ return;
896
+ }
897
+ lastMouseEvent = e;
898
+ lastMouseEvent.scrollTop = popup.renderer.scrollTop;
899
+ var row = lastMouseEvent.getDocumentPosition().row;
900
+ if (hoverMarker.start.row != row) {
901
+ if (!hoverMarker.id)
902
+ popup.setRow(row);
903
+ setHoverMarker(row);
904
+ }
905
+ });
906
+ popup.renderer.on("beforeRender", function() {
907
+ if (lastMouseEvent && hoverMarker.start.row != -1) {
908
+ lastMouseEvent.$pos = null;
909
+ var row = lastMouseEvent.getDocumentPosition().row;
910
+ if (!hoverMarker.id)
911
+ popup.setRow(row);
912
+ setHoverMarker(row, true);
913
+ }
914
+ });
915
+ popup.renderer.on("afterRender", function() {
916
+ var row = popup.getRow();
917
+ var t = popup.renderer.$textLayer;
918
+ var selected = t.element.childNodes[row - t.config.firstRow];
919
+ if (selected == t.selectedNode)
920
+ return;
921
+ if (t.selectedNode)
922
+ dom.removeCssClass(t.selectedNode, "ace_selected");
923
+ t.selectedNode = selected;
924
+ if (selected)
925
+ dom.addCssClass(selected, "ace_selected");
926
+ });
927
+ var hideHoverMarker = function() {
928
+ setHoverMarker(-1);
929
+ };
930
+ var setHoverMarker = function(row, suppressRedraw) {
931
+ if (row !== hoverMarker.start.row) {
932
+ hoverMarker.start.row = hoverMarker.end.row = row;
933
+ if (!suppressRedraw)
934
+ popup.session._emit("changeBackMarker");
935
+ popup._emit("changeHoverMarker");
936
+ }
937
+ };
938
+ popup.getHoveredRow = function() {
939
+ return hoverMarker.start.row;
940
+ };
941
+ event.addListener(popup.container, "mouseout", hideHoverMarker);
942
+ popup.on("hide", hideHoverMarker);
943
+ popup.on("changeSelection", hideHoverMarker);
944
+ popup.session.doc.getLength = function() {
945
+ return popup.data.length;
946
+ };
947
+ popup.session.doc.getLine = function(i) {
948
+ var data = popup.data[i];
949
+ if (typeof data == "string")
950
+ return data;
951
+ return data && data.value || "";
952
+ };
953
+ var bgTokenizer = popup.session.bgTokenizer;
954
+ bgTokenizer.$tokenizeRow = function(row) {
955
+ var data = popup.data[row];
956
+ var tokens = [];
957
+ if (!data)
958
+ return tokens;
959
+ if (typeof data == "string")
960
+ data = { value: data };
961
+ if (!data.caption)
962
+ data.caption = data.value || data.name;
963
+ var last = -1;
964
+ var flag, c;
965
+ for (var i = 0; i < data.caption.length; i++) {
966
+ c = data.caption[i];
967
+ flag = data.matchMask & 1 << i ? 1 : 0;
968
+ if (last !== flag) {
969
+ tokens.push({ type: data.className || (flag ? "completion-highlight" : ""), value: c });
970
+ last = flag;
971
+ } else {
972
+ tokens[tokens.length - 1].value += c;
973
+ }
974
+ }
975
+ if (data.meta) {
976
+ var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
977
+ var metaData = data.meta;
978
+ if (metaData.length + data.caption.length > maxW - 2) {
979
+ metaData = metaData.substr(0, maxW - data.caption.length - 3) + "…";
980
+ }
981
+ tokens.push({ type: "rightAlignedText", value: metaData });
982
+ }
983
+ return tokens;
984
+ };
985
+ bgTokenizer.$updateOnChange = noop;
986
+ bgTokenizer.start = noop;
987
+ popup.session.$computeWidth = function() {
988
+ return this.screenWidth = 0;
989
+ };
990
+ popup.$blockScrolling = Infinity;
991
+ popup.isOpen = false;
992
+ popup.isTopdown = false;
993
+ popup.autoSelect = true;
994
+ popup.data = [];
995
+ popup.setData = function(list) {
996
+ popup.setValue(lang.stringRepeat("\n", list.length), -1);
997
+ popup.data = list || [];
998
+ popup.setRow(0);
999
+ };
1000
+ popup.getData = function(row) {
1001
+ return popup.data[row];
1002
+ };
1003
+ popup.getRow = function() {
1004
+ return selectionMarker.start.row;
1005
+ };
1006
+ popup.setRow = function(line) {
1007
+ line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length, line));
1008
+ if (selectionMarker.start.row != line) {
1009
+ popup.selection.clearSelection();
1010
+ selectionMarker.start.row = selectionMarker.end.row = line || 0;
1011
+ popup.session._emit("changeBackMarker");
1012
+ popup.moveCursorTo(line || 0, 0);
1013
+ if (popup.isOpen)
1014
+ popup._signal("select");
1015
+ }
1016
+ };
1017
+ popup.on("changeSelection", function() {
1018
+ if (popup.isOpen)
1019
+ popup.setRow(popup.selection.lead.row);
1020
+ popup.renderer.scrollCursorIntoView();
1021
+ });
1022
+ popup.hide = function() {
1023
+ this.container.style.display = "none";
1024
+ this._signal("hide");
1025
+ popup.isOpen = false;
1026
+ };
1027
+ popup.show = function(pos, lineHeight, topdownOnly) {
1028
+ var el2 = this.container;
1029
+ var screenHeight = window.innerHeight;
1030
+ var screenWidth = window.innerWidth;
1031
+ var renderer = this.renderer;
1032
+ var maxH = renderer.$maxLines * lineHeight * 1.4;
1033
+ var top = pos.top + this.$borderSize;
1034
+ var allowTopdown = top > screenHeight / 2 && !topdownOnly;
1035
+ if (allowTopdown && top + lineHeight + maxH > screenHeight) {
1036
+ renderer.$maxPixelHeight = top - 2 * this.$borderSize;
1037
+ el2.style.top = "";
1038
+ el2.style.bottom = screenHeight - top + "px";
1039
+ popup.isTopdown = false;
1040
+ } else {
1041
+ top += lineHeight;
1042
+ renderer.$maxPixelHeight = screenHeight - top - 0.2 * lineHeight;
1043
+ el2.style.top = top + "px";
1044
+ el2.style.bottom = "";
1045
+ popup.isTopdown = true;
1046
+ }
1047
+ el2.style.display = "";
1048
+ this.renderer.$textLayer.checkForSizeChanges();
1049
+ var left = pos.left;
1050
+ if (left + el2.offsetWidth > screenWidth)
1051
+ left = screenWidth - el2.offsetWidth;
1052
+ el2.style.left = left + "px";
1053
+ this._signal("show");
1054
+ lastMouseEvent = null;
1055
+ popup.isOpen = true;
1056
+ };
1057
+ popup.getTextLeftOffset = function() {
1058
+ return this.$borderSize + this.renderer.$padding + this.$imageSize;
1059
+ };
1060
+ popup.$imageSize = 0;
1061
+ popup.$borderSize = 1;
1062
+ return popup;
1063
+ };
1064
+ dom.importCssString(".ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line { background-color: #CAD6FA; z-index: 1;}.ace_editor.ace_autocomplete .ace_line-hover { border: 1px solid #abbffe; margin-top: -1px; background: rgba(233,233,253,0.4);}.ace_editor.ace_autocomplete .ace_line-hover { position: absolute; z-index: 2;}.ace_editor.ace_autocomplete .ace_scroller { background: none; border: none; box-shadow: none;}.ace_rightAlignedText { color: gray; display: inline-block; position: absolute; right: 4px; text-align: right; z-index: -1;}.ace_editor.ace_autocomplete .ace_completion-highlight{ color: #000; text-shadow: 0 0 0.01em;}.ace_editor.ace_autocomplete { width: 280px; z-index: 200000; background: #fbfbfb; color: #444; border: 1px lightgray solid; position: fixed; box-shadow: 2px 3px 5px rgba(0,0,0,.2); line-height: 1.4;}");
1065
+ exports.AcePopup = AcePopup;
1066
+ });
1067
+ ace.define("ace/autocomplete/util", ["require", "exports", "module"], function(acequire, exports, module) {
1068
+ exports.parForEach = function(array, fn, callback) {
1069
+ var completed = 0;
1070
+ var arLength = array.length;
1071
+ if (arLength === 0)
1072
+ callback();
1073
+ for (var i = 0; i < arLength; i++) {
1074
+ fn(array[i], function(result, err) {
1075
+ completed++;
1076
+ if (completed === arLength)
1077
+ callback(result, err);
1078
+ });
1079
+ }
1080
+ };
1081
+ var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;
1082
+ exports.retrievePrecedingIdentifier = function(text, pos, regex) {
1083
+ regex = regex || ID_REGEX;
1084
+ var buf = [];
1085
+ for (var i = pos - 1; i >= 0; i--) {
1086
+ if (regex.test(text[i]))
1087
+ buf.push(text[i]);
1088
+ else
1089
+ break;
1090
+ }
1091
+ return buf.reverse().join("");
1092
+ };
1093
+ exports.retrieveFollowingIdentifier = function(text, pos, regex) {
1094
+ regex = regex || ID_REGEX;
1095
+ var buf = [];
1096
+ for (var i = pos; i < text.length; i++) {
1097
+ if (regex.test(text[i]))
1098
+ buf.push(text[i]);
1099
+ else
1100
+ break;
1101
+ }
1102
+ return buf;
1103
+ };
1104
+ exports.getCompletionPrefix = function(editor) {
1105
+ var pos = editor.getCursorPosition();
1106
+ var line = editor.session.getLine(pos.row);
1107
+ var prefix;
1108
+ editor.completers.forEach((function(completer) {
1109
+ if (completer.identifierRegexps) {
1110
+ completer.identifierRegexps.forEach((function(identifierRegex) {
1111
+ if (!prefix && identifierRegex)
1112
+ prefix = this.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
1113
+ }).bind(this));
1114
+ }
1115
+ }).bind(this));
1116
+ return prefix || this.retrievePrecedingIdentifier(line, pos.column);
1117
+ };
1118
+ });
1119
+ ace.define("ace/autocomplete", ["require", "exports", "module", "ace/keyboard/hash_handler", "ace/autocomplete/popup", "ace/autocomplete/util", "ace/lib/event", "ace/lib/lang", "ace/lib/dom", "ace/snippets"], function(acequire, exports, module) {
1120
+ var HashHandler = acequire("./keyboard/hash_handler").HashHandler;
1121
+ var AcePopup = acequire("./autocomplete/popup").AcePopup;
1122
+ var util = acequire("./autocomplete/util");
1123
+ acequire("./lib/event");
1124
+ var lang = acequire("./lib/lang");
1125
+ var dom = acequire("./lib/dom");
1126
+ var snippetManager = acequire("./snippets").snippetManager;
1127
+ var Autocomplete = function() {
1128
+ this.autoInsert = false;
1129
+ this.autoSelect = true;
1130
+ this.exactMatch = false;
1131
+ this.gatherCompletionsId = 0;
1132
+ this.keyboardHandler = new HashHandler();
1133
+ this.keyboardHandler.bindKeys(this.commands);
1134
+ this.blurListener = this.blurListener.bind(this);
1135
+ this.changeListener = this.changeListener.bind(this);
1136
+ this.mousedownListener = this.mousedownListener.bind(this);
1137
+ this.mousewheelListener = this.mousewheelListener.bind(this);
1138
+ this.changeTimer = lang.delayedCall((function() {
1139
+ this.updateCompletions(true);
1140
+ }).bind(this));
1141
+ this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50);
1142
+ };
1143
+ (function() {
1144
+ this.$init = function() {
1145
+ this.popup = new AcePopup(document.body || document.documentElement);
1146
+ this.popup.on("click", (function(e) {
1147
+ this.insertMatch();
1148
+ e.stop();
1149
+ }).bind(this));
1150
+ this.popup.focus = this.editor.focus.bind(this.editor);
1151
+ this.popup.on("show", this.tooltipTimer.bind(null, null));
1152
+ this.popup.on("select", this.tooltipTimer.bind(null, null));
1153
+ this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null));
1154
+ return this.popup;
1155
+ };
1156
+ this.getPopup = function() {
1157
+ return this.popup || this.$init();
1158
+ };
1159
+ this.openPopup = function(editor, prefix, keepPopupPosition) {
1160
+ if (!this.popup)
1161
+ this.$init();
1162
+ this.popup.autoSelect = this.autoSelect;
1163
+ this.popup.setData(this.completions.filtered);
1164
+ editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
1165
+ var renderer = editor.renderer;
1166
+ this.popup.setRow(this.autoSelect ? 0 : -1);
1167
+ if (!keepPopupPosition) {
1168
+ this.popup.setTheme(editor.getTheme());
1169
+ this.popup.setFontSize(editor.getFontSize());
1170
+ var lineHeight = renderer.layerConfig.lineHeight;
1171
+ var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
1172
+ pos.left -= this.popup.getTextLeftOffset();
1173
+ var rect = editor.container.getBoundingClientRect();
1174
+ pos.top += rect.top - renderer.layerConfig.offset;
1175
+ pos.left += rect.left - editor.renderer.scrollLeft;
1176
+ pos.left += renderer.gutterWidth;
1177
+ this.popup.show(pos, lineHeight);
1178
+ } else if (keepPopupPosition && !prefix) {
1179
+ this.detach();
1180
+ }
1181
+ };
1182
+ this.detach = function() {
1183
+ this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
1184
+ this.editor.off("changeSelection", this.changeListener);
1185
+ this.editor.off("blur", this.blurListener);
1186
+ this.editor.off("mousedown", this.mousedownListener);
1187
+ this.editor.off("mousewheel", this.mousewheelListener);
1188
+ this.changeTimer.cancel();
1189
+ this.hideDocTooltip();
1190
+ this.gatherCompletionsId += 1;
1191
+ if (this.popup && this.popup.isOpen)
1192
+ this.popup.hide();
1193
+ if (this.base)
1194
+ this.base.detach();
1195
+ this.activated = false;
1196
+ this.completions = this.base = null;
1197
+ };
1198
+ this.changeListener = function(e) {
1199
+ var cursor = this.editor.selection.lead;
1200
+ if (cursor.row != this.base.row || cursor.column < this.base.column) {
1201
+ this.detach();
1202
+ }
1203
+ if (this.activated)
1204
+ this.changeTimer.schedule();
1205
+ else
1206
+ this.detach();
1207
+ };
1208
+ this.blurListener = function(e) {
1209
+ var el = document.activeElement;
1210
+ var text = this.editor.textInput.getElement();
1211
+ var fromTooltip = e.relatedTarget && this.tooltipNode && this.tooltipNode.contains(e.relatedTarget);
1212
+ var container = this.popup && this.popup.container;
1213
+ if (el != text && el.parentNode != container && !fromTooltip && el != this.tooltipNode && e.relatedTarget != text) {
1214
+ this.detach();
1215
+ }
1216
+ };
1217
+ this.mousedownListener = function(e) {
1218
+ this.detach();
1219
+ };
1220
+ this.mousewheelListener = function(e) {
1221
+ this.detach();
1222
+ };
1223
+ this.goTo = function(where) {
1224
+ var row = this.popup.getRow();
1225
+ var max = this.popup.session.getLength() - 1;
1226
+ switch (where) {
1227
+ case "up":
1228
+ row = row <= 0 ? max : row - 1;
1229
+ break;
1230
+ case "down":
1231
+ row = row >= max ? -1 : row + 1;
1232
+ break;
1233
+ case "start":
1234
+ row = 0;
1235
+ break;
1236
+ case "end":
1237
+ row = max;
1238
+ break;
1239
+ }
1240
+ this.popup.setRow(row);
1241
+ };
1242
+ this.insertMatch = function(data, options) {
1243
+ if (!data)
1244
+ data = this.popup.getData(this.popup.getRow());
1245
+ if (!data)
1246
+ return false;
1247
+ if (data.completer && data.completer.insertMatch) {
1248
+ data.completer.insertMatch(this.editor, data);
1249
+ } else {
1250
+ if (this.completions.filterText) {
1251
+ var ranges = this.editor.selection.getAllRanges();
1252
+ for (var i = 0, range; range = ranges[i]; i++) {
1253
+ range.start.column -= this.completions.filterText.length;
1254
+ this.editor.session.remove(range);
1255
+ }
1256
+ }
1257
+ if (data.snippet)
1258
+ snippetManager.insertSnippet(this.editor, data.snippet);
1259
+ else
1260
+ this.editor.execCommand("insertstring", data.value || data);
1261
+ }
1262
+ this.detach();
1263
+ };
1264
+ this.commands = {
1265
+ "Up": function(editor) {
1266
+ editor.completer.goTo("up");
1267
+ },
1268
+ "Down": function(editor) {
1269
+ editor.completer.goTo("down");
1270
+ },
1271
+ "Ctrl-Up|Ctrl-Home": function(editor) {
1272
+ editor.completer.goTo("start");
1273
+ },
1274
+ "Ctrl-Down|Ctrl-End": function(editor) {
1275
+ editor.completer.goTo("end");
1276
+ },
1277
+ "Esc": function(editor) {
1278
+ editor.completer.detach();
1279
+ },
1280
+ "Return": function(editor) {
1281
+ return editor.completer.insertMatch();
1282
+ },
1283
+ "Shift-Return": function(editor) {
1284
+ editor.completer.insertMatch(null, { deleteSuffix: true });
1285
+ },
1286
+ "Tab": function(editor) {
1287
+ var result = editor.completer.insertMatch();
1288
+ if (!result && !editor.tabstopManager)
1289
+ editor.completer.goTo("down");
1290
+ else
1291
+ return result;
1292
+ },
1293
+ "PageUp": function(editor) {
1294
+ editor.completer.popup.gotoPageUp();
1295
+ },
1296
+ "PageDown": function(editor) {
1297
+ editor.completer.popup.gotoPageDown();
1298
+ }
1299
+ };
1300
+ this.gatherCompletions = function(editor, callback) {
1301
+ var session = editor.getSession();
1302
+ var pos = editor.getCursorPosition();
1303
+ var prefix = util.getCompletionPrefix(editor);
1304
+ this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
1305
+ this.base.$insertRight = true;
1306
+ var matches = [];
1307
+ var total = editor.completers.length;
1308
+ editor.completers.forEach(function(completer, i) {
1309
+ completer.getCompletions(editor, session, pos, prefix, function(err, results) {
1310
+ if (!err && results)
1311
+ matches = matches.concat(results);
1312
+ callback(null, {
1313
+ prefix: util.getCompletionPrefix(editor),
1314
+ matches,
1315
+ finished: --total === 0
1316
+ });
1317
+ });
1318
+ });
1319
+ return true;
1320
+ };
1321
+ this.showPopup = function(editor) {
1322
+ if (this.editor)
1323
+ this.detach();
1324
+ this.activated = true;
1325
+ this.editor = editor;
1326
+ if (editor.completer != this) {
1327
+ if (editor.completer)
1328
+ editor.completer.detach();
1329
+ editor.completer = this;
1330
+ }
1331
+ editor.on("changeSelection", this.changeListener);
1332
+ editor.on("blur", this.blurListener);
1333
+ editor.on("mousedown", this.mousedownListener);
1334
+ editor.on("mousewheel", this.mousewheelListener);
1335
+ this.updateCompletions();
1336
+ };
1337
+ this.updateCompletions = function(keepPopupPosition) {
1338
+ if (keepPopupPosition && this.base && this.completions) {
1339
+ var pos = this.editor.getCursorPosition();
1340
+ var prefix = this.editor.session.getTextRange({ start: this.base, end: pos });
1341
+ if (prefix == this.completions.filterText)
1342
+ return;
1343
+ this.completions.setFilter(prefix);
1344
+ if (!this.completions.filtered.length)
1345
+ return this.detach();
1346
+ if (this.completions.filtered.length == 1 && this.completions.filtered[0].value == prefix && !this.completions.filtered[0].snippet)
1347
+ return this.detach();
1348
+ this.openPopup(this.editor, prefix, keepPopupPosition);
1349
+ return;
1350
+ }
1351
+ var _id = this.gatherCompletionsId;
1352
+ this.gatherCompletions(this.editor, (function(err, results) {
1353
+ var detachIfFinished = (function() {
1354
+ if (!results.finished)
1355
+ return;
1356
+ return this.detach();
1357
+ }).bind(this);
1358
+ var prefix2 = results.prefix;
1359
+ var matches = results && results.matches;
1360
+ if (!matches || !matches.length)
1361
+ return detachIfFinished();
1362
+ if (prefix2.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId)
1363
+ return;
1364
+ this.completions = new FilteredList(matches);
1365
+ if (this.exactMatch)
1366
+ this.completions.exactMatch = true;
1367
+ this.completions.setFilter(prefix2);
1368
+ var filtered = this.completions.filtered;
1369
+ if (!filtered.length)
1370
+ return detachIfFinished();
1371
+ if (filtered.length == 1 && filtered[0].value == prefix2 && !filtered[0].snippet)
1372
+ return detachIfFinished();
1373
+ if (this.autoInsert && filtered.length == 1 && results.finished)
1374
+ return this.insertMatch(filtered[0]);
1375
+ this.openPopup(this.editor, prefix2, keepPopupPosition);
1376
+ }).bind(this));
1377
+ };
1378
+ this.cancelContextMenu = function() {
1379
+ this.editor.$mouseHandler.cancelContextMenu();
1380
+ };
1381
+ this.updateDocTooltip = function() {
1382
+ var popup = this.popup;
1383
+ var all = popup.data;
1384
+ var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]);
1385
+ var doc = null;
1386
+ if (!selected || !this.editor || !this.popup.isOpen)
1387
+ return this.hideDocTooltip();
1388
+ this.editor.completers.some(function(completer) {
1389
+ if (completer.getDocTooltip)
1390
+ doc = completer.getDocTooltip(selected);
1391
+ return doc;
1392
+ });
1393
+ if (!doc)
1394
+ doc = selected;
1395
+ if (typeof doc == "string")
1396
+ doc = { docText: doc };
1397
+ if (!doc || !(doc.docHTML || doc.docText))
1398
+ return this.hideDocTooltip();
1399
+ this.showDocTooltip(doc);
1400
+ };
1401
+ this.showDocTooltip = function(item) {
1402
+ if (!this.tooltipNode) {
1403
+ this.tooltipNode = dom.createElement("div");
1404
+ this.tooltipNode.className = "ace_tooltip ace_doc-tooltip";
1405
+ this.tooltipNode.style.margin = 0;
1406
+ this.tooltipNode.style.pointerEvents = "auto";
1407
+ this.tooltipNode.tabIndex = -1;
1408
+ this.tooltipNode.onblur = this.blurListener.bind(this);
1409
+ this.tooltipNode.onclick = this.onTooltipClick.bind(this);
1410
+ }
1411
+ var tooltipNode = this.tooltipNode;
1412
+ if (item.docHTML) {
1413
+ tooltipNode.innerHTML = item.docHTML;
1414
+ } else if (item.docText) {
1415
+ tooltipNode.textContent = item.docText;
1416
+ }
1417
+ if (!tooltipNode.parentNode)
1418
+ document.body.appendChild(tooltipNode);
1419
+ var popup = this.popup;
1420
+ var rect = popup.container.getBoundingClientRect();
1421
+ tooltipNode.style.top = popup.container.style.top;
1422
+ tooltipNode.style.bottom = popup.container.style.bottom;
1423
+ if (window.innerWidth - rect.right < 320) {
1424
+ tooltipNode.style.right = window.innerWidth - rect.left + "px";
1425
+ tooltipNode.style.left = "";
1426
+ } else {
1427
+ tooltipNode.style.left = rect.right + 1 + "px";
1428
+ tooltipNode.style.right = "";
1429
+ }
1430
+ tooltipNode.style.display = "block";
1431
+ };
1432
+ this.hideDocTooltip = function() {
1433
+ this.tooltipTimer.cancel();
1434
+ if (!this.tooltipNode)
1435
+ return;
1436
+ var el = this.tooltipNode;
1437
+ if (!this.editor.isFocused() && document.activeElement == el)
1438
+ this.editor.focus();
1439
+ this.tooltipNode = null;
1440
+ if (el.parentNode)
1441
+ el.parentNode.removeChild(el);
1442
+ };
1443
+ this.onTooltipClick = function(e) {
1444
+ var a = e.target;
1445
+ while (a && a != this.tooltipNode) {
1446
+ if (a.nodeName == "A" && a.href) {
1447
+ a.rel = "noreferrer";
1448
+ a.target = "_blank";
1449
+ break;
1450
+ }
1451
+ a = a.parentNode;
1452
+ }
1453
+ };
1454
+ }).call(Autocomplete.prototype);
1455
+ Autocomplete.startCommand = {
1456
+ name: "startAutocomplete",
1457
+ exec: function(editor) {
1458
+ if (!editor.completer)
1459
+ editor.completer = new Autocomplete();
1460
+ editor.completer.autoInsert = false;
1461
+ editor.completer.autoSelect = true;
1462
+ editor.completer.showPopup(editor);
1463
+ editor.completer.cancelContextMenu();
1464
+ },
1465
+ bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
1466
+ };
1467
+ var FilteredList = function(array, filterText) {
1468
+ this.all = array;
1469
+ this.filtered = array;
1470
+ this.filterText = filterText || "";
1471
+ this.exactMatch = false;
1472
+ };
1473
+ (function() {
1474
+ this.setFilter = function(str) {
1475
+ if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
1476
+ var matches = this.filtered;
1477
+ else
1478
+ var matches = this.all;
1479
+ this.filterText = str;
1480
+ matches = this.filterCompletions(matches, this.filterText);
1481
+ matches = matches.sort(function(a, b) {
1482
+ return b.exactMatch - a.exactMatch || b.score - a.score;
1483
+ });
1484
+ var prev = null;
1485
+ matches = matches.filter(function(item) {
1486
+ var caption = item.snippet || item.caption || item.value;
1487
+ if (caption === prev)
1488
+ return false;
1489
+ prev = caption;
1490
+ return true;
1491
+ });
1492
+ this.filtered = matches;
1493
+ };
1494
+ this.filterCompletions = function(items, needle) {
1495
+ var results = [];
1496
+ var upper = needle.toUpperCase();
1497
+ var lower = needle.toLowerCase();
1498
+ loop:
1499
+ for (var i = 0, item; item = items[i]; i++) {
1500
+ var caption = item.value || item.caption || item.snippet;
1501
+ if (!caption)
1502
+ continue;
1503
+ var lastIndex = -1;
1504
+ var matchMask = 0;
1505
+ var penalty = 0;
1506
+ var index, distance;
1507
+ if (this.exactMatch) {
1508
+ if (needle !== caption.substr(0, needle.length))
1509
+ continue loop;
1510
+ } else {
1511
+ for (var j = 0; j < needle.length; j++) {
1512
+ var i1 = caption.indexOf(lower[j], lastIndex + 1);
1513
+ var i2 = caption.indexOf(upper[j], lastIndex + 1);
1514
+ index = i1 >= 0 ? i2 < 0 || i1 < i2 ? i1 : i2 : i2;
1515
+ if (index < 0)
1516
+ continue loop;
1517
+ distance = index - lastIndex - 1;
1518
+ if (distance > 0) {
1519
+ if (lastIndex === -1)
1520
+ penalty += 10;
1521
+ penalty += distance;
1522
+ }
1523
+ matchMask = matchMask | 1 << index;
1524
+ lastIndex = index;
1525
+ }
1526
+ }
1527
+ item.matchMask = matchMask;
1528
+ item.exactMatch = penalty ? 0 : 1;
1529
+ item.score = (item.score || 0) - penalty;
1530
+ results.push(item);
1531
+ }
1532
+ return results;
1533
+ };
1534
+ }).call(FilteredList.prototype);
1535
+ exports.Autocomplete = Autocomplete;
1536
+ exports.FilteredList = FilteredList;
1537
+ });
1538
+ ace.define("ace/autocomplete/text_completer", ["require", "exports", "module", "ace/range"], function(acequire, exports, module) {
1539
+ var Range = acequire("../range").Range;
1540
+ var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
1541
+ function getWordIndex(doc, pos) {
1542
+ var textBefore = doc.getTextRange(Range.fromPoints({ row: 0, column: 0 }, pos));
1543
+ return textBefore.split(splitRegex).length - 1;
1544
+ }
1545
+ function wordDistance(doc, pos) {
1546
+ var prefixPos = getWordIndex(doc, pos);
1547
+ var words = doc.getValue().split(splitRegex);
1548
+ var wordScores = /* @__PURE__ */ Object.create(null);
1549
+ var currentWord = words[prefixPos];
1550
+ words.forEach(function(word, idx) {
1551
+ if (!word || word === currentWord)
1552
+ return;
1553
+ var distance = Math.abs(prefixPos - idx);
1554
+ var score = words.length - distance;
1555
+ if (wordScores[word]) {
1556
+ wordScores[word] = Math.max(score, wordScores[word]);
1557
+ } else {
1558
+ wordScores[word] = score;
1559
+ }
1560
+ });
1561
+ return wordScores;
1562
+ }
1563
+ exports.getCompletions = function(editor, session, pos, prefix, callback) {
1564
+ var wordScore = wordDistance(session, pos);
1565
+ var wordList = Object.keys(wordScore);
1566
+ callback(null, wordList.map(function(word) {
1567
+ return {
1568
+ caption: word,
1569
+ value: word,
1570
+ score: wordScore[word],
1571
+ meta: "local"
1572
+ };
1573
+ }));
1574
+ };
1575
+ });
1576
+ ace.define("ace/ext/language_tools", ["require", "exports", "module", "ace/snippets", "ace/autocomplete", "ace/config", "ace/lib/lang", "ace/autocomplete/util", "ace/autocomplete/text_completer", "ace/editor", "ace/config"], function(acequire, exports, module) {
1577
+ var snippetManager = acequire("../snippets").snippetManager;
1578
+ var Autocomplete = acequire("../autocomplete").Autocomplete;
1579
+ var config = acequire("../config");
1580
+ var lang = acequire("../lib/lang");
1581
+ var util = acequire("../autocomplete/util");
1582
+ var textCompleter = acequire("../autocomplete/text_completer");
1583
+ var keyWordCompleter = {
1584
+ getCompletions: function(editor, session, pos, prefix, callback) {
1585
+ if (session.$mode.completer) {
1586
+ return session.$mode.completer.getCompletions(editor, session, pos, prefix, callback);
1587
+ }
1588
+ var state = editor.session.getState(pos.row);
1589
+ var completions = session.$mode.getCompletions(state, session, pos, prefix);
1590
+ callback(null, completions);
1591
+ }
1592
+ };
1593
+ var snippetCompleter = {
1594
+ getCompletions: function(editor, session, pos, prefix, callback) {
1595
+ var snippetMap = snippetManager.snippetMap;
1596
+ var completions = [];
1597
+ snippetManager.getActiveScopes(editor).forEach(function(scope) {
1598
+ var snippets = snippetMap[scope] || [];
1599
+ for (var i = snippets.length; i--; ) {
1600
+ var s = snippets[i];
1601
+ var caption = s.name || s.tabTrigger;
1602
+ if (!caption)
1603
+ continue;
1604
+ completions.push({
1605
+ caption,
1606
+ snippet: s.content,
1607
+ meta: s.tabTrigger && !s.name ? s.tabTrigger + "⇥ " : "snippet",
1608
+ type: "snippet"
1609
+ });
1610
+ }
1611
+ }, this);
1612
+ callback(null, completions);
1613
+ },
1614
+ getDocTooltip: function(item) {
1615
+ if (item.type == "snippet" && !item.docHTML) {
1616
+ item.docHTML = [
1617
+ "<b>",
1618
+ lang.escapeHTML(item.caption),
1619
+ "</b>",
1620
+ "<hr></hr>",
1621
+ lang.escapeHTML(item.snippet)
1622
+ ].join("");
1623
+ }
1624
+ }
1625
+ };
1626
+ var completers = [snippetCompleter, textCompleter, keyWordCompleter];
1627
+ exports.setCompleters = function(val) {
1628
+ completers.length = 0;
1629
+ if (val)
1630
+ completers.push.apply(completers, val);
1631
+ };
1632
+ exports.addCompleter = function(completer) {
1633
+ completers.push(completer);
1634
+ };
1635
+ exports.textCompleter = textCompleter;
1636
+ exports.keyWordCompleter = keyWordCompleter;
1637
+ exports.snippetCompleter = snippetCompleter;
1638
+ var expandSnippet = {
1639
+ name: "expandSnippet",
1640
+ exec: function(editor) {
1641
+ return snippetManager.expandWithTab(editor);
1642
+ },
1643
+ bindKey: "Tab"
1644
+ };
1645
+ var onChangeMode = function(e, editor) {
1646
+ loadSnippetsForMode(editor.session.$mode);
1647
+ };
1648
+ var loadSnippetsForMode = function(mode) {
1649
+ var id = mode.$id;
1650
+ if (!snippetManager.files)
1651
+ snippetManager.files = {};
1652
+ loadSnippetFile(id);
1653
+ if (mode.modes)
1654
+ mode.modes.forEach(loadSnippetsForMode);
1655
+ };
1656
+ var loadSnippetFile = function(id) {
1657
+ if (!id || snippetManager.files[id])
1658
+ return;
1659
+ var snippetFilePath = id.replace("mode", "snippets");
1660
+ snippetManager.files[id] = {};
1661
+ config.loadModule(snippetFilePath, function(m) {
1662
+ if (m) {
1663
+ snippetManager.files[id] = m;
1664
+ if (!m.snippets && m.snippetText)
1665
+ m.snippets = snippetManager.parseSnippetFile(m.snippetText);
1666
+ snippetManager.register(m.snippets || [], m.scope);
1667
+ if (m.includeScopes) {
1668
+ snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
1669
+ m.includeScopes.forEach(function(x) {
1670
+ loadSnippetFile("ace/mode/" + x);
1671
+ });
1672
+ }
1673
+ }
1674
+ });
1675
+ };
1676
+ var doLiveAutocomplete = function(e) {
1677
+ var editor = e.editor;
1678
+ var hasCompleter = editor.completer && editor.completer.activated;
1679
+ if (e.command.name === "backspace") {
1680
+ if (hasCompleter && !util.getCompletionPrefix(editor))
1681
+ editor.completer.detach();
1682
+ } else if (e.command.name === "insertstring") {
1683
+ var prefix = util.getCompletionPrefix(editor);
1684
+ if (prefix && !hasCompleter) {
1685
+ if (!editor.completer) {
1686
+ editor.completer = new Autocomplete();
1687
+ }
1688
+ editor.completer.autoInsert = false;
1689
+ editor.completer.showPopup(editor);
1690
+ }
1691
+ }
1692
+ };
1693
+ var Editor = acequire("../editor").Editor;
1694
+ acequire("../config").defineOptions(Editor.prototype, "editor", {
1695
+ enableBasicAutocompletion: {
1696
+ set: function(val) {
1697
+ if (val) {
1698
+ if (!this.completers)
1699
+ this.completers = Array.isArray(val) ? val : completers;
1700
+ this.commands.addCommand(Autocomplete.startCommand);
1701
+ } else {
1702
+ this.commands.removeCommand(Autocomplete.startCommand);
1703
+ }
1704
+ },
1705
+ value: false
1706
+ },
1707
+ enableLiveAutocompletion: {
1708
+ set: function(val) {
1709
+ if (val) {
1710
+ if (!this.completers)
1711
+ this.completers = Array.isArray(val) ? val : completers;
1712
+ this.commands.on("afterExec", doLiveAutocomplete);
1713
+ } else {
1714
+ this.commands.removeListener("afterExec", doLiveAutocomplete);
1715
+ }
1716
+ },
1717
+ value: false
1718
+ },
1719
+ enableSnippets: {
1720
+ set: function(val) {
1721
+ if (val) {
1722
+ this.commands.addCommand(expandSnippet);
1723
+ this.on("changeMode", onChangeMode);
1724
+ onChangeMode(null, this);
1725
+ } else {
1726
+ this.commands.removeCommand(expandSnippet);
1727
+ this.off("changeMode", onChangeMode);
1728
+ }
1729
+ },
1730
+ value: false
1731
+ }
1732
+ });
1733
+ });
1734
+ (function() {
1735
+ ace.acequire(["ace/ext/language_tools"], function() {
1736
+ });
1737
+ })();