Debian Codegraph @

extensions/CodeEditor/modules/lib/ace/ext-inline_autocomplete.js

raw symbols SCIP
1 ace.define("ace/snippets",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/range_list","ace/keyboard/hash_handler","ace/tokenizer","ace/clipboard","ace/editor"], function(require, exports, module){"use strict";
2 var dom = require("./lib/dom");
3 var oop = require("./lib/oop");
4 var EventEmitter = require("./lib/event_emitter").EventEmitter;
5 var lang = require("./lib/lang");
6 var Range = require("./range").Range;
7 var RangeList = require("./range_list").RangeList;
8 var HashHandler = require("./keyboard/hash_handler").HashHandler;
9 var Tokenizer = require("./tokenizer").Tokenizer;
10 var clipboard = require("./clipboard");
11 var VARIABLES = {
12 CURRENT_WORD: function (editor) {
13 return editor.session.getTextRange(editor.session.getWordRange());
14 },
15 SELECTION: function (editor, name, indentation) {
16 var text = editor.session.getTextRange();
17 if (indentation)
18 return text.replace(/\n\r?([ \t]*\S)/g, "\n" + indentation + "$1");
19 return text;
20 },
21 CURRENT_LINE: function (editor) {
22 return editor.session.getLine(editor.getCursorPosition().row);
23 },
24 PREV_LINE: function (editor) {
25 return editor.session.getLine(editor.getCursorPosition().row - 1);
26 },
27 LINE_INDEX: function (editor) {
28 return editor.getCursorPosition().row;
29 },
30 LINE_NUMBER: function (editor) {
31 return editor.getCursorPosition().row + 1;
32 },
33 SOFT_TABS: function (editor) {
34 return editor.session.getUseSoftTabs() ? "YES" : "NO";
35 },
36 TAB_SIZE: function (editor) {
37 return editor.session.getTabSize();
38 },
39 CLIPBOARD: function (editor) {
40 return clipboard.getText && clipboard.getText();
41 },
42 FILENAME: function (editor) {
43 return /[^/\\]*$/.exec(this.FILEPATH(editor))[0];
44 },
45 FILENAME_BASE: function (editor) {
46 return /[^/\\]*$/.exec(this.FILEPATH(editor))[0].replace(/\.[^.]*$/, "");
47 },
48 DIRECTORY: function (editor) {
49 return this.FILEPATH(editor).replace(/[^/\\]*$/, "");
50 },
51 FILEPATH: function (editor) { return "/not implemented.txt"; },
52 WORKSPACE_NAME: function () { return "Unknown"; },
53 FULLNAME: function () { return "Unknown"; },
54 BLOCK_COMMENT_START: function (editor) {
55 var mode = editor.session.$mode || {};
56 return mode.blockComment && mode.blockComment.start || "";
57 },
58 BLOCK_COMMENT_END: function (editor) {
59 var mode = editor.session.$mode || {};
60 return mode.blockComment && mode.blockComment.end || "";
61 },
62 LINE_COMMENT: function (editor) {
63 var mode = editor.session.$mode || {};
64 return mode.lineCommentStart || "";
65 },
66 CURRENT_YEAR: date.bind(null, { year: "numeric" }),
67 CURRENT_YEAR_SHORT: date.bind(null, { year: "2-digit" }),
68 CURRENT_MONTH: date.bind(null, { month: "numeric" }),
69 CURRENT_MONTH_NAME: date.bind(null, { month: "long" }),
70 CURRENT_MONTH_NAME_SHORT: date.bind(null, { month: "short" }),
71 CURRENT_DATE: date.bind(null, { day: "2-digit" }),
72 CURRENT_DAY_NAME: date.bind(null, { weekday: "long" }),
73 CURRENT_DAY_NAME_SHORT: date.bind(null, { weekday: "short" }),
74 CURRENT_HOUR: date.bind(null, { hour: "2-digit", hour12: false }),
75 CURRENT_MINUTE: date.bind(null, { minute: "2-digit" }),
76 CURRENT_SECOND: date.bind(null, { second: "2-digit" })
77 };
78 VARIABLES.SELECTED_TEXT = VARIABLES.SELECTION;
79 function date(dateFormat) {
80 var str = new Date().toLocaleString("en-us", dateFormat);
81 return str.length == 1 ? "0" + str : str;
82 }
83 var SnippetManager = /** @class */ (function () {
84 function SnippetManager() {
85 this.snippetMap = {};
86 this.snippetNameMap = {};
87 this.variables = VARIABLES;
88 }
89 SnippetManager.prototype.getTokenizer = function () {
90 return SnippetManager["$tokenizer"] || this.createTokenizer();
91 };
92 SnippetManager.prototype.createTokenizer = function () {
93 function TabstopToken(str) {
94 str = str.substr(1);
95 if (/^\d+$/.test(str))
96 return [{ tabstopId: parseInt(str, 10) }];
97 return [{ text: str }];
98 }
99 function escape(ch) {
100 return "(?:[^\\\\" + ch + "]|\\\\.)";
101 }
102 var formatMatcher = {
103 regex: "/(" + escape("/") + "+)/",
104 onMatch: function (val, state, stack) {
105 var ts = stack[0];
106 ts.fmtString = true;
107 ts.guard = val.slice(1, -1);
108 ts.flag = "";
109 return "";
110 },
111 next: "formatString"
112 };
113 SnippetManager["$tokenizer"] = new Tokenizer({
114 start: [
115 { regex: /\\./, onMatch: function (val, state, stack) {
116 var ch = val[1];
117 if (ch == "}" && stack.length) {
118 val = ch;
119 }
120 else if ("`$\\".indexOf(ch) != -1) {
121 val = ch;
122 }
123 return [val];
124 } },
125 { regex: /}/, onMatch: function (val, state, stack) {
126 return [stack.length ? stack.shift() : val];
127 } },
128 { regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken },
129 { regex: /\$\{[\dA-Z_a-z]+/, onMatch: function (str, state, stack) {
130 var t = TabstopToken(str.substr(1));
131 stack.unshift(t[0]);
132 return t;
133 }, next: "snippetVar" },
134 { regex: /\n/, token: "newline", merge: false }
135 ],
136 snippetVar: [
137 { regex: "\\|" + escape("\\|") + "*\\|", onMatch: function (val, state, stack) {
138 var choices = val.slice(1, -1).replace(/\\[,|\\]|,/g, function (operator) {
139 return operator.length == 2 ? operator[1] : "\x00";
140 }).split("\x00").map(function (value) {
141 return { value: value };
142 });
143 stack[0].choices = choices;
144 return [choices[0]];
145 }, next: "start" },
146 formatMatcher,
147 { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start" }
148 ],
149 formatString: [
150 { regex: /:/, onMatch: function (val, state, stack) {
151 if (stack.length && stack[0].expectElse) {
152 stack[0].expectElse = false;
153 stack[0].ifEnd = { elseEnd: stack[0] };
154 return [stack[0].ifEnd];
155 }
156 return ":";
157 } },
158 { regex: /\\./, onMatch: function (val, state, stack) {
159 var ch = val[1];
160 if (ch == "}" && stack.length)
161 val = ch;
162 else if ("`$\\".indexOf(ch) != -1)
163 val = ch;
164 else if (ch == "n")
165 val = "\n";
166 else if (ch == "t")
167 val = "\t";
168 else if ("ulULE".indexOf(ch) != -1)
169 val = { changeCase: ch, local: ch > "a" };
170 return [val];
171 } },
172 { regex: "/\\w*}", onMatch: function (val, state, stack) {
173 var next = stack.shift();
174 if (next)
175 next.flag = val.slice(1, -1);
176 this.next = next && next.tabstopId ? "start" : "";
177 return [next || val];
178 }, next: "start" },
179 { regex: /\$(?:\d+|\w+)/, onMatch: function (val, state, stack) {
180 return [{ text: val.slice(1) }];
181 } },
182 { regex: /\${\w+/, onMatch: function (val, state, stack) {
183 var token = { text: val.slice(2) };
184 stack.unshift(token);
185 return [token];
186 }, next: "formatStringVar" },
187 { regex: /\n/, token: "newline", merge: false },
188 { regex: /}/, onMatch: function (val, state, stack) {
189 var next = stack.shift();
190 this.next = next && next.tabstopId ? "start" : "";
191 return [next || val];
192 }, next: "start" }
193 ],
194 formatStringVar: [
195 { regex: /:\/\w+}/, onMatch: function (val, state, stack) {
196 var ts = stack[0];
197 ts.formatFunction = val.slice(2, -1);
198 return [stack.shift()];
199 }, next: "formatString" },
200 formatMatcher,
201 { regex: /:[\?\-+]?/, onMatch: function (val, state, stack) {
202 if (val[1] == "+")
203 stack[0].ifEnd = stack[0];
204 if (val[1] == "?")
205 stack[0].expectElse = true;
206 }, next: "formatString" },
207 { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "formatString" }
208 ]
209 });
210 return SnippetManager["$tokenizer"];
211 };
212 SnippetManager.prototype.tokenizeTmSnippet = function (str, startState) {
213 return this.getTokenizer().getLineTokens(str, startState).tokens.map(function (x) {
214 return x.value || x;
215 });
216 };
217 SnippetManager.prototype.getVariableValue = function (editor, name, indentation) {
218 if (/^\d+$/.test(name))
219 return (this.variables.__ || {})[name] || "";
220 if (/^[A-Z]\d+$/.test(name))
221 return (this.variables[name[0] + "__"] || {})[name.substr(1)] || "";
222 name = name.replace(/^TM_/, "");
223 if (!this.variables.hasOwnProperty(name))
224 return "";
225 var value = this.variables[name];
226 if (typeof value == "function")
227 value = this.variables[name](editor, name, indentation);
228 return value == null ? "" : value;
229 };
230 SnippetManager.prototype.tmStrFormat = function (str, ch, editor) {
231 if (!ch.fmt)
232 return str;
233 var flag = ch.flag || "";
234 var re = ch.guard;
235 re = new RegExp(re, flag.replace(/[^gim]/g, ""));
236 var fmtTokens = typeof ch.fmt == "string" ? this.tokenizeTmSnippet(ch.fmt, "formatString") : ch.fmt;
237 var _self = this;
238 var formatted = str.replace(re, function () {
239 var oldArgs = _self.variables.__;
240 _self.variables.__ = [].slice.call(arguments);
241 var fmtParts = _self.resolveVariables(fmtTokens, editor);
242 var gChangeCase = "E";
243 for (var i = 0; i < fmtParts.length; i++) {
244 var ch = fmtParts[i];
245 if (typeof ch == "object") {
246 fmtParts[i] = "";
247 if (ch.changeCase && ch.local) {
248 var next = fmtParts[i + 1];
249 if (next && typeof next == "string") {
250 if (ch.changeCase == "u")
251 fmtParts[i] = next[0].toUpperCase();
252 else
253 fmtParts[i] = next[0].toLowerCase();
254 fmtParts[i + 1] = next.substr(1);
255 }
256 }
257 else if (ch.changeCase) {
258 gChangeCase = ch.changeCase;
259 }
260 }
261 else if (gChangeCase == "U") {
262 fmtParts[i] = ch.toUpperCase();
263 }
264 else if (gChangeCase == "L") {
265 fmtParts[i] = ch.toLowerCase();
266 }
267 }
268 _self.variables.__ = oldArgs;
269 return fmtParts.join("");
270 });
271 return formatted;
272 };
273 SnippetManager.prototype.tmFormatFunction = function (str, ch, editor) {
274 if (ch.formatFunction == "upcase")
275 return str.toUpperCase();
276 if (ch.formatFunction == "downcase")
277 return str.toLowerCase();
278 return str;
279 };
280 SnippetManager.prototype.resolveVariables = function (snippet, editor) {
281 var result = [];
282 var indentation = "";
283 var afterNewLine = true;
284 for (var i = 0; i < snippet.length; i++) {
285 var ch = snippet[i];
286 if (typeof ch == "string") {
287 result.push(ch);
288 if (ch == "\n") {
289 afterNewLine = true;
290 indentation = "";
291 }
292 else if (afterNewLine) {
293 indentation = /^\t*/.exec(ch)[0];
294 afterNewLine = /\S/.test(ch);
295 }
296 continue;
297 }
298 if (!ch)
299 continue;
300 afterNewLine = false;
301 if (ch.fmtString) {
302 var j = snippet.indexOf(ch, i + 1);
303 if (j == -1)
304 j = snippet.length;
305 ch.fmt = snippet.slice(i + 1, j);
306 i = j;
307 }
308 if (ch.text) {
309 var value = this.getVariableValue(editor, ch.text, indentation) + "";
310 if (ch.fmtString)
311 value = this.tmStrFormat(value, ch, editor);
312 if (ch.formatFunction)
313 value = this.tmFormatFunction(value, ch, editor);
314 if (value && !ch.ifEnd) {
315 result.push(value);
316 gotoNext(ch);
317 }
318 else if (!value && ch.ifEnd) {
319 gotoNext(ch.ifEnd);
320 }
321 }
322 else if (ch.elseEnd) {
323 gotoNext(ch.elseEnd);
324 }
325 else if (ch.tabstopId != null) {
326 result.push(ch);
327 }
328 else if (ch.changeCase != null) {
329 result.push(ch);
330 }
331 }
332 function gotoNext(ch) {
333 var i1 = snippet.indexOf(ch, i + 1);
334 if (i1 != -1)
335 i = i1;
336 }
337 return result;
338 };
339 SnippetManager.prototype.getDisplayTextForSnippet = function (editor, snippetText) {
340 var processedSnippet = processSnippetText.call(this, editor, snippetText);
341 return processedSnippet.text;
342 };
343 SnippetManager.prototype.insertSnippetForSelection = function (editor, snippetText, options) {
344 if (options === void 0) { options = {}; }
345 var processedSnippet = processSnippetText.call(this, editor, snippetText, options);
346 var range = editor.getSelectionRange();
347 var end = editor.session.replace(range, processedSnippet.text);
348 var tabstopManager = new TabstopManager(editor);
349 var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
350 tabstopManager.addTabstops(processedSnippet.tabstops, range.start, end, selectionId);
351 };
352 SnippetManager.prototype.insertSnippet = function (editor, snippetText, options) {
353 if (options === void 0) { options = {}; }
354 var self = this;
355 if (editor.inVirtualSelectionMode)
356 return self.insertSnippetForSelection(editor, snippetText, options);
357 editor.forEachSelection(function () {
358 self.insertSnippetForSelection(editor, snippetText, options);
359 }, null, { keepOrder: true });
360 if (editor.tabstopManager)
361 editor.tabstopManager.tabNext();
362 };
363 SnippetManager.prototype.$getScope = function (editor) {
364 var scope = editor.session.$mode.$id || "";
365 scope = scope.split("/").pop();
366 if (scope === "html" || scope === "php") {
367 if (scope === "php" && !editor.session.$mode.inlinePhp)
368 scope = "html";
369 var c = editor.getCursorPosition();
370 var state = editor.session.getState(c.row);
371 if (typeof state === "object") {
372 state = state[0];
373 }
374 if (state.substring) {
375 if (state.substring(0, 3) == "js-")
376 scope = "javascript";
377 else if (state.substring(0, 4) == "css-")
378 scope = "css";
379 else if (state.substring(0, 4) == "php-")
380 scope = "php";
381 }
382 }
383 return scope;
384 };
385 SnippetManager.prototype.getActiveScopes = function (editor) {
386 var scope = this.$getScope(editor);
387 var scopes = [scope];
388 var snippetMap = this.snippetMap;
389 if (snippetMap[scope] && snippetMap[scope].includeScopes) {
390 scopes.push.apply(scopes, snippetMap[scope].includeScopes);
391 }
392 scopes.push("_");
393 return scopes;
394 };
395 SnippetManager.prototype.expandWithTab = function (editor, options) {
396 var self = this;
397 var result = editor.forEachSelection(function () {
398 return self.expandSnippetForSelection(editor, options);
399 }, null, { keepOrder: true });
400 if (result && editor.tabstopManager)
401 editor.tabstopManager.tabNext();
402 return result;
403 };
404 SnippetManager.prototype.expandSnippetForSelection = function (editor, options) {
405 var cursor = editor.getCursorPosition();
406 var line = editor.session.getLine(cursor.row);
407 var before = line.substring(0, cursor.column);
408 var after = line.substr(cursor.column);
409 var snippetMap = this.snippetMap;
410 var snippet;
411 this.getActiveScopes(editor).some(function (scope) {
412 var snippets = snippetMap[scope];
413 if (snippets)
414 snippet = this.findMatchingSnippet(snippets, before, after);
415 return !!snippet;
416 }, this);
417 if (!snippet)
418 return false;
419 if (options && options.dryRun)
420 return true;
421 editor.session.doc.removeInLine(cursor.row, cursor.column - snippet.replaceBefore.length, cursor.column + snippet.replaceAfter.length);
422 this.variables.M__ = snippet.matchBefore;
423 this.variables.T__ = snippet.matchAfter;
424 this.insertSnippetForSelection(editor, snippet.content);
425 this.variables.M__ = this.variables.T__ = null;
426 return true;
427 };
428 SnippetManager.prototype.findMatchingSnippet = function (snippetList, before, after) {
429 for (var i = snippetList.length; i--;) {
430 var s = snippetList[i];
431 if (s.startRe && !s.startRe.test(before))
432 continue;
433 if (s.endRe && !s.endRe.test(after))
434 continue;
435 if (!s.startRe && !s.endRe)
436 continue;
437 s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
438 s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
439 s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
440 s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
441 return s;
442 }
443 };
444 SnippetManager.prototype.register = function (snippets, scope) {
445 var snippetMap = this.snippetMap;
446 var snippetNameMap = this.snippetNameMap;
447 var self = this;
448 if (!snippets)
449 snippets = [];
450 function wrapRegexp(src) {
451 if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
452 src = "(?:" + src + ")";
453 return src || "";
454 }
455 function guardedRegexp(re, guard, opening) {
456 re = wrapRegexp(re);
457 guard = wrapRegexp(guard);
458 if (opening) {
459 re = guard + re;
460 if (re && re[re.length - 1] != "$")
461 re = re + "$";
462 }
463 else {
464 re = re + guard;
465 if (re && re[0] != "^")
466 re = "^" + re;
467 }
468 return new RegExp(re);
469 }
470 function addSnippet(s) {
471 if (!s.scope)
472 s.scope = scope || "_";
473 scope = s.scope;
474 if (!snippetMap[scope]) {
475 snippetMap[scope] = [];
476 snippetNameMap[scope] = {};
477 }
478 var map = snippetNameMap[scope];
479 if (s.name) {
480 var old = map[s.name];
481 if (old)
482 self.unregister(old);
483 map[s.name] = s;
484 }
485 snippetMap[scope].push(s);
486 if (s.prefix)
487 s.tabTrigger = s.prefix;
488 if (!s.content && s.body)
489 s.content = Array.isArray(s.body) ? s.body.join("\n") : s.body;
490 if (s.tabTrigger && !s.trigger) {
491 if (!s.guard && /^\w/.test(s.tabTrigger))
492 s.guard = "\\b";
493 s.trigger = lang.escapeRegExp(s.tabTrigger);
494 }
495 if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard)
496 return;
497 s.startRe = guardedRegexp(s.trigger, s.guard, true);
498 s.triggerRe = new RegExp(s.trigger);
499 s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
500 s.endTriggerRe = new RegExp(s.endTrigger);
501 }
502 if (Array.isArray(snippets)) {
503 snippets.forEach(addSnippet);
504 }
505 else {
506 Object.keys(snippets).forEach(function (key) {
507 addSnippet(snippets[key]);
508 });
509 }
510 this._signal("registerSnippets", { scope: scope });
511 };
512 SnippetManager.prototype.unregister = function (snippets, scope) {
513 var snippetMap = this.snippetMap;
514 var snippetNameMap = this.snippetNameMap;
515 function removeSnippet(s) {
516 var nameMap = snippetNameMap[s.scope || scope];
517 if (nameMap && nameMap[s.name]) {
518 delete nameMap[s.name];
519 var map = snippetMap[s.scope || scope];
520 var i = map && map.indexOf(s);
521 if (i >= 0)
522 map.splice(i, 1);
523 }
524 }
525 if (snippets.content)
526 removeSnippet(snippets);
527 else if (Array.isArray(snippets))
528 snippets.forEach(removeSnippet);
529 };
530 SnippetManager.prototype.parseSnippetFile = function (str) {
531 str = str.replace(/\r/g, "");
532 var list = [], /**@type{Snippet}*/ snippet = {};
533 var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
534 var m;
535 while (m = re.exec(str)) {
536 if (m[1]) {
537 try {
538 snippet = JSON.parse(m[1]);
539 list.push(snippet);
540 }
541 catch (e) { }
542 }
543 if (m[4]) {
544 snippet.content = m[4].replace(/^\t/gm, "");
545 list.push(snippet);
546 snippet = {};
547 }
548 else {
549 var key = m[2], val = m[3];
550 if (key == "regex") {
551 var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
552 snippet.guard = guardRe.exec(val)[1];
553 snippet.trigger = guardRe.exec(val)[1];
554 snippet.endTrigger = guardRe.exec(val)[1];
555 snippet.endGuard = guardRe.exec(val)[1];
556 }
557 else if (key == "snippet") {
558 snippet.tabTrigger = val.match(/^\S*/)[0];
559 if (!snippet.name)
560 snippet.name = val;
561 }
562 else if (key) {
563 snippet[key] = val;
564 }
565 }
566 }
567 return list;
568 };
569 SnippetManager.prototype.getSnippetByName = function (name, editor) {
570 var snippetMap = this.snippetNameMap;
571 var snippet;
572 this.getActiveScopes(editor).some(function (scope) {
573 var snippets = snippetMap[scope];
574 if (snippets)
575 snippet = snippets[name];
576 return !!snippet;
577 }, this);
578 return snippet;
579 };
580 return SnippetManager;
581 }());
582 oop.implement(SnippetManager.prototype, EventEmitter);
583 var processSnippetText = function (editor, snippetText, options) {
584 if (options === void 0) { options = {}; }
585 var cursor = editor.getCursorPosition();
586 var line = editor.session.getLine(cursor.row);
587 var tabString = editor.session.getTabString();
588 var indentString = line.match(/^\s*/)[0];
589 if (cursor.column < indentString.length)
590 indentString = indentString.slice(0, cursor.column);
591 snippetText = snippetText.replace(/\r/g, "");
592 var tokens = this.tokenizeTmSnippet(snippetText);
593 tokens = this.resolveVariables(tokens, editor);
594 tokens = tokens.map(function (x) {
595 if (x == "\n" && !options.excludeExtraIndent)
596 return x + indentString;
597 if (typeof x == "string")
598 return x.replace(/\t/g, tabString);
599 return x;
600 });
601 var tabstops = [];
602 tokens.forEach(function (p, i) {
603 if (typeof p != "object")
604 return;
605 var id = p.tabstopId;
606 var ts = tabstops[id];
607 if (!ts) {
608 ts = tabstops[id] = [];
609 ts.index = id;
610 ts.value = "";
611 ts.parents = {};
612 }
613 if (ts.indexOf(p) !== -1)
614 return;
615 if (p.choices && !ts.choices)
616 ts.choices = p.choices;
617 ts.push(p);
618 var i1 = tokens.indexOf(p, i + 1);
619 if (i1 === -1)
620 return;
621 var value = tokens.slice(i + 1, i1);
622 var isNested = value.some(function (t) { return typeof t === "object"; });
623 if (isNested && !ts.value) {
624 ts.value = value;
625 }
626 else if (value.length && (!ts.value || typeof ts.value !== "string")) {
627 ts.value = value.join("");
628 }
629 });
630 tabstops.forEach(function (ts) { ts.length = 0; });
631 var expanding = {};
632 function copyValue(val) {
633 var copy = [];
634 for (var i = 0; i < val.length; i++) {
635 var p = val[i];
636 if (typeof p == "object") {
637 if (expanding[p.tabstopId])
638 continue;
639 var j = val.lastIndexOf(p, i - 1);
640 p = copy[j] || { tabstopId: p.tabstopId };
641 }
642 copy[i] = p;
643 }
644 return copy;
645 }
646 for (var i = 0; i < tokens.length; i++) {
647 var p = tokens[i];
648 if (typeof p != "object")
649 continue;
650 var id = p.tabstopId;
651 var ts = tabstops[id];
652 var i1 = tokens.indexOf(p, i + 1);
653 if (expanding[id]) {
654 if (expanding[id] === p) {
655 delete expanding[id];
656 Object.keys(expanding).forEach(function (parentId) {
657 ts.parents[parentId] = true;
658 });
659 }
660 continue;
661 }
662 expanding[id] = p;
663 var value = ts.value;
664 if (typeof value !== "string")
665 value = copyValue(value);
666 else if (p.fmt)
667 value = this.tmStrFormat(value, p, editor);
668 tokens.splice.apply(tokens, [i + 1, Math.max(0, i1 - i)].concat(value, p));
669 if (ts.indexOf(p) === -1)
670 ts.push(p);
671 }
672 var row = 0, column = 0;
673 var text = "";
674 tokens.forEach(function (t) {
675 if (typeof t === "string") {
676 var lines = t.split("\n");
677 if (lines.length > 1) {
678 column = lines[lines.length - 1].length;
679 row += lines.length - 1;
680 }
681 else
682 column += t.length;
683 text += t;
684 }
685 else if (t) {
686 if (!t.start)
687 t.start = { row: row, column: column };
688 else
689 t.end = { row: row, column: column };
690 }
691 });
692 return {
693 text: text,
694 tabstops: tabstops,
695 tokens: tokens
696 };
697 };
698 var TabstopManager = /** @class */ (function () {
699 function TabstopManager(editor) {
700 this.index = 0;
701 this.ranges = [];
702 this.tabstops = [];
703 if (editor.tabstopManager)
704 return editor.tabstopManager;
705 editor.tabstopManager = this;
706 this.$onChange = this.onChange.bind(this);
707 this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
708 this.$onChangeSession = this.onChangeSession.bind(this);
709 this.$onAfterExec = this.onAfterExec.bind(this);
710 this.attach(editor);
711 }
712 TabstopManager.prototype.attach = function (editor) {
713 this.$openTabstops = null;
714 this.selectedTabstop = null;
715 this.editor = editor;
716 this.session = editor.session;
717 this.editor.on("change", this.$onChange);
718 this.editor.on("changeSelection", this.$onChangeSelection);
719 this.editor.on("changeSession", this.$onChangeSession);
720 this.editor.commands.on("afterExec", this.$onAfterExec);
721 this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
722 };
723 TabstopManager.prototype.detach = function () {
724 this.tabstops.forEach(this.removeTabstopMarkers, this);
725 this.ranges.length = 0;
726 this.tabstops.length = 0;
727 this.selectedTabstop = null;
728 this.editor.off("change", this.$onChange);
729 this.editor.off("changeSelection", this.$onChangeSelection);
730 this.editor.off("changeSession", this.$onChangeSession);
731 this.editor.commands.off("afterExec", this.$onAfterExec);
732 this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
733 this.editor.tabstopManager = null;
734 this.session = null;
735 this.editor = null;
736 };
737 TabstopManager.prototype.onChange = function (delta) {
738 var isRemove = delta.action[0] == "r";
739 var selectedTabstop = this.selectedTabstop || {};
740 var parents = selectedTabstop.parents || {};
741 var tabstops = this.tabstops.slice();
742 for (var i = 0; i < tabstops.length; i++) {
743 var ts = tabstops[i];
744 var active = ts == selectedTabstop || parents[ts.index];
745 ts.rangeList.$bias = active ? 0 : 1;
746 if (delta.action == "remove" && ts !== selectedTabstop) {
747 var parentActive = ts.parents && ts.parents[selectedTabstop.index];
748 var startIndex = ts.rangeList.pointIndex(delta.start, parentActive);
749 startIndex = startIndex < 0 ? -startIndex - 1 : startIndex + 1;
750 var endIndex = ts.rangeList.pointIndex(delta.end, parentActive);
751 endIndex = endIndex < 0 ? -endIndex - 1 : endIndex - 1;
752 var toRemove = ts.rangeList.ranges.slice(startIndex, endIndex);
753 for (var j = 0; j < toRemove.length; j++)
754 this.removeRange(toRemove[j]);
755 }
756 ts.rangeList.$onChange(delta);
757 }
758 var session = this.session;
759 if (!this.$inChange && isRemove && session.getLength() == 1 && !session.getValue())
760 this.detach();
761 };
762 TabstopManager.prototype.updateLinkedFields = function () {
763 var ts = this.selectedTabstop;
764 if (!ts || !ts.hasLinkedRanges || !ts.firstNonLinked)
765 return;
766 this.$inChange = true;
767 var session = this.session;
768 var text = session.getTextRange(ts.firstNonLinked);
769 for (var i = 0; i < ts.length; i++) {
770 var range = ts[i];
771 if (!range.linked)
772 continue;
773 var original = range.original;
774 var fmt = exports.snippetManager.tmStrFormat(text, original, this.editor);
775 session.replace(range, fmt);
776 }
777 this.$inChange = false;
778 };
779 TabstopManager.prototype.onAfterExec = function (e) {
780 if (e.command && !e.command.readOnly)
781 this.updateLinkedFields();
782 };
783 TabstopManager.prototype.onChangeSelection = function () {
784 if (!this.editor)
785 return;
786 var lead = this.editor.selection.lead;
787 var anchor = this.editor.selection.anchor;
788 var isEmpty = this.editor.selection.isEmpty();
789 for (var i = 0; i < this.ranges.length; i++) {
790 if (this.ranges[i].linked)
791 continue;
792 var containsLead = this.ranges[i].contains(lead.row, lead.column);
793 var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
794 if (containsLead && containsAnchor)
795 return;
796 }
797 this.detach();
798 };
799 TabstopManager.prototype.onChangeSession = function () {
800 this.detach();
801 };
802 TabstopManager.prototype.tabNext = function (dir) {
803 var max = this.tabstops.length;
804 var index = this.index + (dir || 1);
805 index = Math.min(Math.max(index, 1), max);
806 if (index == max)
807 index = 0;
808 this.selectTabstop(index);
809 this.updateTabstopMarkers();
810 if (index === 0) {
811 this.detach();
812 }
813 };
814 TabstopManager.prototype.selectTabstop = function (index) {
815 this.$openTabstops = null;
816 var ts = this.tabstops[this.index];
817 if (ts)
818 this.addTabstopMarkers(ts);
819 this.index = index;
820 ts = this.tabstops[this.index];
821 if (!ts || !ts.length)
822 return;
823 this.selectedTabstop = ts;
824 var range = ts.firstNonLinked || ts;
825 if (ts.choices)
826 range.cursor = range.start;
827 if (!this.editor.inVirtualSelectionMode) {
828 var sel = this.editor.multiSelect;
829 sel.toSingleRange(range);
830 for (var i = 0; i < ts.length; i++) {
831 if (ts.hasLinkedRanges && ts[i].linked)
832 continue;
833 sel.addRange(ts[i].clone(), true);
834 }
835 }
836 else {
837 this.editor.selection.fromOrientedRange(range);
838 }
839 this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
840 if (this.selectedTabstop && this.selectedTabstop.choices)
841 this.editor.execCommand("startAutocomplete", { matches: this.selectedTabstop.choices });
842 };
843 TabstopManager.prototype.addTabstops = function (tabstops, start, end) {
844 var useLink = this.useLink || !this.editor.getOption("enableMultiselect");
845 if (!this.$openTabstops)
846 this.$openTabstops = [];
847 if (!tabstops[0]) {
848 var p = Range.fromPoints(end, end);
849 moveRelative(p.start, start);
850 moveRelative(p.end, start);
851 tabstops[0] = [p];
852 tabstops[0].index = 0;
853 }
854 var i = this.index;
855 var arg = [i + 1, 0];
856 var ranges = this.ranges;
857 var snippetId = this.snippetId = (this.snippetId || 0) + 1;
858 tabstops.forEach(function (ts, index) {
859 var dest = this.$openTabstops[index] || ts;
860 dest.snippetId = snippetId;
861 for (var i = 0; i < ts.length; i++) {
862 var p = ts[i];
863 var range = Range.fromPoints(p.start, p.end || p.start);
864 movePoint(range.start, start);
865 movePoint(range.end, start);
866 range.original = p;
867 range.tabstop = dest;
868 ranges.push(range);
869 if (dest != ts)
870 dest.unshift(range);
871 else
872 dest[i] = range;
873 if (p.fmtString || (dest.firstNonLinked && useLink)) {
874 range.linked = true;
875 dest.hasLinkedRanges = true;
876 }
877 else if (!dest.firstNonLinked)
878 dest.firstNonLinked = range;
879 }
880 if (!dest.firstNonLinked)
881 dest.hasLinkedRanges = false;
882 if (dest === ts) {
883 arg.push(dest);
884 this.$openTabstops[index] = dest;
885 }
886 this.addTabstopMarkers(dest);
887 dest.rangeList = dest.rangeList || new RangeList();
888 dest.rangeList.$bias = 0;
889 dest.rangeList.addList(dest);
890 }, this);
891 if (arg.length > 2) {
892 if (this.tabstops.length)
893 arg.push(arg.splice(2, 1)[0]);
894 this.tabstops.splice.apply(this.tabstops, arg);
895 }
896 };
897 TabstopManager.prototype.addTabstopMarkers = function (ts) {
898 var session = this.session;
899 ts.forEach(function (range) {
900 if (!range.markerId)
901 range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
902 });
903 };
904 TabstopManager.prototype.removeTabstopMarkers = function (ts) {
905 var session = this.session;
906 ts.forEach(function (range) {
907 session.removeMarker(range.markerId);
908 range.markerId = null;
909 });
910 };
911 TabstopManager.prototype.updateTabstopMarkers = function () {
912 if (!this.selectedTabstop)
913 return;
914 var currentSnippetId = this.selectedTabstop.snippetId;
915 if (this.selectedTabstop.index === 0) {
916 currentSnippetId--;
917 }
918 this.tabstops.forEach(function (ts) {
919 if (ts.snippetId === currentSnippetId)
920 this.addTabstopMarkers(ts);
921 else
922 this.removeTabstopMarkers(ts);
923 }, this);
924 };
925 TabstopManager.prototype.removeRange = function (range) {
926 var i = range.tabstop.indexOf(range);
927 if (i != -1)
928 range.tabstop.splice(i, 1);
929 i = this.ranges.indexOf(range);
930 if (i != -1)
931 this.ranges.splice(i, 1);
932 i = range.tabstop.rangeList.ranges.indexOf(range);
933 if (i != -1)
934 range.tabstop.splice(i, 1);
935 this.session.removeMarker(range.markerId);
936 if (!range.tabstop.length) {
937 i = this.tabstops.indexOf(range.tabstop);
938 if (i != -1)
939 this.tabstops.splice(i, 1);
940 if (!this.tabstops.length)
941 this.detach();
942 }
943 };
944 return TabstopManager;
945 }());
946 TabstopManager.prototype.keyboardHandler = new HashHandler();
947 TabstopManager.prototype.keyboardHandler.bindKeys({
948 "Tab": function (editor) {
949 if (exports.snippetManager && exports.snippetManager.expandWithTab(editor))
950 return;
951 editor.tabstopManager.tabNext(1);
952 editor.renderer.scrollCursorIntoView();
953 },
954 "Shift-Tab": function (editor) {
955 editor.tabstopManager.tabNext(-1);
956 editor.renderer.scrollCursorIntoView();
957 },
958 "Esc": function (editor) {
959 editor.tabstopManager.detach();
960 }
961 });
962 var movePoint = function (point, diff) {
963 if (point.row == 0)
964 point.column += diff.column;
965 point.row += diff.row;
966 };
967 var moveRelative = function (point, start) {
968 if (point.row == start.row)
969 point.column -= start.column;
970 point.row -= start.row;
971 };
972 dom.importCssString("\n.ace_snippet-marker {\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n background: rgba(194, 193, 208, 0.09);\n border: 1px dotted rgba(211, 208, 235, 0.62);\n position: absolute;\n}", "snippets.css", false);
973 exports.snippetManager = new SnippetManager();
974 var Editor = require("./editor").Editor;
975 (function () {
976 this.insertSnippet = function (content, options) {
977 return exports.snippetManager.insertSnippet(this, content, options);
978 };
979 this.expandSnippet = function (options) {
980 return exports.snippetManager.expandWithTab(this, options);
981 };
982 }).call(Editor.prototype);
983
984 });
985
986 ace.define("ace/autocomplete/inline_screenreader",["require","exports","module"], function(require, exports, module){"use strict";
987 var AceInlineScreenReader = /** @class */ (function () {
988 function AceInlineScreenReader(editor) {
989 this.editor = editor;
990 this.screenReaderDiv = document.createElement("div");
991 this.screenReaderDiv.classList.add("ace_screenreader-only");
992 this.editor.container.appendChild(this.screenReaderDiv);
993 }
994 AceInlineScreenReader.prototype.setScreenReaderContent = function (content) {
995 if (!this.popup && this.editor.completer && /**@type{import("../autocomplete").Autocomplete}*/ (this.editor.completer).popup) {
996 this.popup = /**@type{import("../autocomplete").Autocomplete}*/ (this.editor.completer).popup;
997 this.popup.renderer.on("afterRender", function () {
998 var row = this.popup.getRow();
999 var t = this.popup.renderer.$textLayer;
1000 var selected = t.element.childNodes[row - t.config.firstRow];
1001 if (selected) {
1002 var idString = "doc-tooltip ";
1003 for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) {
1004 idString += "ace-inline-screenreader-line-".concat(lineIndex, " ");
1005 }
1006 selected.setAttribute("aria-describedby", idString);
1007 }
1008 }.bind(this));
1009 }
1010 while (this.screenReaderDiv.firstChild) {
1011 this.screenReaderDiv.removeChild(this.screenReaderDiv.firstChild);
1012 }
1013 this._lines = content.split(/\r\n|\r|\n/);
1014 var codeElement = this.createCodeBlock();
1015 this.screenReaderDiv.appendChild(codeElement);
1016 };
1017 AceInlineScreenReader.prototype.destroy = function () {
1018 this.screenReaderDiv.remove();
1019 };
1020 AceInlineScreenReader.prototype.createCodeBlock = function () {
1021 var container = document.createElement("pre");
1022 container.setAttribute("id", "ace-inline-screenreader");
1023 for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) {
1024 var codeElement = document.createElement("code");
1025 codeElement.setAttribute("id", "ace-inline-screenreader-line-".concat(lineIndex));
1026 var line = document.createTextNode(this._lines[lineIndex]);
1027 codeElement.appendChild(line);
1028 container.appendChild(codeElement);
1029 }
1030 return container;
1031 };
1032 return AceInlineScreenReader;
1033 }());
1034 exports.AceInlineScreenReader = AceInlineScreenReader;
1035
1036 });
1037
1038 ace.define("ace/autocomplete/inline",["require","exports","module","ace/snippets","ace/autocomplete/inline_screenreader"], function(require, exports, module){"use strict";
1039 var snippetManager = require("../snippets").snippetManager;
1040 var AceInlineScreenReader = require("./inline_screenreader").AceInlineScreenReader;
1041 var AceInline = /** @class */ (function () {
1042 function AceInline() {
1043 this.editor = null;
1044 }
1045 AceInline.prototype.show = function (editor, completion, prefix) {
1046 prefix = prefix || "";
1047 if (editor && this.editor && this.editor !== editor) {
1048 this.hide();
1049 this.editor = null;
1050 this.inlineScreenReader = null;
1051 }
1052 if (!editor || !completion) {
1053 return false;
1054 }
1055 if (!this.inlineScreenReader) {
1056 this.inlineScreenReader = new AceInlineScreenReader(editor);
1057 }
1058 var displayText = completion.snippet ? snippetManager.getDisplayTextForSnippet(editor, completion.snippet) : completion.value;
1059 if (completion.hideInlinePreview || !displayText || !displayText.startsWith(prefix)) {
1060 return false;
1061 }
1062 this.editor = editor;
1063 this.inlineScreenReader.setScreenReaderContent(displayText);
1064 displayText = displayText.slice(prefix.length);
1065 if (displayText === "") {
1066 editor.removeGhostText();
1067 }
1068 else {
1069 editor.setGhostText(displayText);
1070 }
1071 return true;
1072 };
1073 AceInline.prototype.isOpen = function () {
1074 if (!this.editor) {
1075 return false;
1076 }
1077 return !!this.editor.renderer.$ghostText;
1078 };
1079 AceInline.prototype.hide = function () {
1080 if (!this.editor) {
1081 return false;
1082 }
1083 this.editor.removeGhostText();
1084 return true;
1085 };
1086 AceInline.prototype.destroy = function () {
1087 this.hide();
1088 this.editor = null;
1089 if (this.inlineScreenReader) {
1090 this.inlineScreenReader.destroy();
1091 this.inlineScreenReader = null;
1092 }
1093 };
1094 return AceInline;
1095 }());
1096 exports.AceInline = AceInline;
1097
1098 });
1099
1100 ace.define("ace/autocomplete/popup",["require","exports","module","ace/virtual_renderer","ace/editor","ace/range","ace/lib/event","ace/lib/lang","ace/lib/dom","ace/config","ace/lib/useragent"], function(require, exports, module){"use strict";
1101 var Renderer = require("../virtual_renderer").VirtualRenderer;
1102 var Editor = require("../editor").Editor;
1103 var Range = require("../range").Range;
1104 var event = require("../lib/event");
1105 var lang = require("../lib/lang");
1106 var dom = require("../lib/dom");
1107 var nls = require("../config").nls;
1108 var userAgent = require("./../lib/useragent");
1109 var getAriaId = function (index) {
1110 return "suggest-aria-id:".concat(index);
1111 };
1112 var popupAriaRole = userAgent.isSafari ? "menu" : "listbox";
1113 var optionAriaRole = userAgent.isSafari ? "menuitem" : "option";
1114 var ariaActiveState = userAgent.isSafari ? "aria-current" : "aria-selected";
1115 var $singleLineEditor = function (el) {
1116 var renderer = new Renderer(el);
1117 renderer.$maxLines = 4;
1118 var editor = new Editor(renderer);
1119 editor.setHighlightActiveLine(false);
1120 editor.setShowPrintMargin(false);
1121 editor.renderer.setShowGutter(false);
1122 editor.renderer.setHighlightGutterLine(false);
1123 editor.$mouseHandler.$focusTimeout = 0;
1124 editor.$highlightTagPending = true;
1125 return editor;
1126 };
1127 var AcePopup = /** @class */ (function () {
1128 function AcePopup(parentNode) {
1129 var el = dom.createElement("div");
1130 var popup = $singleLineEditor(el);
1131 if (parentNode) {
1132 parentNode.appendChild(el);
1133 }
1134 el.style.display = "none";
1135 popup.renderer.content.style.cursor = "default";
1136 popup.renderer.setStyle("ace_autocomplete");
1137 popup.renderer.$textLayer.element.setAttribute("role", popupAriaRole);
1138 popup.renderer.$textLayer.element.setAttribute("aria-roledescription", nls("Autocomplete suggestions"));
1139 popup.renderer.$textLayer.element.setAttribute("aria-label", nls("Autocomplete suggestions"));
1140 popup.renderer.textarea.setAttribute("aria-hidden", "true");
1141 popup.setOption("displayIndentGuides", false);
1142 popup.setOption("dragDelay", 150);
1143 var noop = function () { };
1144 popup.focus = noop;
1145 popup.$isFocused = true;
1146 popup.renderer.$cursorLayer.restartTimer = noop;
1147 popup.renderer.$cursorLayer.element.style.opacity = "0";
1148 popup.renderer.$maxLines = 8;
1149 popup.renderer.$keepTextAreaAtCursor = false;
1150 popup.setHighlightActiveLine(false);
1151 popup.session.highlight("");
1152 popup.session.$searchHighlight.clazz = "ace_highlight-marker";
1153 popup.on("mousedown", function (e) {
1154 var pos = e.getDocumentPosition();
1155 popup.selection.moveToPosition(pos);
1156 selectionMarker.start.row = selectionMarker.end.row = pos.row;
1157 e.stop();
1158 });
1159 var lastMouseEvent;
1160 var hoverMarker = new Range(-1, 0, -1, Infinity);
1161 var selectionMarker = new Range(-1, 0, -1, Infinity);
1162 selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
1163 popup.setSelectOnHover = function (val) {
1164 if (!val) {
1165 hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
1166 }
1167 else if (hoverMarker.id) {
1168 popup.session.removeMarker(hoverMarker.id);
1169 hoverMarker.id = null;
1170 }
1171 };
1172 popup.setSelectOnHover(false);
1173 popup.on("mousemove", function (e) {
1174 if (!lastMouseEvent) {
1175 lastMouseEvent = e;
1176 return;
1177 }
1178 if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
1179 return;
1180 }
1181 lastMouseEvent = e;
1182 lastMouseEvent.scrollTop = popup.renderer.scrollTop;
1183 popup.isMouseOver = true;
1184 var row = lastMouseEvent.getDocumentPosition().row;
1185 if (hoverMarker.start.row != row) {
1186 if (!hoverMarker.id)
1187 popup.setRow(row);
1188 setHoverMarker(row);
1189 }
1190 });
1191 popup.renderer.on("beforeRender", function () {
1192 if (lastMouseEvent && hoverMarker.start.row != -1) {
1193 lastMouseEvent.$pos = null;
1194 var row = lastMouseEvent.getDocumentPosition().row;
1195 if (!hoverMarker.id)
1196 popup.setRow(row);
1197 setHoverMarker(row, true);
1198 }
1199 });
1200 popup.renderer.on("afterRender", function () {
1201 var row = popup.getRow();
1202 var t = popup.renderer.$textLayer;
1203 var selected = /** @type {HTMLElement|null} */ (t.element.childNodes[row - t.config.firstRow]);
1204 var el = document.activeElement; // Active element is textarea of main editor
1205 if (selected !== popup.selectedNode && popup.selectedNode) {
1206 dom.removeCssClass(popup.selectedNode, "ace_selected");
1207 el.removeAttribute("aria-activedescendant");
1208 popup.selectedNode.removeAttribute(ariaActiveState);
1209 popup.selectedNode.removeAttribute("id");
1210 }
1211 popup.selectedNode = selected;
1212 if (selected) {
1213 dom.addCssClass(selected, "ace_selected");
1214 var ariaId = getAriaId(row);
1215 selected.id = ariaId;
1216 t.element.setAttribute("aria-activedescendant", ariaId);
1217 el.setAttribute("aria-activedescendant", ariaId);
1218 selected.setAttribute("role", optionAriaRole);
1219 selected.setAttribute("aria-roledescription", nls("item"));
1220 selected.setAttribute("aria-label", popup.getData(row).caption || popup.getData(row).value);
1221 selected.setAttribute("aria-setsize", popup.data.length);
1222 selected.setAttribute("aria-posinset", row + 1);
1223 selected.setAttribute("aria-describedby", "doc-tooltip");
1224 selected.setAttribute(ariaActiveState, "true");
1225 }
1226 });
1227 var hideHoverMarker = function () { setHoverMarker(-1); };
1228 var setHoverMarker = function (row, suppressRedraw) {
1229 if (row !== hoverMarker.start.row) {
1230 hoverMarker.start.row = hoverMarker.end.row = row;
1231 if (!suppressRedraw)
1232 popup.session._emit("changeBackMarker");
1233 popup._emit("changeHoverMarker");
1234 }
1235 };
1236 popup.getHoveredRow = function () {
1237 return hoverMarker.start.row;
1238 };
1239 event.addListener(popup.container, "mouseout", function () {
1240 popup.isMouseOver = false;
1241 hideHoverMarker();
1242 });
1243 popup.on("hide", hideHoverMarker);
1244 popup.on("changeSelection", hideHoverMarker);
1245 popup.session.doc.getLength = function () {
1246 return popup.data.length;
1247 };
1248 popup.session.doc.getLine = function (i) {
1249 var data = popup.data[i];
1250 if (typeof data == "string")
1251 return data;
1252 return (data && data.value) || "";
1253 };
1254 var bgTokenizer = popup.session.bgTokenizer;
1255 bgTokenizer.$tokenizeRow = function (row) {
1256 var data = popup.data[row];
1257 var tokens = [];
1258 if (!data)
1259 return tokens;
1260 if (typeof data == "string")
1261 data = { value: data };
1262 var caption = data.caption || data.value || data.name;
1263 function addToken(value, className) {
1264 value && tokens.push({
1265 type: (data.className || "") + (className || ""),
1266 value: value
1267 });
1268 }
1269 var lower = caption.toLowerCase();
1270 var filterText = (popup.filterText || "").toLowerCase();
1271 var lastIndex = 0;
1272 var lastI = 0;
1273 for (var i = 0; i <= filterText.length; i++) {
1274 if (i != lastI && (data.matchMask & (1 << i) || i == filterText.length)) {
1275 var sub = filterText.slice(lastI, i);
1276 lastI = i;
1277 var index = lower.indexOf(sub, lastIndex);
1278 if (index == -1)
1279 continue;
1280 addToken(caption.slice(lastIndex, index), "");
1281 lastIndex = index + sub.length;
1282 addToken(caption.slice(index, lastIndex), "completion-highlight");
1283 }
1284 }
1285 addToken(caption.slice(lastIndex, caption.length), "");
1286 tokens.push({ type: "completion-spacer", value: " " });
1287 if (data.meta)
1288 tokens.push({ type: "completion-meta", value: data.meta });
1289 if (data.message)
1290 tokens.push({ type: "completion-message", value: data.message });
1291 return tokens;
1292 };
1293 bgTokenizer.$updateOnChange = noop;
1294 bgTokenizer.start = noop;
1295 popup.session.$computeWidth = function () {
1296 return this.screenWidth = 0;
1297 };
1298 popup.isOpen = false;
1299 popup.isTopdown = false;
1300 popup.autoSelect = true;
1301 popup.filterText = "";
1302 popup.isMouseOver = false;
1303 popup.data = [];
1304 popup.setData = function (list, filterText) {
1305 popup.filterText = filterText || "";
1306 popup.setValue(lang.stringRepeat("\n", list.length), -1);
1307 popup.data = list || [];
1308 popup.setRow(0);
1309 };
1310 popup.getData = function (row) {
1311 return popup.data[row];
1312 };
1313 popup.getRow = function () {
1314 return selectionMarker.start.row;
1315 };
1316 popup.setRow = function (line) {
1317 line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line));
1318 if (selectionMarker.start.row != line) {
1319 popup.selection.clearSelection();
1320 selectionMarker.start.row = selectionMarker.end.row = line || 0;
1321 popup.session._emit("changeBackMarker");
1322 popup.moveCursorTo(line || 0, 0);
1323 if (popup.isOpen)
1324 popup._signal("select");
1325 }
1326 };
1327 popup.on("changeSelection", function () {
1328 if (popup.isOpen)
1329 popup.setRow(popup.selection.lead.row);
1330 popup.renderer.scrollCursorIntoView();
1331 });
1332 popup.hide = function () {
1333 this.container.style.display = "none";
1334 popup.anchorPos = null;
1335 popup.anchor = null;
1336 if (popup.isOpen) {
1337 popup.isOpen = false;
1338 this._signal("hide");
1339 }
1340 };
1341 popup.tryShow = function (pos, lineHeight, anchor, forceShow) {
1342 if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor &&
1343 popup.anchorPos.top === pos.top && popup.anchorPos.left === pos.left &&
1344 popup.anchor === anchor) {
1345 return true;
1346 }
1347 var el = this.container;
1348 var screenHeight = window.innerHeight;
1349 var screenWidth = window.innerWidth;
1350 var renderer = this.renderer;
1351 var maxH = renderer.$maxLines * lineHeight * 1.4;
1352 var dims = { top: 0, bottom: 0, left: 0 };
1353 var spaceBelow = screenHeight - pos.top - 3 * this.$borderSize - lineHeight;
1354 var spaceAbove = pos.top - 3 * this.$borderSize;
1355 if (!anchor) {
1356 if (spaceAbove <= spaceBelow || spaceBelow >= maxH) {
1357 anchor = "bottom";
1358 }
1359 else {
1360 anchor = "top";
1361 }
1362 }
1363 if (anchor === "top") {
1364 dims.bottom = pos.top - this.$borderSize;
1365 dims.top = dims.bottom - maxH;
1366 }
1367 else if (anchor === "bottom") {
1368 dims.top = pos.top + lineHeight + this.$borderSize;
1369 dims.bottom = dims.top + maxH;
1370 }
1371 var fitsX = dims.top >= 0 && dims.bottom <= screenHeight;
1372 if (!forceShow && !fitsX) {
1373 return false;
1374 }
1375 if (!fitsX) {
1376 if (anchor === "top") {
1377 renderer.$maxPixelHeight = spaceAbove;
1378 }
1379 else {
1380 renderer.$maxPixelHeight = spaceBelow;
1381 }
1382 }
1383 else {
1384 renderer.$maxPixelHeight = null;
1385 }
1386 if (anchor === "top") {
1387 el.style.top = "";
1388 el.style.bottom = (screenHeight - dims.bottom) + "px";
1389 popup.isTopdown = false;
1390 }
1391 else {
1392 el.style.top = dims.top + "px";
1393 el.style.bottom = "";
1394 popup.isTopdown = true;
1395 }
1396 el.style.display = "";
1397 var left = pos.left;
1398 if (left + el.offsetWidth > screenWidth)
1399 left = screenWidth - el.offsetWidth;
1400 el.style.left = left + "px";
1401 el.style.right = "";
1402 if (!popup.isOpen) {
1403 popup.isOpen = true;
1404 this._signal("show");
1405 lastMouseEvent = null;
1406 }
1407 popup.anchorPos = pos;
1408 popup.anchor = anchor;
1409 return true;
1410 };
1411 popup.show = function (pos, lineHeight, topdownOnly) {
1412 this.tryShow(pos, lineHeight, topdownOnly ? "bottom" : undefined, true);
1413 };
1414 popup.goTo = function (where) {
1415 var row = this.getRow();
1416 var max = this.session.getLength() - 1;
1417 switch (where) {
1418 case "up":
1419 row = row <= 0 ? max : row - 1;
1420 break;
1421 case "down":
1422 row = row >= max ? -1 : row + 1;
1423 break;
1424 case "start":
1425 row = 0;
1426 break;
1427 case "end":
1428 row = max;
1429 break;
1430 }
1431 this.setRow(row);
1432 };
1433 popup.getTextLeftOffset = function () {
1434 return this.$borderSize + this.renderer.$padding + this.$imageSize;
1435 };
1436 popup.$imageSize = 0;
1437 popup.$borderSize = 1;
1438 return popup;
1439 }
1440 return AcePopup;
1441 }());
1442 dom.importCssString("\n.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\n background-color: #CAD6FA;\n z-index: 1;\n}\n.ace_dark.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\n background-color: #3a674e;\n}\n.ace_editor.ace_autocomplete .ace_line-hover {\n border: 1px solid #abbffe;\n margin-top: -1px;\n background: rgba(233,233,253,0.4);\n position: absolute;\n z-index: 2;\n}\n.ace_dark.ace_editor.ace_autocomplete .ace_line-hover {\n border: 1px solid rgba(109, 150, 13, 0.8);\n background: rgba(58, 103, 78, 0.62);\n}\n.ace_completion-meta {\n opacity: 0.5;\n margin-left: 0.9em;\n}\n.ace_completion-message {\n margin-left: 0.9em;\n color: blue;\n}\n.ace_editor.ace_autocomplete .ace_completion-highlight{\n color: #2d69c7;\n}\n.ace_dark.ace_editor.ace_autocomplete .ace_completion-highlight{\n color: #93ca12;\n}\n.ace_editor.ace_autocomplete {\n width: 300px;\n z-index: 200000;\n border: 1px lightgray solid;\n position: fixed;\n box-shadow: 2px 3px 5px rgba(0,0,0,.2);\n line-height: 1.4;\n background: #fefefe;\n color: #111;\n}\n.ace_dark.ace_editor.ace_autocomplete {\n border: 1px #484747 solid;\n box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.51);\n line-height: 1.4;\n background: #25282c;\n color: #c1c1c1;\n}\n.ace_autocomplete .ace_text-layer {\n width: calc(100% - 8px);\n}\n.ace_autocomplete .ace_line {\n display: flex;\n align-items: center;\n}\n.ace_autocomplete .ace_line > * {\n min-width: 0;\n flex: 0 0 auto;\n}\n.ace_autocomplete .ace_line .ace_ {\n flex: 0 1 auto;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.ace_autocomplete .ace_completion-spacer {\n flex: 1;\n}\n.ace_autocomplete.ace_loading:after {\n content: \"\";\n position: absolute;\n top: 0px;\n height: 2px;\n width: 8%;\n background: blue;\n z-index: 100;\n animation: ace_progress 3s infinite linear;\n animation-delay: 300ms;\n transform: translateX(-100%) scaleX(1);\n}\n@keyframes ace_progress {\n 0% { transform: translateX(-100%) scaleX(1) }\n 50% { transform: translateX(625%) scaleX(2) } \n 100% { transform: translateX(1500%) scaleX(3) } \n}\n@media (prefers-reduced-motion) {\n .ace_autocomplete.ace_loading:after {\n transform: translateX(625%) scaleX(2);\n animation: none;\n }\n}\n", "autocompletion.css", false);
1443 exports.AcePopup = AcePopup;
1444 exports.$singleLineEditor = $singleLineEditor;
1445 exports.getAriaId = getAriaId;
1446
1447 });
1448
1449 ace.define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module){"use strict";
1450 exports.parForEach = function (array, fn, callback) {
1451 var completed = 0;
1452 var arLength = array.length;
1453 if (arLength === 0)
1454 callback();
1455 for (var i = 0; i < arLength; i++) {
1456 fn(array[i], function (result, err) {
1457 completed++;
1458 if (completed === arLength)
1459 callback(result, err);
1460 });
1461 }
1462 };
1463 var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\u2000\u2070-\uFFFF]/;
1464 exports.retrievePrecedingIdentifier = function (text, pos, regex) {
1465 regex = regex || ID_REGEX;
1466 var buf = [];
1467 for (var i = pos - 1; i >= 0; i--) {
1468 if (regex.test(text[i]))
1469 buf.push(text[i]);
1470 else
1471 break;
1472 }
1473 return buf.reverse().join("");
1474 };
1475 exports.retrieveFollowingIdentifier = function (text, pos, regex) {
1476 regex = regex || ID_REGEX;
1477 var buf = [];
1478 for (var i = pos; i < text.length; i++) {
1479 if (regex.test(text[i]))
1480 buf.push(text[i]);
1481 else
1482 break;
1483 }
1484 return buf;
1485 };
1486 exports.getCompletionPrefix = function (editor) {
1487 var pos = editor.getCursorPosition();
1488 var line = editor.session.getLine(pos.row);
1489 var prefix;
1490 editor.completers.forEach(function (completer) {
1491 if (completer.identifierRegexps) {
1492 completer.identifierRegexps.forEach(function (identifierRegex) {
1493 if (!prefix && identifierRegex)
1494 prefix = this.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
1495 }.bind(this));
1496 }
1497 }.bind(this));
1498 return prefix || this.retrievePrecedingIdentifier(line, pos.column);
1499 };
1500 exports.triggerAutocomplete = function (editor) {
1501 var pos = editor.getCursorPosition();
1502 var line = editor.session.getLine(pos.row);
1503 var column = (pos.column === 0) ? 0 : pos.column - 1;
1504 var previousChar = line[column];
1505 return editor.completers.some(function (el) {
1506 if (el.triggerCharacters && Array.isArray(el.triggerCharacters)) {
1507 return el.triggerCharacters.includes(previousChar);
1508 }
1509 });
1510 };
1511
1512 });
1513
1514 ace.define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/inline","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/lang","ace/lib/dom","ace/snippets","ace/config","ace/lib/event","ace/lib/scroll"], function(require, exports, module){"use strict";
1515 var HashHandler = require("./keyboard/hash_handler").HashHandler;
1516 var AcePopup = require("./autocomplete/popup").AcePopup;
1517 var AceInline = require("./autocomplete/inline").AceInline;
1518 var getAriaId = require("./autocomplete/popup").getAriaId;
1519 var util = require("./autocomplete/util");
1520 var lang = require("./lib/lang");
1521 var dom = require("./lib/dom");
1522 var snippetManager = require("./snippets").snippetManager;
1523 var config = require("./config");
1524 var event = require("./lib/event");
1525 var preventParentScroll = require("./lib/scroll").preventParentScroll;
1526 var destroyCompleter = function (e, editor) {
1527 editor.completer && editor.completer.destroy();
1528 };
1529 var Autocomplete = /** @class */ (function () {
1530 function Autocomplete() {
1531 this.autoInsert = false;
1532 this.autoSelect = true;
1533 this.autoShown = false;
1534 this.exactMatch = false;
1535 this.inlineEnabled = false;
1536 this.keyboardHandler = new HashHandler();
1537 this.keyboardHandler.bindKeys(this.commands);
1538 this.parentNode = null;
1539 this.setSelectOnHover = false;
1540 this.hasSeen = new Set();
1541 this.showLoadingState = false;
1542 this.stickySelectionDelay = 500;
1543 this.blurListener = this.blurListener.bind(this);
1544 this.changeListener = this.changeListener.bind(this);
1545 this.mousedownListener = this.mousedownListener.bind(this);
1546 this.mousewheelListener = this.mousewheelListener.bind(this);
1547 this.onLayoutChange = this.onLayoutChange.bind(this);
1548 this.changeTimer = lang.delayedCall(function () {
1549 this.updateCompletions(true);
1550 }.bind(this));
1551 this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50);
1552 this.popupTimer = lang.delayedCall(this.$updatePopupPosition.bind(this), 50);
1553 this.stickySelectionTimer = lang.delayedCall(function () {
1554 this.stickySelection = true;
1555 }.bind(this), this.stickySelectionDelay);
1556 this.$firstOpenTimer = lang.delayedCall(/**@this{Autocomplete}*/ function () {
1557 var initialPosition = this.completionProvider && this.completionProvider.initialPosition;
1558 if (this.autoShown || (this.popup && this.popup.isOpen) || !initialPosition || this.editor.completers.length === 0)
1559 return;
1560 this.completions = new FilteredList(Autocomplete.completionsForLoading);
1561 this.openPopup(this.editor, initialPosition.prefix, false);
1562 this.popup.renderer.setStyle("ace_loading", true);
1563 }.bind(this), this.stickySelectionDelay);
1564 }
1565 Object.defineProperty(Autocomplete, "completionsForLoading", {
1566 get: function () {
1567 return [{
1568 caption: config.nls("Loading..."),
1569 value: ""
1570 }];
1571 },
1572 enumerable: false,
1573 configurable: true
1574 });
1575 Autocomplete.prototype.$init = function () {
1576 this.popup = new AcePopup(this.parentNode || document.body || document.documentElement);
1577 this.popup.on("click", function (e) {
1578 this.insertMatch();
1579 e.stop();
1580 }.bind(this));
1581 this.popup.focus = this.editor.focus.bind(this.editor);
1582 this.popup.on("show", this.$onPopupShow.bind(this));
1583 this.popup.on("hide", this.$onHidePopup.bind(this));
1584 this.popup.on("select", this.$onPopupChange.bind(this));
1585 event.addListener(this.popup.container, "mouseout", this.mouseOutListener.bind(this));
1586 this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null));
1587 this.popup.renderer.on("afterRender", this.$onPopupRender.bind(this));
1588 return this.popup;
1589 };
1590 Autocomplete.prototype.$initInline = function () {
1591 if (!this.inlineEnabled || this.inlineRenderer)
1592 return;
1593 this.inlineRenderer = new AceInline();
1594 return this.inlineRenderer;
1595 };
1596 Autocomplete.prototype.getPopup = function () {
1597 return this.popup || this.$init();
1598 };
1599 Autocomplete.prototype.$onHidePopup = function () {
1600 if (this.inlineRenderer) {
1601 this.inlineRenderer.hide();
1602 }
1603 this.hideDocTooltip();
1604 this.stickySelectionTimer.cancel();
1605 this.popupTimer.cancel();
1606 this.stickySelection = false;
1607 };
1608 Autocomplete.prototype.$seen = function (completion) {
1609 if (!this.hasSeen.has(completion) && completion && completion.completer && completion.completer.onSeen && typeof completion.completer.onSeen === "function") {
1610 completion.completer.onSeen(this.editor, completion);
1611 this.hasSeen.add(completion);
1612 }
1613 };
1614 Autocomplete.prototype.$onPopupChange = function (hide) {
1615 if (this.inlineRenderer && this.inlineEnabled) {
1616 var completion = hide ? null : this.popup.getData(this.popup.getRow());
1617 this.$updateGhostText(completion);
1618 if (this.popup.isMouseOver && this.setSelectOnHover) {
1619 this.tooltipTimer.call(null, null);
1620 return;
1621 }
1622 this.popupTimer.schedule();
1623 this.tooltipTimer.schedule();
1624 }
1625 else {
1626 this.popupTimer.call(null, null);
1627 this.tooltipTimer.call(null, null);
1628 }
1629 };
1630 Autocomplete.prototype.$updateGhostText = function (completion) {
1631 var row = this.base.row;
1632 var column = this.base.column;
1633 var cursorColumn = this.editor.getCursorPosition().column;
1634 var prefix = this.editor.session.getLine(row).slice(column, cursorColumn);
1635 if (!this.inlineRenderer.show(this.editor, completion, prefix)) {
1636 this.inlineRenderer.hide();
1637 }
1638 else {
1639 this.$seen(completion);
1640 }
1641 };
1642 Autocomplete.prototype.$onPopupRender = function () {
1643 var inlineEnabled = this.inlineRenderer && this.inlineEnabled;
1644 if (this.completions && this.completions.filtered && this.completions.filtered.length > 0) {
1645 for (var i = this.popup.getFirstVisibleRow(); i <= this.popup.getLastVisibleRow(); i++) {
1646 var completion = this.popup.getData(i);
1647 if (completion && (!inlineEnabled || completion.hideInlinePreview)) {
1648 this.$seen(completion);
1649 }
1650 }
1651 }
1652 };
1653 Autocomplete.prototype.$onPopupShow = function (hide) {
1654 this.$onPopupChange(hide);
1655 this.stickySelection = false;
1656 if (this.stickySelectionDelay >= 0)
1657 this.stickySelectionTimer.schedule(this.stickySelectionDelay);
1658 };
1659 Autocomplete.prototype.observeLayoutChanges = function () {
1660 if (this.$elements || !this.editor)
1661 return;
1662 window.addEventListener("resize", this.onLayoutChange, { passive: true });
1663 window.addEventListener("wheel", this.mousewheelListener);
1664 var el = this.editor.container.parentNode;
1665 var elements = [];
1666 while (el) {
1667 elements.push(el);
1668 el.addEventListener("scroll", this.onLayoutChange, { passive: true });
1669 el = el.parentNode;
1670 }
1671 this.$elements = elements;
1672 };
1673 Autocomplete.prototype.unObserveLayoutChanges = function () {
1674 var _this = this;
1675 window.removeEventListener("resize", this.onLayoutChange, { passive: true });
1676 window.removeEventListener("wheel", this.mousewheelListener);
1677 this.$elements && this.$elements.forEach(function (el) {
1678 el.removeEventListener("scroll", _this.onLayoutChange, { passive: true });
1679 });
1680 this.$elements = null;
1681 };
1682 Autocomplete.prototype.onLayoutChange = function () {
1683 if (!this.popup.isOpen)
1684 return this.unObserveLayoutChanges();
1685 this.$updatePopupPosition();
1686 this.updateDocTooltip();
1687 };
1688 Autocomplete.prototype.$updatePopupPosition = function () {
1689 var editor = this.editor;
1690 var renderer = editor.renderer;
1691 var lineHeight = renderer.layerConfig.lineHeight;
1692 var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
1693 pos.left -= this.popup.getTextLeftOffset();
1694 var rect = editor.container.getBoundingClientRect();
1695 pos.top += rect.top - renderer.layerConfig.offset;
1696 pos.left += rect.left - editor.renderer.scrollLeft;
1697 pos.left += renderer.gutterWidth;
1698 var posGhostText = {
1699 top: pos.top,
1700 left: pos.left
1701 };
1702 if (renderer.$ghostText && renderer.$ghostTextWidget) {
1703 if (this.base.row === renderer.$ghostText.position.row) {
1704 posGhostText.top += renderer.$ghostTextWidget.el.offsetHeight;
1705 }
1706 }
1707 var editorContainerBottom = editor.container.getBoundingClientRect().bottom - lineHeight;
1708 var lowestPosition = editorContainerBottom < posGhostText.top ?
1709 { top: editorContainerBottom, left: posGhostText.left } :
1710 posGhostText;
1711 if (this.popup.tryShow(lowestPosition, lineHeight, "bottom")) {
1712 return;
1713 }
1714 if (this.popup.tryShow(pos, lineHeight, "top")) {
1715 return;
1716 }
1717 this.popup.show(pos, lineHeight);
1718 };
1719 Autocomplete.prototype.openPopup = function (editor, prefix, keepPopupPosition) {
1720 this.$firstOpenTimer.cancel();
1721 if (!this.popup)
1722 this.$init();
1723 if (this.inlineEnabled && !this.inlineRenderer)
1724 this.$initInline();
1725 this.popup.autoSelect = this.autoSelect;
1726 this.popup.setSelectOnHover(this.setSelectOnHover);
1727 var oldRow = this.popup.getRow();
1728 var previousSelectedItem = this.popup.data[oldRow];
1729 this.popup.setData(this.completions.filtered, this.completions.filterText);
1730 if (this.editor.textInput.setAriaOptions) {
1731 this.editor.textInput.setAriaOptions({
1732 activeDescendant: getAriaId(this.popup.getRow()),
1733 inline: this.inlineEnabled
1734 });
1735 }
1736 editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
1737 var newRow;
1738 if (this.stickySelection)
1739 newRow = this.popup.data.indexOf(previousSelectedItem);
1740 if (!newRow || newRow === -1)
1741 newRow = 0;
1742 this.popup.setRow(this.autoSelect ? newRow : -1);
1743 if (newRow === oldRow && previousSelectedItem !== this.completions.filtered[newRow])
1744 this.$onPopupChange();
1745 var inlineEnabled = this.inlineRenderer && this.inlineEnabled;
1746 if (newRow === oldRow && inlineEnabled) {
1747 var completion = this.popup.getData(this.popup.getRow());
1748 this.$updateGhostText(completion);
1749 }
1750 if (!keepPopupPosition) {
1751 this.popup.setTheme(editor.getTheme());
1752 this.popup.setFontSize(editor.getFontSize());
1753 this.$updatePopupPosition();
1754 if (this.tooltipNode) {
1755 this.updateDocTooltip();
1756 }
1757 }
1758 else if (keepPopupPosition && !prefix) {
1759 this.detach();
1760 }
1761 this.changeTimer.cancel();
1762 this.observeLayoutChanges();
1763 };
1764 Autocomplete.prototype.detach = function () {
1765 if (this.editor) {
1766 this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
1767 this.editor.off("changeSelection", this.changeListener);
1768 this.editor.off("blur", this.blurListener);
1769 this.editor.off("mousedown", this.mousedownListener);
1770 this.editor.off("mousewheel", this.mousewheelListener);
1771 }
1772 this.$firstOpenTimer.cancel();
1773 this.changeTimer.cancel();
1774 this.hideDocTooltip();
1775 if (this.completionProvider) {
1776 this.completionProvider.detach();
1777 }
1778 if (this.popup && this.popup.isOpen)
1779 this.popup.hide();
1780 if (this.popup && this.popup.renderer) {
1781 this.popup.renderer.off("afterRender", this.$onPopupRender);
1782 }
1783 if (this.base)
1784 this.base.detach();
1785 this.activated = false;
1786 this.completionProvider = this.completions = this.base = null;
1787 this.unObserveLayoutChanges();
1788 };
1789 Autocomplete.prototype.changeListener = function (e) {
1790 var cursor = this.editor.selection.lead;
1791 if (cursor.row != this.base.row || cursor.column < this.base.column) {
1792 this.detach();
1793 }
1794 if (this.activated)
1795 this.changeTimer.schedule();
1796 else
1797 this.detach();
1798 };
1799 Autocomplete.prototype.blurListener = function (e) {
1800 var el = document.activeElement;
1801 var text = this.editor.textInput.getElement();
1802 var fromTooltip = e.relatedTarget && this.tooltipNode && this.tooltipNode.contains(e.relatedTarget);
1803 var container = this.popup && this.popup.container;
1804 if (el != text && el.parentNode != container && !fromTooltip
1805 && el != this.tooltipNode && e.relatedTarget != text) {
1806 this.detach();
1807 }
1808 };
1809 Autocomplete.prototype.mousedownListener = function (e) {
1810 this.detach();
1811 };
1812 Autocomplete.prototype.mousewheelListener = function (e) {
1813 if (!this.popup.isMouseOver)
1814 this.detach();
1815 };
1816 Autocomplete.prototype.mouseOutListener = function (e) {
1817 if (this.popup.isOpen)
1818 this.$updatePopupPosition();
1819 };
1820 Autocomplete.prototype.goTo = function (where) {
1821 this.popup.goTo(where);
1822 };
1823 Autocomplete.prototype.insertMatch = function (data, options) {
1824 if (!data)
1825 data = this.popup.getData(this.popup.getRow());
1826 if (!data)
1827 return false;
1828 if (data.value === "") // Explicitly given nothing to insert, e.g. "No suggestion state"
1829 return this.detach();
1830 var completions = this.completions;
1831 var result = this.getCompletionProvider().insertMatch(this.editor, data, completions.filterText, options);
1832 if (this.completions == completions)
1833 this.detach();
1834 return result;
1835 };
1836 Autocomplete.prototype.showPopup = function (editor, options) {
1837 if (this.editor)
1838 this.detach();
1839 this.activated = true;
1840 this.editor = editor;
1841 if (editor.completer != this) {
1842 if (editor.completer)
1843 editor.completer.detach();
1844 editor.completer = this;
1845 }
1846 editor.on("changeSelection", this.changeListener);
1847 editor.on("blur", this.blurListener);
1848 editor.on("mousedown", this.mousedownListener);
1849 editor.on("mousewheel", this.mousewheelListener);
1850 this.updateCompletions(false, options);
1851 };
1852 Autocomplete.prototype.getCompletionProvider = function (initialPosition) {
1853 if (!this.completionProvider)
1854 this.completionProvider = new CompletionProvider(initialPosition);
1855 return this.completionProvider;
1856 };
1857 Autocomplete.prototype.gatherCompletions = function (editor, callback) {
1858 return this.getCompletionProvider().gatherCompletions(editor, callback);
1859 };
1860 Autocomplete.prototype.updateCompletions = function (keepPopupPosition, options) {
1861 if (keepPopupPosition && this.base && this.completions) {
1862 var pos = this.editor.getCursorPosition();
1863 var prefix = this.editor.session.getTextRange({ start: this.base, end: pos });
1864 if (prefix == this.completions.filterText)
1865 return;
1866 this.completions.setFilter(prefix);
1867 if (!this.completions.filtered.length)
1868 return this.detach();
1869 if (this.completions.filtered.length == 1
1870 && this.completions.filtered[0].value == prefix
1871 && !this.completions.filtered[0].snippet)
1872 return this.detach();
1873 this.openPopup(this.editor, prefix, keepPopupPosition);
1874 return;
1875 }
1876 if (options && options.matches) {
1877 var pos = this.editor.getSelectionRange().start;
1878 this.base = this.editor.session.doc.createAnchor(pos.row, pos.column);
1879 this.base.$insertRight = true;
1880 this.completions = new FilteredList(options.matches);
1881 this.getCompletionProvider().completions = this.completions;
1882 return this.openPopup(this.editor, "", keepPopupPosition);
1883 }
1884 var session = this.editor.getSession();
1885 var pos = this.editor.getCursorPosition();
1886 var prefix = util.getCompletionPrefix(this.editor);
1887 this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
1888 this.base.$insertRight = true;
1889 var completionOptions = {
1890 exactMatch: this.exactMatch,
1891 ignoreCaption: this.ignoreCaption
1892 };
1893 this.getCompletionProvider({
1894 prefix: prefix,
1895 pos: pos
1896 }).provideCompletions(this.editor, completionOptions,
1897 function (err, completions, finished) {
1898 var filtered = completions.filtered;
1899 var prefix = util.getCompletionPrefix(this.editor);
1900 this.$firstOpenTimer.cancel();
1901 if (finished) {
1902 if (!filtered.length) {
1903 var emptyMessage = !this.autoShown && this.emptyMessage;
1904 if (typeof emptyMessage == "function")
1905 emptyMessage = this.emptyMessage(prefix);
1906 if (emptyMessage) {
1907 var completionsForEmpty = [{
1908 caption: emptyMessage,
1909 value: ""
1910 }
1911 ];
1912 this.completions = new FilteredList(completionsForEmpty);
1913 this.openPopup(this.editor, prefix, keepPopupPosition);
1914 this.popup.renderer.setStyle("ace_loading", false);
1915 return;
1916 }
1917 return this.detach();
1918 }
1919 if (filtered.length == 1 && filtered[0].value == prefix
1920 && !filtered[0].snippet)
1921 return this.detach();
1922 if (this.autoInsert && !this.autoShown && filtered.length == 1)
1923 return this.insertMatch(filtered[0]);
1924 }
1925 this.completions = !finished && this.showLoadingState ?
1926 new FilteredList(Autocomplete.completionsForLoading.concat(filtered), completions.filterText) :
1927 completions;
1928 this.openPopup(this.editor, prefix, keepPopupPosition);
1929 this.popup.renderer.setStyle("ace_loading", !finished);
1930 }.bind(this));
1931 if (this.showLoadingState && !this.autoShown && !(this.popup && this.popup.isOpen)) {
1932 this.$firstOpenTimer.delay(this.stickySelectionDelay / 2);
1933 }
1934 };
1935 Autocomplete.prototype.cancelContextMenu = function () {
1936 this.editor.$mouseHandler.cancelContextMenu();
1937 };
1938 Autocomplete.prototype.updateDocTooltip = function () {
1939 var popup = this.popup;
1940 var all = this.completions.filtered;
1941 var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]);
1942 var doc = null;
1943 if (!selected || !this.editor || !this.popup.isOpen)
1944 return this.hideDocTooltip();
1945 var completersLength = this.editor.completers.length;
1946 for (var i = 0; i < completersLength; i++) {
1947 var completer = this.editor.completers[i];
1948 if (completer.getDocTooltip && selected.completerId === completer.id) {
1949 doc = completer.getDocTooltip(selected);
1950 break;
1951 }
1952 }
1953 if (!doc && typeof selected != "string")
1954 doc = selected;
1955 if (typeof doc == "string")
1956 doc = { docText: doc };
1957 if (!doc || !(doc.docHTML || doc.docText))
1958 return this.hideDocTooltip();
1959 this.showDocTooltip(doc);
1960 };
1961 Autocomplete.prototype.showDocTooltip = function (item) {
1962 if (!this.tooltipNode) {
1963 this.tooltipNode = dom.createElement("div");
1964 this.tooltipNode.style.margin = "0";
1965 this.tooltipNode.style.pointerEvents = "auto";
1966 this.tooltipNode.style.overscrollBehavior = "contain";
1967 this.tooltipNode.tabIndex = -1;
1968 this.tooltipNode.onblur = this.blurListener.bind(this);
1969 this.tooltipNode.onclick = this.onTooltipClick.bind(this);
1970 this.tooltipNode.id = "doc-tooltip";
1971 this.tooltipNode.setAttribute("role", "tooltip");
1972 this.tooltipNode.addEventListener("wheel", preventParentScroll);
1973 }
1974 var theme = this.editor.renderer.theme;
1975 this.tooltipNode.className = "ace_tooltip ace_doc-tooltip " +
1976 (theme.isDark ? "ace_dark " : "") + (theme.cssClass || "");
1977 var tooltipNode = this.tooltipNode;
1978 if (item.docHTML) {
1979 tooltipNode.innerHTML = item.docHTML;
1980 }
1981 else if (item.docText) {
1982 tooltipNode.textContent = item.docText;
1983 }
1984 if (!tooltipNode.parentNode)
1985 this.popup.container.appendChild(this.tooltipNode);
1986 var popup = this.popup;
1987 var rect = popup.container.getBoundingClientRect();
1988 tooltipNode.style.top = popup.container.style.top;
1989 tooltipNode.style.bottom = popup.container.style.bottom;
1990 tooltipNode.style.display = "block";
1991 if (window.innerWidth - rect.right < 320) {
1992 if (rect.left < 320) {
1993 if (popup.isTopdown) {
1994 tooltipNode.style.top = rect.bottom + "px";
1995 tooltipNode.style.left = rect.left + "px";
1996 tooltipNode.style.right = "";
1997 tooltipNode.style.bottom = "";
1998 }
1999 else {
2000 tooltipNode.style.top = popup.container.offsetTop - tooltipNode.offsetHeight + "px";
2001 tooltipNode.style.left = rect.left + "px";
2002 tooltipNode.style.right = "";
2003 tooltipNode.style.bottom = "";
2004 }
2005 }
2006 else {
2007 tooltipNode.style.right = window.innerWidth - rect.left + "px";
2008 tooltipNode.style.left = "";
2009 }
2010 }
2011 else {
2012 tooltipNode.style.left = (rect.right + 1) + "px";
2013 tooltipNode.style.right = "";
2014 }
2015 };
2016 Autocomplete.prototype.hideDocTooltip = function () {
2017 this.tooltipTimer.cancel();
2018 if (!this.tooltipNode)
2019 return;
2020 var el = this.tooltipNode;
2021 if (!this.editor.isFocused() && document.activeElement == el)
2022 this.editor.focus();
2023 this.tooltipNode = null;
2024 if (el.parentNode)
2025 el.parentNode.removeChild(el);
2026 };
2027 Autocomplete.prototype.onTooltipClick = function (e) {
2028 var a = e.target;
2029 while (a && a != this.tooltipNode) {
2030 if (a.nodeName == "A" && a.href) {
2031 a.rel = "noreferrer";
2032 a.target = "_blank";
2033 break;
2034 }
2035 a = a.parentNode;
2036 }
2037 };
2038 Autocomplete.prototype.destroy = function () {
2039 this.detach();
2040 if (this.popup) {
2041 this.popup.destroy();
2042 var el = this.popup.container;
2043 if (el && el.parentNode)
2044 el.parentNode.removeChild(el);
2045 }
2046 if (this.editor && this.editor.completer == this) {
2047 this.editor.off("destroy", destroyCompleter);
2048 this.editor.completer = null;
2049 }
2050 this.inlineRenderer = this.popup = this.editor = null;
2051 };
2052 return Autocomplete;
2053 }());
2054 Autocomplete.prototype.commands = {
2055 "Up": function (editor) { editor.completer.goTo("up"); },
2056 "Down": function (editor) { editor.completer.goTo("down"); },
2057 "Ctrl-Up|Ctrl-Home": function (editor) { editor.completer.goTo("start"); },
2058 "Ctrl-Down|Ctrl-End": function (editor) { editor.completer.goTo("end"); },
2059 "Esc": function (editor) { editor.completer.detach(); },
2060 "Return": function (editor) { return editor.completer.insertMatch(); },
2061 "Shift-Return": function (editor) { editor.completer.insertMatch(null, { deleteSuffix: true }); },
2062 "Tab": function (editor) {
2063 var result = editor.completer.insertMatch();
2064 if (!result && !editor.tabstopManager)
2065 editor.completer.goTo("down");
2066 else
2067 return result;
2068 },
2069 "PageUp": function (editor) { editor.completer.popup.gotoPageUp(); },
2070 "PageDown": function (editor) { editor.completer.popup.gotoPageDown(); }
2071 };
2072 Autocomplete.for = function (editor) {
2073 if (editor.completer instanceof Autocomplete) {
2074 return editor.completer;
2075 }
2076 if (editor.completer) {
2077 editor.completer.destroy();
2078 editor.completer = null;
2079 }
2080 if (config.get("sharedPopups")) {
2081 if (!Autocomplete["$sharedInstance"])
2082 Autocomplete["$sharedInstance"] = new Autocomplete();
2083 editor.completer = Autocomplete["$sharedInstance"];
2084 }
2085 else {
2086 editor.completer = new Autocomplete();
2087 editor.once("destroy", destroyCompleter);
2088 }
2089 return editor.completer;
2090 };
2091 Autocomplete.startCommand = {
2092 name: "startAutocomplete",
2093 exec: function (editor, options) {
2094 var completer = Autocomplete.for(editor);
2095 completer.autoInsert = false;
2096 completer.autoSelect = true;
2097 completer.autoShown = false;
2098 completer.showPopup(editor, options);
2099 completer.cancelContextMenu();
2100 },
2101 bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
2102 };
2103 var CompletionProvider = /** @class */ (function () {
2104 function CompletionProvider(initialPosition) {
2105 this.initialPosition = initialPosition;
2106 this.active = true;
2107 }
2108 CompletionProvider.prototype.insertByIndex = function (editor, index, options) {
2109 if (!this.completions || !this.completions.filtered) {
2110 return false;
2111 }
2112 return this.insertMatch(editor, this.completions.filtered[index], options);
2113 };
2114 CompletionProvider.prototype.insertMatch = function (editor, data, options) {
2115 if (!data)
2116 return false;
2117 editor.startOperation({ command: { name: "insertMatch" } });
2118 if (data.completer && data.completer.insertMatch) {
2119 data.completer.insertMatch(editor, data);
2120 }
2121 else {
2122 if (!this.completions)
2123 return false;
2124 var replaceBefore = this.completions.filterText.length;
2125 var replaceAfter = 0;
2126 if (data.range && data.range.start.row === data.range.end.row) {
2127 replaceBefore -= this.initialPosition.prefix.length;
2128 replaceBefore += this.initialPosition.pos.column - data.range.start.column;
2129 replaceAfter += data.range.end.column - this.initialPosition.pos.column;
2130 }
2131 if (replaceBefore || replaceAfter) {
2132 var ranges;
2133 if (editor.selection.getAllRanges) {
2134 ranges = editor.selection.getAllRanges();
2135 }
2136 else {
2137 ranges = [editor.getSelectionRange()];
2138 }
2139 for (var i = 0, range; range = ranges[i]; i++) {
2140 range.start.column -= replaceBefore;
2141 range.end.column += replaceAfter;
2142 editor.session.remove(range);
2143 }
2144 }
2145 if (data.snippet) {
2146 snippetManager.insertSnippet(editor, data.snippet);
2147 }
2148 else {
2149 this.$insertString(editor, data);
2150 }
2151 if (data.completer && data.completer.onInsert && typeof data.completer.onInsert == "function") {
2152 data.completer.onInsert(editor, data);
2153 }
2154 if (data.command && data.command === "startAutocomplete") {
2155 editor.execCommand(data.command);
2156 }
2157 }
2158 editor.endOperation();
2159 return true;
2160 };
2161 CompletionProvider.prototype.$insertString = function (editor, data) {
2162 var text = data.value || data;
2163 editor.execCommand("insertstring", text);
2164 };
2165 CompletionProvider.prototype.gatherCompletions = function (editor, callback) {
2166 var session = editor.getSession();
2167 var pos = editor.getCursorPosition();
2168 var prefix = util.getCompletionPrefix(editor);
2169 var matches = [];
2170 this.completers = editor.completers;
2171 var total = editor.completers.length;
2172 editor.completers.forEach(function (completer, i) {
2173 completer.getCompletions(editor, session, pos, prefix, function (err, results) {
2174 if (completer.hideInlinePreview)
2175 results = results.map(function (result) {
2176 return Object.assign(result, { hideInlinePreview: completer.hideInlinePreview });
2177 });
2178 if (!err && results)
2179 matches = matches.concat(results);
2180 callback(null, {
2181 prefix: util.getCompletionPrefix(editor),
2182 matches: matches,
2183 finished: (--total === 0)
2184 });
2185 });
2186 });
2187 return true;
2188 };
2189 CompletionProvider.prototype.provideCompletions = function (editor, options, callback) {
2190 var processResults = function (results) {
2191 var prefix = results.prefix;
2192 var matches = results.matches;
2193 this.completions = new FilteredList(matches);
2194 if (options.exactMatch)
2195 this.completions.exactMatch = true;
2196 if (options.ignoreCaption)
2197 this.completions.ignoreCaption = true;
2198 this.completions.setFilter(prefix);
2199 if (results.finished || this.completions.filtered.length)
2200 callback(null, this.completions, results.finished);
2201 }.bind(this);
2202 var isImmediate = true;
2203 var immediateResults = null;
2204 this.gatherCompletions(editor, function (err, results) {
2205 if (!this.active) {
2206 return;
2207 }
2208 if (err) {
2209 callback(err, [], true);
2210 this.detach();
2211 }
2212 var prefix = results.prefix;
2213 if (prefix.indexOf(results.prefix) !== 0)
2214 return;
2215 if (isImmediate) {
2216 immediateResults = results;
2217 return;
2218 }
2219 processResults(results);
2220 }.bind(this));
2221 isImmediate = false;
2222 if (immediateResults) {
2223 var results = immediateResults;
2224 immediateResults = null;
2225 processResults(results);
2226 }
2227 };
2228 CompletionProvider.prototype.detach = function () {
2229 this.active = false;
2230 this.completers && this.completers.forEach(function (completer) {
2231 if (typeof completer.cancel === "function") {
2232 completer.cancel();
2233 }
2234 });
2235 };
2236 return CompletionProvider;
2237 }());
2238 var FilteredList = /** @class */ (function () {
2239 function FilteredList(array, filterText) {
2240 this.all = array;
2241 this.filtered = array;
2242 this.filterText = filterText || "";
2243 this.exactMatch = false;
2244 this.ignoreCaption = false;
2245 }
2246 FilteredList.prototype.setFilter = function (str) {
2247 if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
2248 var matches = this.filtered;
2249 else
2250 var matches = this.all;
2251 this.filterText = str;
2252 matches = this.filterCompletions(matches, this.filterText);
2253 matches = matches.sort(function (a, b) {
2254 return b.exactMatch - a.exactMatch || b.$score - a.$score
2255 || (a.caption || a.value).localeCompare(b.caption || b.value);
2256 });
2257 var prev = null;
2258 matches = matches.filter(function (item) {
2259 var caption = item.snippet || item.caption || item.value;
2260 if (caption === prev)
2261 return false;
2262 prev = caption;
2263 return true;
2264 });
2265 this.filtered = matches;
2266 };
2267 FilteredList.prototype.filterCompletions = function (items, needle) {
2268 var results = [];
2269 var upper = needle.toUpperCase();
2270 var lower = needle.toLowerCase();
2271 loop: for (var i = 0, item; item = items[i]; i++) {
2272 var caption = (!this.ignoreCaption && item.caption) || item.value || item.snippet;
2273 if (!caption)
2274 continue;
2275 var lastIndex = -1;
2276 var matchMask = 0;
2277 var penalty = 0;
2278 var index, distance;
2279 if (this.exactMatch) {
2280 if (needle !== caption.substr(0, needle.length))
2281 continue loop;
2282 }
2283 else {
2284 var fullMatchIndex = caption.toLowerCase().indexOf(lower);
2285 if (fullMatchIndex > -1) {
2286 penalty = fullMatchIndex;
2287 }
2288 else {
2289 for (var j = 0; j < needle.length; j++) {
2290 var i1 = caption.indexOf(lower[j], lastIndex + 1);
2291 var i2 = caption.indexOf(upper[j], lastIndex + 1);
2292 index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
2293 if (index < 0)
2294 continue loop;
2295 distance = index - lastIndex - 1;
2296 if (distance > 0) {
2297 if (lastIndex === -1)
2298 penalty += 10;
2299 penalty += distance;
2300 matchMask = matchMask | (1 << j);
2301 }
2302 lastIndex = index;
2303 }
2304 }
2305 }
2306 item.matchMask = matchMask;
2307 item.exactMatch = penalty ? 0 : 1;
2308 item.$score = (item.score || 0) - penalty;
2309 results.push(item);
2310 }
2311 return results;
2312 };
2313 return FilteredList;
2314 }());
2315 exports.Autocomplete = Autocomplete;
2316 exports.CompletionProvider = CompletionProvider;
2317 exports.FilteredList = FilteredList;
2318
2319 });
2320
2321 ace.define("ace/ext/command_bar",["require","exports","module","ace/tooltip","ace/lib/event_emitter","ace/lib/lang","ace/lib/dom","ace/lib/oop","ace/lib/useragent"], function(require, exports, module){var __values = (this && this.__values) || function(o) {
2322 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
2323 if (m) return m.call(o);
2324 if (o && typeof o.length === "number") return {
2325 next: function () {
2326 if (o && i >= o.length) o = void 0;
2327 return { value: o && o[i++], done: !o };
2328 }
2329 };
2330 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
2331 };
2332 var Tooltip = require("../tooltip").Tooltip;
2333 var EventEmitter = require("../lib/event_emitter").EventEmitter;
2334 var lang = require("../lib/lang");
2335 var dom = require("../lib/dom");
2336 var oop = require("../lib/oop");
2337 var useragent = require("../lib/useragent");
2338 var BUTTON_CLASS_NAME = 'command_bar_tooltip_button';
2339 var VALUE_CLASS_NAME = 'command_bar_button_value';
2340 var CAPTION_CLASS_NAME = 'command_bar_button_caption';
2341 var KEYBINDING_CLASS_NAME = 'command_bar_keybinding';
2342 var TOOLTIP_CLASS_NAME = 'command_bar_tooltip';
2343 var MORE_OPTIONS_BUTTON_ID = 'MoreOptionsButton';
2344 var defaultDelay = 100;
2345 var defaultMaxElements = 4;
2346 var minPosition = function (posA, posB) {
2347 if (posB.row > posA.row) {
2348 return posA;
2349 }
2350 else if (posB.row === posA.row && posB.column > posA.column) {
2351 return posA;
2352 }
2353 return posB;
2354 };
2355 var keyDisplayMap = {
2356 "Ctrl": { mac: "^" },
2357 "Option": { mac: "⌥" },
2358 "Command": { mac: "⌘" },
2359 "Cmd": { mac: "⌘" },
2360 "Shift": "⇧",
2361 "Left": "←",
2362 "Right": "→",
2363 "Up": "↑",
2364 "Down": "↓"
2365 };
2366 var CommandBarTooltip = /** @class */ (function () {
2367 function CommandBarTooltip(parentNode, options) {
2368 var e_1, _a;
2369 options = options || {};
2370 this.parentNode = parentNode;
2371 this.tooltip = new Tooltip(this.parentNode);
2372 this.moreOptions = new Tooltip(this.parentNode);
2373 this.maxElementsOnTooltip = options.maxElementsOnTooltip || defaultMaxElements;
2374 this.$alwaysShow = options.alwaysShow || false;
2375 this.eventListeners = {};
2376 this.elements = {};
2377 this.commands = {};
2378 this.tooltipEl = dom.buildDom(['div', { class: TOOLTIP_CLASS_NAME }], this.tooltip.getElement());
2379 this.moreOptionsEl = dom.buildDom(['div', { class: TOOLTIP_CLASS_NAME + " tooltip_more_options" }], this.moreOptions.getElement());
2380 this.$showTooltipTimer = lang.delayedCall(this.$showTooltip.bind(this), options.showDelay || defaultDelay);
2381 this.$hideTooltipTimer = lang.delayedCall(this.$hideTooltip.bind(this), options.hideDelay || defaultDelay);
2382 this.$tooltipEnter = this.$tooltipEnter.bind(this);
2383 this.$onMouseMove = this.$onMouseMove.bind(this);
2384 this.$onChangeScroll = this.$onChangeScroll.bind(this);
2385 this.$onEditorChangeSession = this.$onEditorChangeSession.bind(this);
2386 this.$scheduleTooltipForHide = this.$scheduleTooltipForHide.bind(this);
2387 this.$preventMouseEvent = this.$preventMouseEvent.bind(this);
2388 try {
2389 for (var _b = __values(["mousedown", "mouseup", "click"]), _c = _b.next(); !_c.done; _c = _b.next()) {
2390 var event = _c.value;
2391 this.tooltip.getElement().addEventListener(event, this.$preventMouseEvent);
2392 this.moreOptions.getElement().addEventListener(event, this.$preventMouseEvent);
2393 }
2394 }
2395 catch (e_1_1) { e_1 = { error: e_1_1 }; }
2396 finally {
2397 try {
2398 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2399 }
2400 finally { if (e_1) throw e_1.error; }
2401 }
2402 }
2403 CommandBarTooltip.prototype.registerCommand = function (id, command) {
2404 var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip;
2405 if (!registerForMainTooltip && !this.elements[MORE_OPTIONS_BUTTON_ID]) {
2406 this.$createCommand(MORE_OPTIONS_BUTTON_ID, {
2407 name: "···",
2408 exec:
2409 function () {
2410 this.$shouldHideMoreOptions = false;
2411 this.$setMoreOptionsVisibility(!this.isMoreOptionsShown());
2412 }.bind(this),
2413 type: "checkbox",
2414 getValue: function () {
2415 return this.isMoreOptionsShown();
2416 }.bind(this),
2417 enabled: true
2418 }, true);
2419 }
2420 this.$createCommand(id, command, registerForMainTooltip);
2421 if (this.isShown()) {
2422 this.updatePosition();
2423 }
2424 };
2425 CommandBarTooltip.prototype.isShown = function () {
2426 return !!this.tooltip && this.tooltip.isOpen;
2427 };
2428 CommandBarTooltip.prototype.isMoreOptionsShown = function () {
2429 return !!this.moreOptions && this.moreOptions.isOpen;
2430 };
2431 CommandBarTooltip.prototype.getAlwaysShow = function () {
2432 return this.$alwaysShow;
2433 };
2434 CommandBarTooltip.prototype.setAlwaysShow = function (alwaysShow) {
2435 this.$alwaysShow = alwaysShow;
2436 this.$updateOnHoverHandlers(!this.$alwaysShow);
2437 this._signal("alwaysShow", this.$alwaysShow);
2438 };
2439 CommandBarTooltip.prototype.attach = function (editor) {
2440 if (!editor || (this.isShown() && this.editor === editor)) {
2441 return;
2442 }
2443 this.detach();
2444 this.editor = editor;
2445 this.editor.on("changeSession", this.$onEditorChangeSession);
2446 if (this.editor.session) {
2447 this.editor.session.on("changeScrollLeft", this.$onChangeScroll);
2448 this.editor.session.on("changeScrollTop", this.$onChangeScroll);
2449 }
2450 if (this.getAlwaysShow()) {
2451 this.$showTooltip();
2452 }
2453 else {
2454 this.$updateOnHoverHandlers(true);
2455 }
2456 };
2457 CommandBarTooltip.prototype.updatePosition = function () {
2458 if (!this.editor) {
2459 return;
2460 }
2461 var renderer = this.editor.renderer;
2462 var ranges;
2463 if (this.editor.selection.getAllRanges) {
2464 ranges = this.editor.selection.getAllRanges();
2465 }
2466 else {
2467 ranges = [this.editor.getSelectionRange()];
2468 }
2469 if (!ranges.length) {
2470 return;
2471 }
2472 var minPos = minPosition(ranges[0].start, ranges[0].end);
2473 for (var i = 0, range; range = ranges[i]; i++) {
2474 minPos = minPosition(minPos, minPosition(range.start, range.end));
2475 }
2476 var pos = renderer.$cursorLayer.getPixelPosition(minPos, true);
2477 var tooltipEl = this.tooltip.getElement();
2478 var screenWidth = window.innerWidth;
2479 var screenHeight = window.innerHeight;
2480 var rect = this.editor.container.getBoundingClientRect();
2481 pos.top += rect.top - renderer.layerConfig.offset;
2482 pos.left += rect.left + renderer.gutterWidth - renderer.scrollLeft;
2483 var cursorVisible = pos.top >= rect.top && pos.top <= rect.bottom &&
2484 pos.left >= rect.left + renderer.gutterWidth && pos.left <= rect.right;
2485 if (!cursorVisible && this.isShown()) {
2486 this.$hideTooltip();
2487 return;
2488 }
2489 else if (cursorVisible && !this.isShown() && this.getAlwaysShow()) {
2490 this.$showTooltip();
2491 return;
2492 }
2493 var top = pos.top - tooltipEl.offsetHeight;
2494 var left = Math.min(screenWidth - tooltipEl.offsetWidth, pos.left);
2495 var tooltipFits = top >= 0 && top + tooltipEl.offsetHeight <= screenHeight &&
2496 left >= 0 && left + tooltipEl.offsetWidth <= screenWidth;
2497 if (!tooltipFits) {
2498 this.$hideTooltip();
2499 return;
2500 }
2501 this.tooltip.setPosition(left, top);
2502 if (this.isMoreOptionsShown()) {
2503 top = top + tooltipEl.offsetHeight;
2504 left = this.elements[MORE_OPTIONS_BUTTON_ID].getBoundingClientRect().left;
2505 var moreOptionsEl = this.moreOptions.getElement();
2506 var screenHeight = window.innerHeight;
2507 if (top + moreOptionsEl.offsetHeight > screenHeight) {
2508 top -= tooltipEl.offsetHeight + moreOptionsEl.offsetHeight;
2509 }
2510 if (left + moreOptionsEl.offsetWidth > screenWidth) {
2511 left = screenWidth - moreOptionsEl.offsetWidth;
2512 }
2513 this.moreOptions.setPosition(left, top);
2514 }
2515 };
2516 CommandBarTooltip.prototype.update = function () {
2517 Object.keys(this.elements).forEach(this.$updateElement.bind(this));
2518 };
2519 CommandBarTooltip.prototype.detach = function () {
2520 this.tooltip.hide();
2521 this.moreOptions.hide();
2522 this.$updateOnHoverHandlers(false);
2523 if (this.editor) {
2524 this.editor.off("changeSession", this.$onEditorChangeSession);
2525 if (this.editor.session) {
2526 this.editor.session.off("changeScrollLeft", this.$onChangeScroll);
2527 this.editor.session.off("changeScrollTop", this.$onChangeScroll);
2528 }
2529 }
2530 this.$mouseInTooltip = false;
2531 this.editor = null;
2532 };
2533 CommandBarTooltip.prototype.destroy = function () {
2534 if (this.tooltip && this.moreOptions) {
2535 this.detach();
2536 this.tooltip.destroy();
2537 this.moreOptions.destroy();
2538 }
2539 this.eventListeners = {};
2540 this.commands = {};
2541 this.elements = {};
2542 this.tooltip = this.moreOptions = this.parentNode = null;
2543 };
2544 CommandBarTooltip.prototype.$createCommand = function (id, command, forMainTooltip) {
2545 var parentEl = forMainTooltip ? this.tooltipEl : this.moreOptionsEl;
2546 var keyParts = [];
2547 var bindKey = command.bindKey;
2548 if (bindKey) {
2549 if (typeof bindKey === 'object') {
2550 bindKey = useragent.isMac ? bindKey.mac : bindKey.win;
2551 }
2552 bindKey = bindKey.split("|")[0];
2553 keyParts = bindKey.split("-");
2554 keyParts = keyParts.map(function (key) {
2555 if (keyDisplayMap[key]) {
2556 if (typeof keyDisplayMap[key] === 'string') {
2557 return keyDisplayMap[key];
2558 }
2559 else if (useragent.isMac && keyDisplayMap[key].mac) {
2560 return keyDisplayMap[key].mac;
2561 }
2562 }
2563 return key;
2564 });
2565 }
2566 var buttonNode;
2567 if (forMainTooltip && command.iconCssClass) {
2568 buttonNode = [
2569 'div',
2570 {
2571 class: ["ace_icon_svg", command.iconCssClass].join(" "),
2572 "aria-label": command.name + " (" + command.bindKey + ")"
2573 }
2574 ];
2575 }
2576 else {
2577 buttonNode = [
2578 ['div', { class: VALUE_CLASS_NAME }],
2579 ['div', { class: CAPTION_CLASS_NAME }, command.name]
2580 ];
2581 if (keyParts.length) {
2582 buttonNode.push([
2583 'div',
2584 { class: KEYBINDING_CLASS_NAME },
2585 keyParts.map(function (keyPart) {
2586 return ['div', keyPart];
2587 })
2588 ]);
2589 }
2590 }
2591 dom.buildDom(['div', { class: [BUTTON_CLASS_NAME, command.cssClass || ""].join(" "), ref: id }, buttonNode], parentEl, this.elements);
2592 this.commands[id] = command;
2593 var eventListener =
2594 function (e) {
2595 if (this.editor) {
2596 this.editor.focus();
2597 }
2598 this.$shouldHideMoreOptions = this.isMoreOptionsShown();
2599 if (!this.elements[id].disabled && command.exec) {
2600 command.exec(this.editor);
2601 }
2602 if (this.$shouldHideMoreOptions) {
2603 this.$setMoreOptionsVisibility(false);
2604 }
2605 this.update();
2606 e.preventDefault();
2607 }.bind(this);
2608 this.eventListeners[id] = eventListener;
2609 this.elements[id].addEventListener('click', eventListener.bind(this));
2610 this.$updateElement(id);
2611 };
2612 CommandBarTooltip.prototype.$setMoreOptionsVisibility = function (visible) {
2613 if (visible) {
2614 this.moreOptions.setTheme(this.editor.renderer.theme);
2615 this.moreOptions.setClassName(TOOLTIP_CLASS_NAME + "_wrapper");
2616 this.moreOptions.show();
2617 this.update();
2618 this.updatePosition();
2619 }
2620 else {
2621 this.moreOptions.hide();
2622 }
2623 };
2624 CommandBarTooltip.prototype.$onEditorChangeSession = function (e) {
2625 if (e.oldSession) {
2626 e.oldSession.off("changeScrollTop", this.$onChangeScroll);
2627 e.oldSession.off("changeScrollLeft", this.$onChangeScroll);
2628 }
2629 this.detach();
2630 };
2631 CommandBarTooltip.prototype.$onChangeScroll = function () {
2632 if (this.editor.renderer && (this.isShown() || this.getAlwaysShow())) {
2633 this.editor.renderer.once("afterRender", this.updatePosition.bind(this));
2634 }
2635 };
2636 CommandBarTooltip.prototype.$onMouseMove = function (e) {
2637 if (this.$mouseInTooltip) {
2638 return;
2639 }
2640 var cursorPosition = this.editor.getCursorPosition();
2641 var cursorScreenPosition = this.editor.renderer.textToScreenCoordinates(cursorPosition.row, cursorPosition.column);
2642 var lineHeight = this.editor.renderer.lineHeight;
2643 var isInCurrentLine = e.clientY >= cursorScreenPosition.pageY && e.clientY < cursorScreenPosition.pageY + lineHeight;
2644 if (isInCurrentLine) {
2645 if (!this.isShown() && !this.$showTooltipTimer.isPending()) {
2646 this.$showTooltipTimer.delay();
2647 }
2648 if (this.$hideTooltipTimer.isPending()) {
2649 this.$hideTooltipTimer.cancel();
2650 }
2651 }
2652 else {
2653 if (this.isShown() && !this.$hideTooltipTimer.isPending()) {
2654 this.$hideTooltipTimer.delay();
2655 }
2656 if (this.$showTooltipTimer.isPending()) {
2657 this.$showTooltipTimer.cancel();
2658 }
2659 }
2660 };
2661 CommandBarTooltip.prototype.$preventMouseEvent = function (e) {
2662 if (this.editor) {
2663 this.editor.focus();
2664 }
2665 e.preventDefault();
2666 };
2667 CommandBarTooltip.prototype.$scheduleTooltipForHide = function () {
2668 this.$mouseInTooltip = false;
2669 this.$showTooltipTimer.cancel();
2670 this.$hideTooltipTimer.delay();
2671 };
2672 CommandBarTooltip.prototype.$tooltipEnter = function () {
2673 this.$mouseInTooltip = true;
2674 if (this.$showTooltipTimer.isPending()) {
2675 this.$showTooltipTimer.cancel();
2676 }
2677 if (this.$hideTooltipTimer.isPending()) {
2678 this.$hideTooltipTimer.cancel();
2679 }
2680 };
2681 CommandBarTooltip.prototype.$updateOnHoverHandlers = function (enableHover) {
2682 var tooltipEl = this.tooltip.getElement();
2683 var moreOptionsEl = this.moreOptions.getElement();
2684 if (enableHover) {
2685 if (this.editor) {
2686 this.editor.on("mousemove", this.$onMouseMove);
2687 this.editor.renderer.getMouseEventTarget().addEventListener("mouseout", this.$scheduleTooltipForHide, true);
2688 }
2689 tooltipEl.addEventListener('mouseenter', this.$tooltipEnter);
2690 tooltipEl.addEventListener('mouseleave', this.$scheduleTooltipForHide);
2691 moreOptionsEl.addEventListener('mouseenter', this.$tooltipEnter);
2692 moreOptionsEl.addEventListener('mouseleave', this.$scheduleTooltipForHide);
2693 }
2694 else {
2695 if (this.editor) {
2696 this.editor.off("mousemove", this.$onMouseMove);
2697 this.editor.renderer.getMouseEventTarget().removeEventListener("mouseout", this.$scheduleTooltipForHide, true);
2698 }
2699 tooltipEl.removeEventListener('mouseenter', this.$tooltipEnter);
2700 tooltipEl.removeEventListener('mouseleave', this.$scheduleTooltipForHide);
2701 moreOptionsEl.removeEventListener('mouseenter', this.$tooltipEnter);
2702 moreOptionsEl.removeEventListener('mouseleave', this.$scheduleTooltipForHide);
2703 }
2704 };
2705 CommandBarTooltip.prototype.$showTooltip = function () {
2706 if (this.isShown()) {
2707 return;
2708 }
2709 this.tooltip.setTheme(this.editor.renderer.theme);
2710 this.tooltip.setClassName(TOOLTIP_CLASS_NAME + "_wrapper");
2711 this.tooltip.show();
2712 this.update();
2713 this.updatePosition();
2714 this._signal("show");
2715 };
2716 CommandBarTooltip.prototype.$hideTooltip = function () {
2717 this.$mouseInTooltip = false;
2718 if (!this.isShown()) {
2719 return;
2720 }
2721 this.moreOptions.hide();
2722 this.tooltip.hide();
2723 this._signal("hide");
2724 };
2725 CommandBarTooltip.prototype.$updateElement = function (id) {
2726 var command = this.commands[id];
2727 if (!command) {
2728 return;
2729 }
2730 var el = this.elements[id];
2731 var commandEnabled = command.enabled;
2732 if (typeof commandEnabled === 'function') {
2733 commandEnabled = commandEnabled(this.editor);
2734 }
2735 if (typeof command.getValue === 'function') {
2736 var value = command.getValue(this.editor);
2737 if (command.type === 'text') {
2738 el.textContent = value;
2739 }
2740 else if (command.type === 'checkbox') {
2741 var domCssFn = value ? dom.addCssClass : dom.removeCssClass;
2742 var isOnTooltip = el.parentElement === this.tooltipEl;
2743 el.ariaChecked = value;
2744 if (isOnTooltip) {
2745 domCssFn(el, "ace_selected");
2746 }
2747 else {
2748 el = el.querySelector("." + VALUE_CLASS_NAME);
2749 domCssFn(el, "ace_checkmark");
2750 }
2751 }
2752 }
2753 if (commandEnabled && el.disabled) {
2754 dom.removeCssClass(el, "ace_disabled");
2755 el.ariaDisabled = el.disabled = false;
2756 el.removeAttribute("disabled");
2757 }
2758 else if (!commandEnabled && !el.disabled) {
2759 dom.addCssClass(el, "ace_disabled");
2760 el.ariaDisabled = el.disabled = true;
2761 el.setAttribute("disabled", "");
2762 }
2763 };
2764 return CommandBarTooltip;
2765 }());
2766 oop.implement(CommandBarTooltip.prototype, EventEmitter);
2767 dom.importCssString("\n.ace_tooltip.".concat(TOOLTIP_CLASS_NAME, "_wrapper {\n padding: 0;\n}\n\n.ace_tooltip .").concat(TOOLTIP_CLASS_NAME, " {\n padding: 1px 5px;\n display: flex;\n pointer-events: auto;\n}\n\n.ace_tooltip .").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options {\n padding: 1px;\n flex-direction: column;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, " {\n display: inline-flex;\n cursor: pointer;\n margin: 1px;\n border-radius: 2px;\n padding: 2px 5px;\n align-items: center;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, ".ace_selected,\ndiv.").concat(BUTTON_CLASS_NAME, ":hover:not(.ace_disabled) {\n background-color: rgba(0, 0, 0, 0.1);\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, ".ace_disabled {\n color: #777;\n pointer-events: none;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, " .ace_icon_svg {\n height: 12px;\n background-color: #000;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, ".ace_disabled .ace_icon_svg {\n background-color: #777;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options .").concat(BUTTON_CLASS_NAME, " {\n display: flex;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".").concat(VALUE_CLASS_NAME, " {\n display: none;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options .").concat(VALUE_CLASS_NAME, " {\n display: inline-block;\n width: 12px;\n}\n\n.").concat(CAPTION_CLASS_NAME, " {\n display: inline-block;\n}\n\n.").concat(KEYBINDING_CLASS_NAME, " {\n margin: 0 2px;\n display: inline-block;\n font-size: 8px;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options .").concat(KEYBINDING_CLASS_NAME, " {\n margin-left: auto;\n}\n\n.").concat(KEYBINDING_CLASS_NAME, " div {\n display: inline-block;\n min-width: 8px;\n padding: 2px;\n margin: 0 1px;\n border-radius: 2px;\n background-color: #ccc;\n text-align: center;\n}\n\n.ace_dark.ace_tooltip .").concat(TOOLTIP_CLASS_NAME, " {\n background-color: #373737;\n color: #eee;\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ".ace_disabled {\n color: #979797;\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ".ace_selected,\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ":hover:not(.ace_disabled) {\n background-color: rgba(255, 255, 255, 0.1);\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, " .ace_icon_svg {\n background-color: #eee;\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ".ace_disabled .ace_icon_svg {\n background-color: #979797;\n}\n\n.ace_dark .").concat(BUTTON_CLASS_NAME, ".ace_disabled {\n color: #979797;\n}\n\n.ace_dark .").concat(KEYBINDING_CLASS_NAME, " div {\n background-color: #575757;\n}\n\n.ace_checkmark::before {\n content: '\u2713';\n}\n"), "commandbar.css", false);
2768 exports.CommandBarTooltip = CommandBarTooltip;
2769 exports.TOOLTIP_CLASS_NAME = TOOLTIP_CLASS_NAME;
2770 exports.BUTTON_CLASS_NAME = BUTTON_CLASS_NAME;
2771
2772 });
2773
2774 ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module){var Range = require("../range").Range;
2775 var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
2776 function getWordIndex(doc, pos) {
2777 var textBefore = doc.getTextRange(Range.fromPoints({
2778 row: 0,
2779 column: 0
2780 }, pos));
2781 return textBefore.split(splitRegex).length - 1;
2782 }
2783 function wordDistance(doc, pos) {
2784 var prefixPos = getWordIndex(doc, pos);
2785 var words = doc.getValue().split(splitRegex);
2786 var wordScores = Object.create(null);
2787 var currentWord = words[prefixPos];
2788 words.forEach(function (word, idx) {
2789 if (!word || word === currentWord)
2790 return;
2791 var distance = Math.abs(prefixPos - idx);
2792 var score = words.length - distance;
2793 if (wordScores[word]) {
2794 wordScores[word] = Math.max(score, wordScores[word]);
2795 }
2796 else {
2797 wordScores[word] = score;
2798 }
2799 });
2800 return wordScores;
2801 }
2802 exports.getCompletions = function (editor, session, pos, prefix, callback) {
2803 var wordScore = wordDistance(session, pos);
2804 var wordList = Object.keys(wordScore);
2805 callback(null, wordList.map(function (word) {
2806 return {
2807 caption: word,
2808 value: word,
2809 score: wordScore[word],
2810 meta: "local"
2811 };
2812 }));
2813 };
2814
2815 });
2816
2817 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(require, exports, module){"use strict";
2818 var snippetManager = require("../snippets").snippetManager;
2819 var Autocomplete = require("../autocomplete").Autocomplete;
2820 var config = require("../config");
2821 var lang = require("../lib/lang");
2822 var util = require("../autocomplete/util");
2823 var textCompleter = require("../autocomplete/text_completer");
2824 var keyWordCompleter = {
2825 getCompletions: function (editor, session, pos, prefix, callback) {
2826 if (session.$mode.completer) {
2827 return session.$mode.completer.getCompletions(editor, session, pos, prefix, callback);
2828 }
2829 var state = editor.session.getState(pos.row);
2830 var completions = session.$mode.getCompletions(state, session, pos, prefix);
2831 completions = completions.map(function (el) {
2832 el.completerId = keyWordCompleter.id;
2833 return el;
2834 });
2835 callback(null, completions);
2836 },
2837 id: "keywordCompleter"
2838 };
2839 var transformSnippetTooltip = function (str) {
2840 var record = {};
2841 return str.replace(/\${(\d+)(:(.*?))?}/g, function (_, p1, p2, p3) {
2842 return (record[p1] = p3 || '');
2843 }).replace(/\$(\d+?)/g, function (_, p1) {
2844 return record[p1];
2845 });
2846 };
2847 var snippetCompleter = {
2848 getCompletions: function (editor, session, pos, prefix, callback) {
2849 var scopes = [];
2850 var token = session.getTokenAt(pos.row, pos.column);
2851 if (token && token.type.match(/(tag-name|tag-open|tag-whitespace|attribute-name|attribute-value)\.xml$/))
2852 scopes.push('html-tag');
2853 else
2854 scopes = snippetManager.getActiveScopes(editor);
2855 var snippetMap = snippetManager.snippetMap;
2856 var completions = [];
2857 scopes.forEach(function (scope) {
2858 var snippets = snippetMap[scope] || [];
2859 for (var i = snippets.length; i--;) {
2860 var s = snippets[i];
2861 var caption = s.name || s.tabTrigger;
2862 if (!caption)
2863 continue;
2864 completions.push({
2865 caption: caption,
2866 snippet: s.content,
2867 meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet",
2868 completerId: snippetCompleter.id
2869 });
2870 }
2871 }, this);
2872 callback(null, completions);
2873 },
2874 getDocTooltip: function (item) {
2875 if (item.snippet && !item.docHTML) {
2876 item.docHTML = [
2877 "<b>", lang.escapeHTML(item.caption), "</b>", "<hr></hr>",
2878 lang.escapeHTML(transformSnippetTooltip(item.snippet))
2879 ].join("");
2880 }
2881 },
2882 id: "snippetCompleter"
2883 };
2884 var completers = [snippetCompleter, textCompleter, keyWordCompleter];
2885 exports.setCompleters = function (val) {
2886 completers.length = 0;
2887 if (val)
2888 completers.push.apply(completers, val);
2889 };
2890 exports.addCompleter = function (completer) {
2891 completers.push(completer);
2892 };
2893 exports.textCompleter = textCompleter;
2894 exports.keyWordCompleter = keyWordCompleter;
2895 exports.snippetCompleter = snippetCompleter;
2896 var expandSnippet = {
2897 name: "expandSnippet",
2898 exec: function (editor) {
2899 return snippetManager.expandWithTab(editor);
2900 },
2901 bindKey: "Tab"
2902 };
2903 var onChangeMode = function (e, editor) {
2904 loadSnippetsForMode(editor.session.$mode);
2905 };
2906 var loadSnippetsForMode = function (mode) {
2907 if (typeof mode == "string")
2908 mode = config.$modes[mode];
2909 if (!mode)
2910 return;
2911 if (!snippetManager.files)
2912 snippetManager.files = {};
2913 loadSnippetFile(mode.$id, mode.snippetFileId);
2914 if (mode.modes)
2915 mode.modes.forEach(loadSnippetsForMode);
2916 };
2917 var loadSnippetFile = function (id, snippetFilePath) {
2918 if (!snippetFilePath || !id || snippetManager.files[id])
2919 return;
2920 snippetManager.files[id] = {};
2921 config.loadModule(snippetFilePath, function (m) {
2922 if (!m)
2923 return;
2924 snippetManager.files[id] = m;
2925 if (!m.snippets && m.snippetText)
2926 m.snippets = snippetManager.parseSnippetFile(m.snippetText);
2927 snippetManager.register(m.snippets || [], m.scope);
2928 if (m.includeScopes) {
2929 snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
2930 m.includeScopes.forEach(function (x) {
2931 loadSnippetsForMode("ace/mode/" + x);
2932 });
2933 }
2934 });
2935 };
2936 var doLiveAutocomplete = function (e) {
2937 var editor = e.editor;
2938 var hasCompleter = editor.completer && editor.completer.activated;
2939 if (e.command.name === "backspace") {
2940 if (hasCompleter && !util.getCompletionPrefix(editor))
2941 editor.completer.detach();
2942 }
2943 else if (e.command.name === "insertstring" && !hasCompleter) {
2944 lastExecEvent = e;
2945 var delay = e.editor.$liveAutocompletionDelay;
2946 if (delay) {
2947 liveAutocompleteTimer.delay(delay);
2948 }
2949 else {
2950 showLiveAutocomplete(e);
2951 }
2952 }
2953 };
2954 var lastExecEvent;
2955 var liveAutocompleteTimer = lang.delayedCall(function () {
2956 showLiveAutocomplete(lastExecEvent);
2957 }, 0);
2958 var showLiveAutocomplete = function (e) {
2959 var editor = e.editor;
2960 var prefix = util.getCompletionPrefix(editor);
2961 var triggerAutocomplete = util.triggerAutocomplete(editor);
2962 if (prefix && prefix.length >= editor.$liveAutocompletionThreshold || triggerAutocomplete) {
2963 var completer = Autocomplete.for(editor);
2964 completer.autoShown = true;
2965 completer.showPopup(editor);
2966 }
2967 };
2968 var Editor = require("../editor").Editor;
2969 require("../config").defineOptions(Editor.prototype, "editor", {
2970 enableBasicAutocompletion: {
2971 set: function (val) {
2972 if (val) {
2973 if (!this.completers)
2974 this.completers = Array.isArray(val) ? val : completers;
2975 this.commands.addCommand(Autocomplete.startCommand);
2976 }
2977 else {
2978 this.commands.removeCommand(Autocomplete.startCommand);
2979 }
2980 },
2981 value: false
2982 },
2983 enableLiveAutocompletion: {
2984 set: function (val) {
2985 if (val) {
2986 if (!this.completers)
2987 this.completers = Array.isArray(val) ? val : completers;
2988 this.commands.on('afterExec', doLiveAutocomplete);
2989 }
2990 else {
2991 this.commands.off('afterExec', doLiveAutocomplete);
2992 }
2993 },
2994 value: false
2995 },
2996 liveAutocompletionDelay: {
2997 initialValue: 0
2998 },
2999 liveAutocompletionThreshold: {
3000 initialValue: 0
3001 },
3002 enableSnippets: {
3003 set: function (val) {
3004 if (val) {
3005 this.commands.addCommand(expandSnippet);
3006 this.on("changeMode", onChangeMode);
3007 onChangeMode(null, this);
3008 }
3009 else {
3010 this.commands.removeCommand(expandSnippet);
3011 this.off("changeMode", onChangeMode);
3012 }
3013 },
3014 value: false
3015 }
3016 });
3017
3018 });
3019
3020 ace.define("ace/ext/inline_autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/inline","ace/autocomplete","ace/autocomplete","ace/editor","ace/autocomplete/util","ace/lib/dom","ace/lib/lang","ace/ext/command_bar","ace/ext/command_bar","ace/ext/language_tools","ace/ext/language_tools","ace/ext/language_tools","ace/config"], function(require, exports, module){"use strict";
3021 var HashHandler = require("../keyboard/hash_handler").HashHandler;
3022 var AceInline = require("../autocomplete/inline").AceInline;
3023 var FilteredList = require("../autocomplete").FilteredList;
3024 var CompletionProvider = require("../autocomplete").CompletionProvider;
3025 var Editor = require("../editor").Editor;
3026 var util = require("../autocomplete/util");
3027 var dom = require("../lib/dom");
3028 var lang = require("../lib/lang");
3029 var CommandBarTooltip = require("./command_bar").CommandBarTooltip;
3030 var BUTTON_CLASS_NAME = require("./command_bar").BUTTON_CLASS_NAME;
3031 var snippetCompleter = require("./language_tools").snippetCompleter;
3032 var textCompleter = require("./language_tools").textCompleter;
3033 var keyWordCompleter = require("./language_tools").keyWordCompleter;
3034 var destroyCompleter = function (e, editor) {
3035 editor.completer && editor.completer.destroy();
3036 };
3037 var InlineAutocomplete = /** @class */ (function () {
3038 function InlineAutocomplete(editor) {
3039 this.editor = editor;
3040 this.keyboardHandler = new HashHandler(this.commands);
3041 this.$index = -1;
3042 this.blurListener = this.blurListener.bind(this);
3043 this.changeListener = this.changeListener.bind(this);
3044 this.changeTimer = lang.delayedCall(function () {
3045 this.updateCompletions();
3046 }.bind(this));
3047 }
3048 InlineAutocomplete.prototype.getInlineRenderer = function () {
3049 if (!this.inlineRenderer)
3050 this.inlineRenderer = new AceInline();
3051 return this.inlineRenderer;
3052 };
3053 InlineAutocomplete.prototype.getInlineTooltip = function () {
3054 if (!this.inlineTooltip) {
3055 this.inlineTooltip = InlineAutocomplete.createInlineTooltip(document.body || document.documentElement);
3056 }
3057 return this.inlineTooltip;
3058 };
3059 InlineAutocomplete.prototype.show = function (options) {
3060 this.activated = true;
3061 if (this.editor.completer !== this) {
3062 if (this.editor.completer)
3063 this.editor.completer.detach();
3064 this.editor.completer = this;
3065 }
3066 this.editor.on("changeSelection", this.changeListener);
3067 this.editor.on("blur", this.blurListener);
3068 this.updateCompletions(options);
3069 };
3070 InlineAutocomplete.prototype.$open = function () {
3071 if (this.editor.textInput.setAriaOptions) {
3072 this.editor.textInput.setAriaOptions({});
3073 }
3074 this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
3075 this.getInlineTooltip().attach(this.editor);
3076 if (this.$index === -1) {
3077 this.setIndex(0);
3078 }
3079 else {
3080 this.$showCompletion();
3081 }
3082 this.changeTimer.cancel();
3083 };
3084 InlineAutocomplete.prototype.insertMatch = function () {
3085 var result = this.getCompletionProvider().insertByIndex(this.editor, this.$index);
3086 this.detach();
3087 return result;
3088 };
3089 InlineAutocomplete.prototype.changeListener = function (e) {
3090 var cursor = this.editor.selection.lead;
3091 if (cursor.row != this.base.row || cursor.column < this.base.column) {
3092 this.detach();
3093 }
3094 if (this.activated)
3095 this.changeTimer.schedule();
3096 else
3097 this.detach();
3098 };
3099 InlineAutocomplete.prototype.blurListener = function (e) {
3100 this.detach();
3101 };
3102 InlineAutocomplete.prototype.goTo = function (where) {
3103 if (!this.completions || !this.completions.filtered) {
3104 return;
3105 }
3106 var completionLength = this.completions.filtered.length;
3107 switch (where.toLowerCase()) {
3108 case "prev":
3109 this.setIndex((this.$index - 1 + completionLength) % completionLength);
3110 break;
3111 case "next":
3112 this.setIndex((this.$index + 1 + completionLength) % completionLength);
3113 break;
3114 case "first":
3115 this.setIndex(0);
3116 break;
3117 case "last":
3118 this.setIndex(this.completions.filtered.length - 1);
3119 break;
3120 }
3121 };
3122 InlineAutocomplete.prototype.getLength = function () {
3123 if (!this.completions || !this.completions.filtered) {
3124 return 0;
3125 }
3126 return this.completions.filtered.length;
3127 };
3128 InlineAutocomplete.prototype.getData = function (index) {
3129 if (index == undefined || index === null) {
3130 return this.completions.filtered[this.$index];
3131 }
3132 else {
3133 return this.completions.filtered[index];
3134 }
3135 };
3136 InlineAutocomplete.prototype.getIndex = function () {
3137 return this.$index;
3138 };
3139 InlineAutocomplete.prototype.isOpen = function () {
3140 return this.$index >= 0;
3141 };
3142 InlineAutocomplete.prototype.setIndex = function (value) {
3143 if (!this.completions || !this.completions.filtered) {
3144 return;
3145 }
3146 var newIndex = Math.max(-1, Math.min(this.completions.filtered.length - 1, value));
3147 if (newIndex !== this.$index) {
3148 this.$index = newIndex;
3149 this.$showCompletion();
3150 }
3151 };
3152 InlineAutocomplete.prototype.getCompletionProvider = function (initialPosition) {
3153 if (!this.completionProvider)
3154 this.completionProvider = new CompletionProvider(initialPosition);
3155 return this.completionProvider;
3156 };
3157 InlineAutocomplete.prototype.$showCompletion = function () {
3158 if (!this.getInlineRenderer().show(this.editor, this.completions.filtered[this.$index], this.completions.filterText)) {
3159 this.getInlineRenderer().hide();
3160 }
3161 if (this.inlineTooltip && this.inlineTooltip.isShown()) {
3162 this.inlineTooltip.update();
3163 }
3164 };
3165 InlineAutocomplete.prototype.$updatePrefix = function () {
3166 var pos = this.editor.getCursorPosition();
3167 var prefix = this.editor.session.getTextRange({ start: this.base, end: pos });
3168 this.completions.setFilter(prefix);
3169 if (!this.completions.filtered.length)
3170 return this.detach();
3171 if (this.completions.filtered.length == 1
3172 && this.completions.filtered[0].value == prefix
3173 && !this.completions.filtered[0].snippet)
3174 return this.detach();
3175 this.$open(this.editor, prefix);
3176 return prefix;
3177 };
3178 InlineAutocomplete.prototype.updateCompletions = function (options) {
3179 var prefix = "";
3180 if (options && options.matches) {
3181 var pos = this.editor.getSelectionRange().start;
3182 this.base = this.editor.session.doc.createAnchor(pos.row, pos.column);
3183 this.base.$insertRight = true;
3184 this.completions = new FilteredList(options.matches);
3185 return this.$open(this.editor, "");
3186 }
3187 if (this.base && this.completions) {
3188 prefix = this.$updatePrefix();
3189 }
3190 var session = this.editor.getSession();
3191 var pos = this.editor.getCursorPosition();
3192 var prefix = util.getCompletionPrefix(this.editor);
3193 this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
3194 this.base.$insertRight = true;
3195 var options = {
3196 exactMatch: true,
3197 ignoreCaption: true
3198 };
3199 this.getCompletionProvider({
3200 prefix: prefix,
3201 base: this.base,
3202 pos: pos
3203 }).provideCompletions(this.editor, options,
3204 function (err, completions, finished) {
3205 var filtered = completions.filtered;
3206 var prefix = util.getCompletionPrefix(this.editor);
3207 if (finished) {
3208 if (!filtered.length)
3209 return this.detach();
3210 if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
3211 return this.detach();
3212 }
3213 this.completions = completions;
3214 this.$open(this.editor, prefix);
3215 }.bind(this));
3216 };
3217 InlineAutocomplete.prototype.detach = function () {
3218 if (this.editor) {
3219 this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
3220 this.editor.off("changeSelection", this.changeListener);
3221 this.editor.off("blur", this.blurListener);
3222 }
3223 this.changeTimer.cancel();
3224 if (this.inlineTooltip) {
3225 this.inlineTooltip.detach();
3226 }
3227 this.setIndex(-1);
3228 if (this.completionProvider) {
3229 this.completionProvider.detach();
3230 }
3231 if (this.inlineRenderer && this.inlineRenderer.isOpen()) {
3232 this.inlineRenderer.hide();
3233 }
3234 if (this.base)
3235 this.base.detach();
3236 this.activated = false;
3237 this.completionProvider = this.completions = this.base = null;
3238 };
3239 InlineAutocomplete.prototype.destroy = function () {
3240 this.detach();
3241 if (this.inlineRenderer)
3242 this.inlineRenderer.destroy();
3243 if (this.inlineTooltip)
3244 this.inlineTooltip.destroy();
3245 if (this.editor && this.editor.completer == this) {
3246 this.editor.off("destroy", destroyCompleter);
3247 this.editor.completer = null;
3248 }
3249 this.inlineTooltip = this.editor = this.inlineRenderer = null;
3250 };
3251 InlineAutocomplete.prototype.updateDocTooltip = function () {
3252 };
3253 return InlineAutocomplete;
3254 }());
3255 InlineAutocomplete.prototype.commands = {
3256 "Previous": {
3257 bindKey: "Alt-[",
3258 name: "Previous",
3259 exec: function (editor) {
3260 editor.completer.goTo("prev");
3261 }
3262 },
3263 "Next": {
3264 bindKey: "Alt-]",
3265 name: "Next",
3266 exec: function (editor) {
3267 editor.completer.goTo("next");
3268 }
3269 },
3270 "Accept": {
3271 bindKey: { win: "Tab|Ctrl-Right", mac: "Tab|Cmd-Right" },
3272 name: "Accept",
3273 exec: function (editor) {
3274 return /**@type{InlineAutocomplete}*/ (editor.completer).insertMatch();
3275 }
3276 },
3277 "Close": {
3278 bindKey: "Esc",
3279 name: "Close",
3280 exec: function (editor) {
3281 editor.completer.detach();
3282 }
3283 }
3284 };
3285 InlineAutocomplete.for = function (editor) {
3286 if (editor.completer instanceof InlineAutocomplete) {
3287 return editor.completer;
3288 }
3289 if (editor.completer) {
3290 editor.completer.destroy();
3291 editor.completer = null;
3292 }
3293 editor.completer = new InlineAutocomplete(editor);
3294 editor.once("destroy", destroyCompleter);
3295 return editor.completer;
3296 };
3297 InlineAutocomplete.startCommand = {
3298 name: "startInlineAutocomplete",
3299 exec: function (editor, options) {
3300 var completer = InlineAutocomplete.for(editor);
3301 completer.show(options);
3302 },
3303 bindKey: { win: "Alt-C", mac: "Option-C" }
3304 };
3305 var completers = [snippetCompleter, textCompleter, keyWordCompleter];
3306 require("../config").defineOptions(Editor.prototype, "editor", {
3307 enableInlineAutocompletion: {
3308 set: function (val) {
3309 if (val) {
3310 if (!this.completers)
3311 this.completers = Array.isArray(val) ? val : completers;
3312 this.commands.addCommand(InlineAutocomplete.startCommand);
3313 }
3314 else {
3315 this.commands.removeCommand(InlineAutocomplete.startCommand);
3316 }
3317 },
3318 value: false
3319 }
3320 });
3321 InlineAutocomplete.createInlineTooltip = function (parentEl) {
3322 var inlineTooltip = new CommandBarTooltip(parentEl);
3323 inlineTooltip.registerCommand("Previous",
3324 Object.assign({}, InlineAutocomplete.prototype.commands["Previous"], {
3325 enabled: true,
3326 type: "button",
3327 iconCssClass: "ace_arrow_rotated"
3328 }));
3329 inlineTooltip.registerCommand("Position", {
3330 enabled: false,
3331 getValue: function (editor) {
3332 return editor ? [
3333 (editor.completer).getIndex() + 1, /**@type{InlineAutocomplete}*/ (editor.completer).getLength()
3334 ].join("/") : "";
3335 },
3336 type: "text",
3337 cssClass: "completion_position"
3338 });
3339 inlineTooltip.registerCommand("Next",
3340 Object.assign({}, InlineAutocomplete.prototype.commands["Next"], {
3341 enabled: true,
3342 type: "button",
3343 iconCssClass: "ace_arrow"
3344 }));
3345 inlineTooltip.registerCommand("Accept",
3346 Object.assign({}, InlineAutocomplete.prototype.commands["Accept"], {
3347 enabled: function (editor) {
3348 return !!editor && editor.completer.getIndex() >= 0;
3349 },
3350 type: "button"
3351 }));
3352 inlineTooltip.registerCommand("ShowTooltip", {
3353 name: "Always Show Tooltip",
3354 exec: function () {
3355 inlineTooltip.setAlwaysShow(!inlineTooltip.getAlwaysShow());
3356 },
3357 enabled: true,
3358 getValue: function () {
3359 return inlineTooltip.getAlwaysShow();
3360 },
3361 type: "checkbox"
3362 });
3363 return inlineTooltip;
3364 };
3365 dom.importCssString("\n\n.ace_icon_svg.ace_arrow,\n.ace_icon_svg.ace_arrow_rotated {\n -webkit-mask-image: url(\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTUuODM3MDEgMTVMNC41ODc1MSAxMy43MTU1TDEwLjE0NjggOEw0LjU4NzUxIDIuMjg0NDZMNS44MzcwMSAxTDEyLjY0NjUgOEw1LjgzNzAxIDE1WiIgZmlsbD0iYmxhY2siLz48L3N2Zz4=\");\n}\n\n.ace_icon_svg.ace_arrow_rotated {\n transform: rotate(180deg);\n}\n\ndiv.".concat(BUTTON_CLASS_NAME, ".completion_position {\n padding: 0;\n}\n"), "inlineautocomplete.css", false);
3366 exports.InlineAutocomplete = InlineAutocomplete;
3367
3368 }); (function() {
3369 ace.require(["ace/ext/inline_autocomplete"], function(m) {
3370 if (typeof module == "object" && typeof exports == "object" && module) {
3371 module.exports = m;
3372 }
3373 });
3374 })();
3375