説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ext-language_tools.js 66KB

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