899e0543f3fa0c5298c0e35e9c20e0f8.js 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109
  1. 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";
  2. var Renderer = require("../virtual_renderer").VirtualRenderer;
  3. var Editor = require("../editor").Editor;
  4. var Range = require("../range").Range;
  5. var event = require("../lib/event");
  6. var lang = require("../lib/lang");
  7. var dom = require("../lib/dom");
  8. var nls = require("../config").nls;
  9. var userAgent = require("./../lib/useragent");
  10. var getAriaId = function (index) {
  11. return "suggest-aria-id:".concat(index);
  12. };
  13. var popupAriaRole = userAgent.isSafari ? "menu" : "listbox";
  14. var optionAriaRole = userAgent.isSafari ? "menuitem" : "option";
  15. var ariaActiveState = userAgent.isSafari ? "aria-current" : "aria-selected";
  16. var $singleLineEditor = function (el) {
  17. var renderer = new Renderer(el);
  18. renderer.$maxLines = 4;
  19. var editor = new Editor(renderer);
  20. editor.setHighlightActiveLine(false);
  21. editor.setShowPrintMargin(false);
  22. editor.renderer.setShowGutter(false);
  23. editor.renderer.setHighlightGutterLine(false);
  24. editor.$mouseHandler.$focusTimeout = 0;
  25. editor.$highlightTagPending = true;
  26. return editor;
  27. };
  28. var AcePopup = /** @class */ (function () {
  29. function AcePopup(parentNode) {
  30. var el = dom.createElement("div");
  31. var popup = $singleLineEditor(el);
  32. if (parentNode) {
  33. parentNode.appendChild(el);
  34. }
  35. el.style.display = "none";
  36. popup.renderer.content.style.cursor = "default";
  37. popup.renderer.setStyle("ace_autocomplete");
  38. popup.renderer.$textLayer.element.setAttribute("role", popupAriaRole);
  39. popup.renderer.$textLayer.element.setAttribute("aria-roledescription", nls("autocomplete.popup.aria-roledescription", "Autocomplete suggestions"));
  40. popup.renderer.$textLayer.element.setAttribute("aria-label", nls("autocomplete.popup.aria-label", "Autocomplete suggestions"));
  41. popup.renderer.textarea.setAttribute("aria-hidden", "true");
  42. popup.setOption("displayIndentGuides", false);
  43. popup.setOption("dragDelay", 150);
  44. var noop = function () { };
  45. popup.focus = noop;
  46. popup.$isFocused = true;
  47. popup.renderer.$cursorLayer.restartTimer = noop;
  48. popup.renderer.$cursorLayer.element.style.opacity = "0";
  49. popup.renderer.$maxLines = 8;
  50. popup.renderer.$keepTextAreaAtCursor = false;
  51. popup.setHighlightActiveLine(false);
  52. popup.session.highlight("");
  53. popup.session.$searchHighlight.clazz = "ace_highlight-marker";
  54. popup.on("mousedown", function (e) {
  55. var pos = e.getDocumentPosition();
  56. popup.selection.moveToPosition(pos);
  57. selectionMarker.start.row = selectionMarker.end.row = pos.row;
  58. e.stop();
  59. });
  60. var lastMouseEvent;
  61. var hoverMarker = new Range(-1, 0, -1, Infinity);
  62. var selectionMarker = new Range(-1, 0, -1, Infinity);
  63. selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
  64. popup.setSelectOnHover = function (val) {
  65. if (!val) {
  66. hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
  67. }
  68. else if (hoverMarker.id) {
  69. popup.session.removeMarker(hoverMarker.id);
  70. hoverMarker.id = null;
  71. }
  72. };
  73. popup.setSelectOnHover(false);
  74. popup.on("mousemove", function (e) {
  75. if (!lastMouseEvent) {
  76. lastMouseEvent = e;
  77. return;
  78. }
  79. if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
  80. return;
  81. }
  82. lastMouseEvent = e;
  83. lastMouseEvent.scrollTop = popup.renderer.scrollTop;
  84. popup.isMouseOver = true;
  85. var row = lastMouseEvent.getDocumentPosition().row;
  86. if (hoverMarker.start.row != row) {
  87. if (!hoverMarker.id)
  88. popup.setRow(row);
  89. setHoverMarker(row);
  90. }
  91. });
  92. popup.renderer.on("beforeRender", function () {
  93. if (lastMouseEvent && hoverMarker.start.row != -1) {
  94. lastMouseEvent.$pos = null;
  95. var row = lastMouseEvent.getDocumentPosition().row;
  96. if (!hoverMarker.id)
  97. popup.setRow(row);
  98. setHoverMarker(row, true);
  99. }
  100. });
  101. popup.renderer.on("afterRender", function () {
  102. var t = popup.renderer.$textLayer;
  103. for (var row = t.config.firstRow, l = t.config.lastRow; row <= l; row++) {
  104. var popupRowElement = /** @type {HTMLElement|null} */ (t.element.childNodes[row - t.config.firstRow]);
  105. popupRowElement.setAttribute("role", optionAriaRole);
  106. popupRowElement.setAttribute("aria-roledescription", nls("autocomplete.popup.item.aria-roledescription", "item"));
  107. popupRowElement.setAttribute("aria-setsize", popup.data.length);
  108. popupRowElement.setAttribute("aria-describedby", "doc-tooltip");
  109. popupRowElement.setAttribute("aria-posinset", row + 1);
  110. var rowData = popup.getData(row);
  111. if (rowData) {
  112. var ariaLabel = "".concat(rowData.caption || rowData.value).concat(rowData.meta ? ", ".concat(rowData.meta) : '');
  113. popupRowElement.setAttribute("aria-label", ariaLabel);
  114. }
  115. var highlightedSpans = popupRowElement.querySelectorAll(".ace_completion-highlight");
  116. highlightedSpans.forEach(function (span) {
  117. span.setAttribute("role", "mark");
  118. });
  119. }
  120. });
  121. popup.renderer.on("afterRender", function () {
  122. var row = popup.getRow();
  123. var t = popup.renderer.$textLayer;
  124. var selected = /** @type {HTMLElement|null} */ (t.element.childNodes[row - t.config.firstRow]);
  125. var el = document.activeElement; // Active element is textarea of main editor
  126. if (selected !== popup.selectedNode && popup.selectedNode) {
  127. dom.removeCssClass(popup.selectedNode, "ace_selected");
  128. popup.selectedNode.removeAttribute(ariaActiveState);
  129. popup.selectedNode.removeAttribute("id");
  130. }
  131. el.removeAttribute("aria-activedescendant");
  132. popup.selectedNode = selected;
  133. if (selected) {
  134. var ariaId = getAriaId(row);
  135. dom.addCssClass(selected, "ace_selected");
  136. selected.id = ariaId;
  137. t.element.setAttribute("aria-activedescendant", ariaId);
  138. el.setAttribute("aria-activedescendant", ariaId);
  139. selected.setAttribute(ariaActiveState, "true");
  140. }
  141. });
  142. var hideHoverMarker = function () { setHoverMarker(-1); };
  143. var setHoverMarker = function (row, suppressRedraw) {
  144. if (row !== hoverMarker.start.row) {
  145. hoverMarker.start.row = hoverMarker.end.row = row;
  146. if (!suppressRedraw)
  147. popup.session._emit("changeBackMarker");
  148. popup._emit("changeHoverMarker");
  149. }
  150. };
  151. popup.getHoveredRow = function () {
  152. return hoverMarker.start.row;
  153. };
  154. event.addListener(popup.container, "mouseout", function () {
  155. popup.isMouseOver = false;
  156. hideHoverMarker();
  157. });
  158. popup.on("hide", hideHoverMarker);
  159. popup.on("changeSelection", hideHoverMarker);
  160. popup.session.doc.getLength = function () {
  161. return popup.data.length;
  162. };
  163. popup.session.doc.getLine = function (i) {
  164. var data = popup.data[i];
  165. if (typeof data == "string")
  166. return data;
  167. return (data && data.value) || "";
  168. };
  169. var bgTokenizer = popup.session.bgTokenizer;
  170. bgTokenizer.$tokenizeRow = function (row) {
  171. var data = popup.data[row];
  172. var tokens = [];
  173. if (!data)
  174. return tokens;
  175. if (typeof data == "string")
  176. data = { value: data };
  177. var caption = data.caption || data.value || data.name;
  178. function addToken(value, className) {
  179. value && tokens.push({
  180. type: (data.className || "") + (className || ""),
  181. value: value
  182. });
  183. }
  184. var lower = caption.toLowerCase();
  185. var filterText = (popup.filterText || "").toLowerCase();
  186. var lastIndex = 0;
  187. var lastI = 0;
  188. for (var i = 0; i <= filterText.length; i++) {
  189. if (i != lastI && (data.matchMask & (1 << i) || i == filterText.length)) {
  190. var sub = filterText.slice(lastI, i);
  191. lastI = i;
  192. var index = lower.indexOf(sub, lastIndex);
  193. if (index == -1)
  194. continue;
  195. addToken(caption.slice(lastIndex, index), "");
  196. lastIndex = index + sub.length;
  197. addToken(caption.slice(index, lastIndex), "completion-highlight");
  198. }
  199. }
  200. addToken(caption.slice(lastIndex, caption.length), "");
  201. tokens.push({ type: "completion-spacer", value: " " });
  202. if (data.meta)
  203. tokens.push({ type: "completion-meta", value: data.meta });
  204. if (data.message)
  205. tokens.push({ type: "completion-message", value: data.message });
  206. return tokens;
  207. };
  208. bgTokenizer.$updateOnChange = noop;
  209. bgTokenizer.start = noop;
  210. popup.session.$computeWidth = function () {
  211. return this.screenWidth = 0;
  212. };
  213. popup.isOpen = false;
  214. popup.isTopdown = false;
  215. popup.autoSelect = true;
  216. popup.filterText = "";
  217. popup.isMouseOver = false;
  218. popup.data = [];
  219. popup.setData = function (list, filterText) {
  220. popup.filterText = filterText || "";
  221. popup.setValue(lang.stringRepeat("\n", list.length), -1);
  222. popup.data = list || [];
  223. popup.setRow(0);
  224. };
  225. popup.getData = function (row) {
  226. return popup.data[row];
  227. };
  228. popup.getRow = function () {
  229. return selectionMarker.start.row;
  230. };
  231. popup.setRow = function (line) {
  232. line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line));
  233. if (selectionMarker.start.row != line) {
  234. popup.selection.clearSelection();
  235. selectionMarker.start.row = selectionMarker.end.row = line || 0;
  236. popup.session._emit("changeBackMarker");
  237. popup.moveCursorTo(line || 0, 0);
  238. if (popup.isOpen)
  239. popup._signal("select");
  240. }
  241. };
  242. popup.on("changeSelection", function () {
  243. if (popup.isOpen)
  244. popup.setRow(popup.selection.lead.row);
  245. popup.renderer.scrollCursorIntoView();
  246. });
  247. popup.hide = function () {
  248. this.container.style.display = "none";
  249. popup.anchorPos = null;
  250. popup.anchor = null;
  251. if (popup.isOpen) {
  252. popup.isOpen = false;
  253. this._signal("hide");
  254. }
  255. };
  256. popup.tryShow = function (pos, lineHeight, anchor, forceShow) {
  257. if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor &&
  258. popup.anchorPos.top === pos.top && popup.anchorPos.left === pos.left &&
  259. popup.anchor === anchor) {
  260. return true;
  261. }
  262. var el = this.container;
  263. var scrollBarSize = this.renderer.scrollBar.width || 10;
  264. var screenHeight = window.innerHeight - scrollBarSize;
  265. var screenWidth = window.innerWidth - scrollBarSize;
  266. var renderer = this.renderer;
  267. var maxH = renderer.$maxLines * lineHeight * 1.4;
  268. var dims = { top: 0, bottom: 0, left: 0 };
  269. var spaceBelow = screenHeight - pos.top - 3 * this.$borderSize - lineHeight;
  270. var spaceAbove = pos.top - 3 * this.$borderSize;
  271. if (!anchor) {
  272. if (spaceAbove <= spaceBelow || spaceBelow >= maxH) {
  273. anchor = "bottom";
  274. }
  275. else {
  276. anchor = "top";
  277. }
  278. }
  279. if (anchor === "top") {
  280. dims.bottom = pos.top - this.$borderSize;
  281. dims.top = dims.bottom - maxH;
  282. }
  283. else if (anchor === "bottom") {
  284. dims.top = pos.top + lineHeight + this.$borderSize;
  285. dims.bottom = dims.top + maxH;
  286. }
  287. var fitsX = dims.top >= 0 && dims.bottom <= screenHeight;
  288. if (!forceShow && !fitsX) {
  289. return false;
  290. }
  291. if (!fitsX) {
  292. if (anchor === "top") {
  293. renderer.$maxPixelHeight = spaceAbove;
  294. }
  295. else {
  296. renderer.$maxPixelHeight = spaceBelow;
  297. }
  298. }
  299. else {
  300. renderer.$maxPixelHeight = null;
  301. }
  302. if (anchor === "top") {
  303. el.style.top = "";
  304. el.style.bottom = (screenHeight + scrollBarSize - dims.bottom) + "px";
  305. popup.isTopdown = false;
  306. }
  307. else {
  308. el.style.top = dims.top + "px";
  309. el.style.bottom = "";
  310. popup.isTopdown = true;
  311. }
  312. el.style.display = "";
  313. var left = pos.left;
  314. if (left + el.offsetWidth > screenWidth)
  315. left = screenWidth - el.offsetWidth;
  316. el.style.left = left + "px";
  317. el.style.right = "";
  318. if (!popup.isOpen) {
  319. popup.isOpen = true;
  320. this._signal("show");
  321. lastMouseEvent = null;
  322. }
  323. popup.anchorPos = pos;
  324. popup.anchor = anchor;
  325. return true;
  326. };
  327. popup.show = function (pos, lineHeight, topdownOnly) {
  328. this.tryShow(pos, lineHeight, topdownOnly ? "bottom" : undefined, true);
  329. };
  330. popup.goTo = function (where) {
  331. var row = this.getRow();
  332. var max = this.session.getLength() - 1;
  333. switch (where) {
  334. case "up":
  335. row = row <= 0 ? max : row - 1;
  336. break;
  337. case "down":
  338. row = row >= max ? -1 : row + 1;
  339. break;
  340. case "start":
  341. row = 0;
  342. break;
  343. case "end":
  344. row = max;
  345. break;
  346. }
  347. this.setRow(row);
  348. };
  349. popup.getTextLeftOffset = function () {
  350. return this.$borderSize + this.renderer.$padding + this.$imageSize;
  351. };
  352. popup.$imageSize = 0;
  353. popup.$borderSize = 1;
  354. return popup;
  355. }
  356. return AcePopup;
  357. }());
  358. 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 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);
  359. exports.AcePopup = AcePopup;
  360. exports.$singleLineEditor = $singleLineEditor;
  361. exports.getAriaId = getAriaId;
  362. });
  363. 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";
  364. var dom = require("./lib/dom");
  365. var oop = require("./lib/oop");
  366. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  367. var lang = require("./lib/lang");
  368. var Range = require("./range").Range;
  369. var RangeList = require("./range_list").RangeList;
  370. var HashHandler = require("./keyboard/hash_handler").HashHandler;
  371. var Tokenizer = require("./tokenizer").Tokenizer;
  372. var clipboard = require("./clipboard");
  373. var VARIABLES = {
  374. CURRENT_WORD: function (editor) {
  375. return editor.session.getTextRange(editor.session.getWordRange());
  376. },
  377. SELECTION: function (editor, name, indentation) {
  378. var text = editor.session.getTextRange();
  379. if (indentation)
  380. return text.replace(/\n\r?([ \t]*\S)/g, "\n" + indentation + "$1");
  381. return text;
  382. },
  383. CURRENT_LINE: function (editor) {
  384. return editor.session.getLine(editor.getCursorPosition().row);
  385. },
  386. PREV_LINE: function (editor) {
  387. return editor.session.getLine(editor.getCursorPosition().row - 1);
  388. },
  389. LINE_INDEX: function (editor) {
  390. return editor.getCursorPosition().row;
  391. },
  392. LINE_NUMBER: function (editor) {
  393. return editor.getCursorPosition().row + 1;
  394. },
  395. SOFT_TABS: function (editor) {
  396. return editor.session.getUseSoftTabs() ? "YES" : "NO";
  397. },
  398. TAB_SIZE: function (editor) {
  399. return editor.session.getTabSize();
  400. },
  401. CLIPBOARD: function (editor) {
  402. return clipboard.getText && clipboard.getText();
  403. },
  404. FILENAME: function (editor) {
  405. return /[^/\\]*$/.exec(this.FILEPATH(editor))[0];
  406. },
  407. FILENAME_BASE: function (editor) {
  408. return /[^/\\]*$/.exec(this.FILEPATH(editor))[0].replace(/\.[^.]*$/, "");
  409. },
  410. DIRECTORY: function (editor) {
  411. return this.FILEPATH(editor).replace(/[^/\\]*$/, "");
  412. },
  413. FILEPATH: function (editor) { return "/not implemented.txt"; },
  414. WORKSPACE_NAME: function () { return "Unknown"; },
  415. FULLNAME: function () { return "Unknown"; },
  416. BLOCK_COMMENT_START: function (editor) {
  417. var mode = editor.session.$mode || {};
  418. return mode.blockComment && mode.blockComment.start || "";
  419. },
  420. BLOCK_COMMENT_END: function (editor) {
  421. var mode = editor.session.$mode || {};
  422. return mode.blockComment && mode.blockComment.end || "";
  423. },
  424. LINE_COMMENT: function (editor) {
  425. var mode = editor.session.$mode || {};
  426. return mode.lineCommentStart || "";
  427. },
  428. CURRENT_YEAR: date.bind(null, { year: "numeric" }),
  429. CURRENT_YEAR_SHORT: date.bind(null, { year: "2-digit" }),
  430. CURRENT_MONTH: date.bind(null, { month: "numeric" }),
  431. CURRENT_MONTH_NAME: date.bind(null, { month: "long" }),
  432. CURRENT_MONTH_NAME_SHORT: date.bind(null, { month: "short" }),
  433. CURRENT_DATE: date.bind(null, { day: "2-digit" }),
  434. CURRENT_DAY_NAME: date.bind(null, { weekday: "long" }),
  435. CURRENT_DAY_NAME_SHORT: date.bind(null, { weekday: "short" }),
  436. CURRENT_HOUR: date.bind(null, { hour: "2-digit", hour12: false }),
  437. CURRENT_MINUTE: date.bind(null, { minute: "2-digit" }),
  438. CURRENT_SECOND: date.bind(null, { second: "2-digit" })
  439. };
  440. VARIABLES.SELECTED_TEXT = VARIABLES.SELECTION;
  441. function date(dateFormat) {
  442. var str = new Date().toLocaleString("en-us", dateFormat);
  443. return str.length == 1 ? "0" + str : str;
  444. }
  445. var SnippetManager = /** @class */ (function () {
  446. function SnippetManager() {
  447. this.snippetMap = {};
  448. this.snippetNameMap = {};
  449. this.variables = VARIABLES;
  450. }
  451. SnippetManager.prototype.getTokenizer = function () {
  452. return SnippetManager["$tokenizer"] || this.createTokenizer();
  453. };
  454. SnippetManager.prototype.createTokenizer = function () {
  455. function TabstopToken(str) {
  456. str = str.substr(1);
  457. if (/^\d+$/.test(str))
  458. return [{ tabstopId: parseInt(str, 10) }];
  459. return [{ text: str }];
  460. }
  461. function escape(ch) {
  462. return "(?:[^\\\\" + ch + "]|\\\\.)";
  463. }
  464. var formatMatcher = {
  465. regex: "/(" + escape("/") + "+)/",
  466. onMatch: function (val, state, stack) {
  467. var ts = stack[0];
  468. ts.fmtString = true;
  469. ts.guard = val.slice(1, -1);
  470. ts.flag = "";
  471. return "";
  472. },
  473. next: "formatString"
  474. };
  475. SnippetManager["$tokenizer"] = new Tokenizer({
  476. start: [
  477. { regex: /\\./, onMatch: function (val, state, stack) {
  478. var ch = val[1];
  479. if (ch == "}" && stack.length) {
  480. val = ch;
  481. }
  482. else if ("`$\\".indexOf(ch) != -1) {
  483. val = ch;
  484. }
  485. return [val];
  486. } },
  487. { regex: /}/, onMatch: function (val, state, stack) {
  488. return [stack.length ? stack.shift() : val];
  489. } },
  490. { regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken },
  491. { regex: /\$\{[\dA-Z_a-z]+/, onMatch: function (str, state, stack) {
  492. var t = TabstopToken(str.substr(1));
  493. stack.unshift(t[0]);
  494. return t;
  495. }, next: "snippetVar" },
  496. { regex: /\n/, token: "newline", merge: false }
  497. ],
  498. snippetVar: [
  499. { regex: "\\|" + escape("\\|") + "*\\|", onMatch: function (val, state, stack) {
  500. var choices = val.slice(1, -1).replace(/\\[,|\\]|,/g, function (operator) {
  501. return operator.length == 2 ? operator[1] : "\x00";
  502. }).split("\x00").map(function (value) {
  503. return { value: value };
  504. });
  505. stack[0].choices = choices;
  506. return [choices[0]];
  507. }, next: "start" },
  508. formatMatcher,
  509. { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start" }
  510. ],
  511. formatString: [
  512. { regex: /:/, onMatch: function (val, state, stack) {
  513. if (stack.length && stack[0].expectElse) {
  514. stack[0].expectElse = false;
  515. stack[0].ifEnd = { elseEnd: stack[0] };
  516. return [stack[0].ifEnd];
  517. }
  518. return ":";
  519. } },
  520. { regex: /\\./, onMatch: function (val, state, stack) {
  521. var ch = val[1];
  522. if (ch == "}" && stack.length)
  523. val = ch;
  524. else if ("`$\\".indexOf(ch) != -1)
  525. val = ch;
  526. else if (ch == "n")
  527. val = "\n";
  528. else if (ch == "t")
  529. val = "\t";
  530. else if ("ulULE".indexOf(ch) != -1)
  531. val = { changeCase: ch, local: ch > "a" };
  532. return [val];
  533. } },
  534. { regex: "/\\w*}", onMatch: function (val, state, stack) {
  535. var next = stack.shift();
  536. if (next)
  537. next.flag = val.slice(1, -1);
  538. this.next = next && next.tabstopId ? "start" : "";
  539. return [next || val];
  540. }, next: "start" },
  541. { regex: /\$(?:\d+|\w+)/, onMatch: function (val, state, stack) {
  542. return [{ text: val.slice(1) }];
  543. } },
  544. { regex: /\${\w+/, onMatch: function (val, state, stack) {
  545. var token = { text: val.slice(2) };
  546. stack.unshift(token);
  547. return [token];
  548. }, next: "formatStringVar" },
  549. { regex: /\n/, token: "newline", merge: false },
  550. { regex: /}/, onMatch: function (val, state, stack) {
  551. var next = stack.shift();
  552. this.next = next && next.tabstopId ? "start" : "";
  553. return [next || val];
  554. }, next: "start" }
  555. ],
  556. formatStringVar: [
  557. { regex: /:\/\w+}/, onMatch: function (val, state, stack) {
  558. var ts = stack[0];
  559. ts.formatFunction = val.slice(2, -1);
  560. return [stack.shift()];
  561. }, next: "formatString" },
  562. formatMatcher,
  563. { regex: /:[\?\-+]?/, onMatch: function (val, state, stack) {
  564. if (val[1] == "+")
  565. stack[0].ifEnd = stack[0];
  566. if (val[1] == "?")
  567. stack[0].expectElse = true;
  568. }, next: "formatString" },
  569. { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "formatString" }
  570. ]
  571. });
  572. return SnippetManager["$tokenizer"];
  573. };
  574. SnippetManager.prototype.tokenizeTmSnippet = function (str, startState) {
  575. return this.getTokenizer().getLineTokens(str, startState).tokens.map(function (x) {
  576. return x.value || x;
  577. });
  578. };
  579. SnippetManager.prototype.getVariableValue = function (editor, name, indentation) {
  580. if (/^\d+$/.test(name))
  581. return (this.variables.__ || {})[name] || "";
  582. if (/^[A-Z]\d+$/.test(name))
  583. return (this.variables[name[0] + "__"] || {})[name.substr(1)] || "";
  584. name = name.replace(/^TM_/, "");
  585. if (!this.variables.hasOwnProperty(name))
  586. return "";
  587. var value = this.variables[name];
  588. if (typeof value == "function")
  589. value = this.variables[name](editor, name, indentation);
  590. return value == null ? "" : value;
  591. };
  592. SnippetManager.prototype.tmStrFormat = function (str, ch, editor) {
  593. if (!ch.fmt)
  594. return str;
  595. var flag = ch.flag || "";
  596. var re = ch.guard;
  597. re = new RegExp(re, flag.replace(/[^gim]/g, ""));
  598. var fmtTokens = typeof ch.fmt == "string" ? this.tokenizeTmSnippet(ch.fmt, "formatString") : ch.fmt;
  599. var _self = this;
  600. var formatted = str.replace(re, function () {
  601. var oldArgs = _self.variables.__;
  602. _self.variables.__ = [].slice.call(arguments);
  603. var fmtParts = _self.resolveVariables(fmtTokens, editor);
  604. var gChangeCase = "E";
  605. for (var i = 0; i < fmtParts.length; i++) {
  606. var ch = fmtParts[i];
  607. if (typeof ch == "object") {
  608. fmtParts[i] = "";
  609. if (ch.changeCase && ch.local) {
  610. var next = fmtParts[i + 1];
  611. if (next && typeof next == "string") {
  612. if (ch.changeCase == "u")
  613. fmtParts[i] = next[0].toUpperCase();
  614. else
  615. fmtParts[i] = next[0].toLowerCase();
  616. fmtParts[i + 1] = next.substr(1);
  617. }
  618. }
  619. else if (ch.changeCase) {
  620. gChangeCase = ch.changeCase;
  621. }
  622. }
  623. else if (gChangeCase == "U") {
  624. fmtParts[i] = ch.toUpperCase();
  625. }
  626. else if (gChangeCase == "L") {
  627. fmtParts[i] = ch.toLowerCase();
  628. }
  629. }
  630. _self.variables.__ = oldArgs;
  631. return fmtParts.join("");
  632. });
  633. return formatted;
  634. };
  635. SnippetManager.prototype.tmFormatFunction = function (str, ch, editor) {
  636. if (ch.formatFunction == "upcase")
  637. return str.toUpperCase();
  638. if (ch.formatFunction == "downcase")
  639. return str.toLowerCase();
  640. return str;
  641. };
  642. SnippetManager.prototype.resolveVariables = function (snippet, editor) {
  643. var result = [];
  644. var indentation = "";
  645. var afterNewLine = true;
  646. for (var i = 0; i < snippet.length; i++) {
  647. var ch = snippet[i];
  648. if (typeof ch == "string") {
  649. result.push(ch);
  650. if (ch == "\n") {
  651. afterNewLine = true;
  652. indentation = "";
  653. }
  654. else if (afterNewLine) {
  655. indentation = /^\t*/.exec(ch)[0];
  656. afterNewLine = /\S/.test(ch);
  657. }
  658. continue;
  659. }
  660. if (!ch)
  661. continue;
  662. afterNewLine = false;
  663. if (ch.fmtString) {
  664. var j = snippet.indexOf(ch, i + 1);
  665. if (j == -1)
  666. j = snippet.length;
  667. ch.fmt = snippet.slice(i + 1, j);
  668. i = j;
  669. }
  670. if (ch.text) {
  671. var value = this.getVariableValue(editor, ch.text, indentation) + "";
  672. if (ch.fmtString)
  673. value = this.tmStrFormat(value, ch, editor);
  674. if (ch.formatFunction)
  675. value = this.tmFormatFunction(value, ch, editor);
  676. if (value && !ch.ifEnd) {
  677. result.push(value);
  678. gotoNext(ch);
  679. }
  680. else if (!value && ch.ifEnd) {
  681. gotoNext(ch.ifEnd);
  682. }
  683. }
  684. else if (ch.elseEnd) {
  685. gotoNext(ch.elseEnd);
  686. }
  687. else if (ch.tabstopId != null) {
  688. result.push(ch);
  689. }
  690. else if (ch.changeCase != null) {
  691. result.push(ch);
  692. }
  693. }
  694. function gotoNext(ch) {
  695. var i1 = snippet.indexOf(ch, i + 1);
  696. if (i1 != -1)
  697. i = i1;
  698. }
  699. return result;
  700. };
  701. SnippetManager.prototype.getDisplayTextForSnippet = function (editor, snippetText) {
  702. var processedSnippet = processSnippetText.call(this, editor, snippetText);
  703. return processedSnippet.text;
  704. };
  705. SnippetManager.prototype.insertSnippetForSelection = function (editor, snippetText, options) {
  706. if (options === void 0) { options = {}; }
  707. var processedSnippet = processSnippetText.call(this, editor, snippetText, options);
  708. var range = editor.getSelectionRange();
  709. var end = editor.session.replace(range, processedSnippet.text);
  710. var tabstopManager = new TabstopManager(editor);
  711. var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
  712. tabstopManager.addTabstops(processedSnippet.tabstops, range.start, end, selectionId);
  713. };
  714. SnippetManager.prototype.insertSnippet = function (editor, snippetText, options) {
  715. if (options === void 0) { options = {}; }
  716. var self = this;
  717. if (editor.inVirtualSelectionMode)
  718. return self.insertSnippetForSelection(editor, snippetText, options);
  719. editor.forEachSelection(function () {
  720. self.insertSnippetForSelection(editor, snippetText, options);
  721. }, null, { keepOrder: true });
  722. if (editor.tabstopManager)
  723. editor.tabstopManager.tabNext();
  724. };
  725. SnippetManager.prototype.$getScope = function (editor) {
  726. var scope = editor.session.$mode.$id || "";
  727. scope = scope.split("/").pop();
  728. if (scope === "html" || scope === "php") {
  729. if (scope === "php" && !editor.session.$mode.inlinePhp)
  730. scope = "html";
  731. var c = editor.getCursorPosition();
  732. var state = editor.session.getState(c.row);
  733. if (typeof state === "object") {
  734. state = state[0];
  735. }
  736. if (state.substring) {
  737. if (state.substring(0, 3) == "js-")
  738. scope = "javascript";
  739. else if (state.substring(0, 4) == "css-")
  740. scope = "css";
  741. else if (state.substring(0, 4) == "php-")
  742. scope = "php";
  743. }
  744. }
  745. return scope;
  746. };
  747. SnippetManager.prototype.getActiveScopes = function (editor) {
  748. var scope = this.$getScope(editor);
  749. var scopes = [scope];
  750. var snippetMap = this.snippetMap;
  751. if (snippetMap[scope] && snippetMap[scope].includeScopes) {
  752. scopes.push.apply(scopes, snippetMap[scope].includeScopes);
  753. }
  754. scopes.push("_");
  755. return scopes;
  756. };
  757. SnippetManager.prototype.expandWithTab = function (editor, options) {
  758. var self = this;
  759. var result = editor.forEachSelection(function () {
  760. return self.expandSnippetForSelection(editor, options);
  761. }, null, { keepOrder: true });
  762. if (result && editor.tabstopManager)
  763. editor.tabstopManager.tabNext();
  764. return result;
  765. };
  766. SnippetManager.prototype.expandSnippetForSelection = function (editor, options) {
  767. var cursor = editor.getCursorPosition();
  768. var line = editor.session.getLine(cursor.row);
  769. var before = line.substring(0, cursor.column);
  770. var after = line.substr(cursor.column);
  771. var snippetMap = this.snippetMap;
  772. var snippet;
  773. this.getActiveScopes(editor).some(function (scope) {
  774. var snippets = snippetMap[scope];
  775. if (snippets)
  776. snippet = this.findMatchingSnippet(snippets, before, after);
  777. return !!snippet;
  778. }, this);
  779. if (!snippet)
  780. return false;
  781. if (options && options.dryRun)
  782. return true;
  783. editor.session.doc.removeInLine(cursor.row, cursor.column - snippet.replaceBefore.length, cursor.column + snippet.replaceAfter.length);
  784. this.variables.M__ = snippet.matchBefore;
  785. this.variables.T__ = snippet.matchAfter;
  786. this.insertSnippetForSelection(editor, snippet.content);
  787. this.variables.M__ = this.variables.T__ = null;
  788. return true;
  789. };
  790. SnippetManager.prototype.findMatchingSnippet = function (snippetList, before, after) {
  791. for (var i = snippetList.length; i--;) {
  792. var s = snippetList[i];
  793. if (s.startRe && !s.startRe.test(before))
  794. continue;
  795. if (s.endRe && !s.endRe.test(after))
  796. continue;
  797. if (!s.startRe && !s.endRe)
  798. continue;
  799. s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
  800. s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
  801. s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
  802. s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
  803. return s;
  804. }
  805. };
  806. SnippetManager.prototype.register = function (snippets, scope) {
  807. var snippetMap = this.snippetMap;
  808. var snippetNameMap = this.snippetNameMap;
  809. var self = this;
  810. if (!snippets)
  811. snippets = [];
  812. function wrapRegexp(src) {
  813. if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
  814. src = "(?:" + src + ")";
  815. return src || "";
  816. }
  817. function guardedRegexp(re, guard, opening) {
  818. re = wrapRegexp(re);
  819. guard = wrapRegexp(guard);
  820. if (opening) {
  821. re = guard + re;
  822. if (re && re[re.length - 1] != "$")
  823. re = re + "$";
  824. }
  825. else {
  826. re = re + guard;
  827. if (re && re[0] != "^")
  828. re = "^" + re;
  829. }
  830. return new RegExp(re);
  831. }
  832. function addSnippet(s) {
  833. if (!s.scope)
  834. s.scope = scope || "_";
  835. scope = s.scope;
  836. if (!snippetMap[scope]) {
  837. snippetMap[scope] = [];
  838. snippetNameMap[scope] = {};
  839. }
  840. var map = snippetNameMap[scope];
  841. if (s.name) {
  842. var old = map[s.name];
  843. if (old)
  844. self.unregister(old);
  845. map[s.name] = s;
  846. }
  847. snippetMap[scope].push(s);
  848. if (s.prefix)
  849. s.tabTrigger = s.prefix;
  850. if (!s.content && s.body)
  851. s.content = Array.isArray(s.body) ? s.body.join("\n") : s.body;
  852. if (s.tabTrigger && !s.trigger) {
  853. if (!s.guard && /^\w/.test(s.tabTrigger))
  854. s.guard = "\\b";
  855. s.trigger = lang.escapeRegExp(s.tabTrigger);
  856. }
  857. if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard)
  858. return;
  859. s.startRe = guardedRegexp(s.trigger, s.guard, true);
  860. s.triggerRe = new RegExp(s.trigger);
  861. s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
  862. s.endTriggerRe = new RegExp(s.endTrigger);
  863. }
  864. if (Array.isArray(snippets)) {
  865. snippets.forEach(addSnippet);
  866. }
  867. else {
  868. Object.keys(snippets).forEach(function (key) {
  869. addSnippet(snippets[key]);
  870. });
  871. }
  872. this._signal("registerSnippets", { scope: scope });
  873. };
  874. SnippetManager.prototype.unregister = function (snippets, scope) {
  875. var snippetMap = this.snippetMap;
  876. var snippetNameMap = this.snippetNameMap;
  877. function removeSnippet(s) {
  878. var nameMap = snippetNameMap[s.scope || scope];
  879. if (nameMap && nameMap[s.name]) {
  880. delete nameMap[s.name];
  881. var map = snippetMap[s.scope || scope];
  882. var i = map && map.indexOf(s);
  883. if (i >= 0)
  884. map.splice(i, 1);
  885. }
  886. }
  887. if (snippets.content)
  888. removeSnippet(snippets);
  889. else if (Array.isArray(snippets))
  890. snippets.forEach(removeSnippet);
  891. };
  892. SnippetManager.prototype.parseSnippetFile = function (str) {
  893. str = str.replace(/\r/g, "");
  894. var list = [], /**@type{Snippet}*/ snippet = {};
  895. var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
  896. var m;
  897. while (m = re.exec(str)) {
  898. if (m[1]) {
  899. try {
  900. snippet = JSON.parse(m[1]);
  901. list.push(snippet);
  902. }
  903. catch (e) { }
  904. }
  905. if (m[4]) {
  906. snippet.content = m[4].replace(/^\t/gm, "");
  907. list.push(snippet);
  908. snippet = {};
  909. }
  910. else {
  911. var key = m[2], val = m[3];
  912. if (key == "regex") {
  913. var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
  914. snippet.guard = guardRe.exec(val)[1];
  915. snippet.trigger = guardRe.exec(val)[1];
  916. snippet.endTrigger = guardRe.exec(val)[1];
  917. snippet.endGuard = guardRe.exec(val)[1];
  918. }
  919. else if (key == "snippet") {
  920. snippet.tabTrigger = val.match(/^\S*/)[0];
  921. if (!snippet.name)
  922. snippet.name = val;
  923. }
  924. else if (key) {
  925. snippet[key] = val;
  926. }
  927. }
  928. }
  929. return list;
  930. };
  931. SnippetManager.prototype.getSnippetByName = function (name, editor) {
  932. var snippetMap = this.snippetNameMap;
  933. var snippet;
  934. this.getActiveScopes(editor).some(function (scope) {
  935. var snippets = snippetMap[scope];
  936. if (snippets)
  937. snippet = snippets[name];
  938. return !!snippet;
  939. }, this);
  940. return snippet;
  941. };
  942. return SnippetManager;
  943. }());
  944. oop.implement(SnippetManager.prototype, EventEmitter);
  945. var processSnippetText = function (editor, snippetText, options) {
  946. if (options === void 0) { options = {}; }
  947. var cursor = editor.getCursorPosition();
  948. var line = editor.session.getLine(cursor.row);
  949. var tabString = editor.session.getTabString();
  950. var indentString = line.match(/^\s*/)[0];
  951. if (cursor.column < indentString.length)
  952. indentString = indentString.slice(0, cursor.column);
  953. snippetText = snippetText.replace(/\r/g, "");
  954. var tokens = this.tokenizeTmSnippet(snippetText);
  955. tokens = this.resolveVariables(tokens, editor);
  956. tokens = tokens.map(function (x) {
  957. if (x == "\n" && !options.excludeExtraIndent)
  958. return x + indentString;
  959. if (typeof x == "string")
  960. return x.replace(/\t/g, tabString);
  961. return x;
  962. });
  963. var tabstops = [];
  964. tokens.forEach(function (p, i) {
  965. if (typeof p != "object")
  966. return;
  967. var id = p.tabstopId;
  968. var ts = tabstops[id];
  969. if (!ts) {
  970. ts = tabstops[id] = [];
  971. ts.index = id;
  972. ts.value = "";
  973. ts.parents = {};
  974. }
  975. if (ts.indexOf(p) !== -1)
  976. return;
  977. if (p.choices && !ts.choices)
  978. ts.choices = p.choices;
  979. ts.push(p);
  980. var i1 = tokens.indexOf(p, i + 1);
  981. if (i1 === -1)
  982. return;
  983. var value = tokens.slice(i + 1, i1);
  984. var isNested = value.some(function (t) { return typeof t === "object"; });
  985. if (isNested && !ts.value) {
  986. ts.value = value;
  987. }
  988. else if (value.length && (!ts.value || typeof ts.value !== "string")) {
  989. ts.value = value.join("");
  990. }
  991. });
  992. tabstops.forEach(function (ts) { ts.length = 0; });
  993. var expanding = {};
  994. function copyValue(val) {
  995. var copy = [];
  996. for (var i = 0; i < val.length; i++) {
  997. var p = val[i];
  998. if (typeof p == "object") {
  999. if (expanding[p.tabstopId])
  1000. continue;
  1001. var j = val.lastIndexOf(p, i - 1);
  1002. p = copy[j] || { tabstopId: p.tabstopId };
  1003. }
  1004. copy[i] = p;
  1005. }
  1006. return copy;
  1007. }
  1008. for (var i = 0; i < tokens.length; i++) {
  1009. var p = tokens[i];
  1010. if (typeof p != "object")
  1011. continue;
  1012. var id = p.tabstopId;
  1013. var ts = tabstops[id];
  1014. var i1 = tokens.indexOf(p, i + 1);
  1015. if (expanding[id]) {
  1016. if (expanding[id] === p) {
  1017. delete expanding[id];
  1018. Object.keys(expanding).forEach(function (parentId) {
  1019. ts.parents[parentId] = true;
  1020. });
  1021. }
  1022. continue;
  1023. }
  1024. expanding[id] = p;
  1025. var value = ts.value;
  1026. if (typeof value !== "string")
  1027. value = copyValue(value);
  1028. else if (p.fmt)
  1029. value = this.tmStrFormat(value, p, editor);
  1030. tokens.splice.apply(tokens, [i + 1, Math.max(0, i1 - i)].concat(value, p));
  1031. if (ts.indexOf(p) === -1)
  1032. ts.push(p);
  1033. }
  1034. var row = 0, column = 0;
  1035. var text = "";
  1036. tokens.forEach(function (t) {
  1037. if (typeof t === "string") {
  1038. var lines = t.split("\n");
  1039. if (lines.length > 1) {
  1040. column = lines[lines.length - 1].length;
  1041. row += lines.length - 1;
  1042. }
  1043. else
  1044. column += t.length;
  1045. text += t;
  1046. }
  1047. else if (t) {
  1048. if (!t.start)
  1049. t.start = { row: row, column: column };
  1050. else
  1051. t.end = { row: row, column: column };
  1052. }
  1053. });
  1054. return {
  1055. text: text,
  1056. tabstops: tabstops,
  1057. tokens: tokens
  1058. };
  1059. };
  1060. var TabstopManager = /** @class */ (function () {
  1061. function TabstopManager(editor) {
  1062. this.index = 0;
  1063. this.ranges = [];
  1064. this.tabstops = [];
  1065. if (editor.tabstopManager)
  1066. return editor.tabstopManager;
  1067. editor.tabstopManager = this;
  1068. this.$onChange = this.onChange.bind(this);
  1069. this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
  1070. this.$onChangeSession = this.onChangeSession.bind(this);
  1071. this.$onAfterExec = this.onAfterExec.bind(this);
  1072. this.attach(editor);
  1073. }
  1074. TabstopManager.prototype.attach = function (editor) {
  1075. this.$openTabstops = null;
  1076. this.selectedTabstop = null;
  1077. this.editor = editor;
  1078. this.session = editor.session;
  1079. this.editor.on("change", this.$onChange);
  1080. this.editor.on("changeSelection", this.$onChangeSelection);
  1081. this.editor.on("changeSession", this.$onChangeSession);
  1082. this.editor.commands.on("afterExec", this.$onAfterExec);
  1083. this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
  1084. };
  1085. TabstopManager.prototype.detach = function () {
  1086. this.tabstops.forEach(this.removeTabstopMarkers, this);
  1087. this.ranges.length = 0;
  1088. this.tabstops.length = 0;
  1089. this.selectedTabstop = null;
  1090. this.editor.off("change", this.$onChange);
  1091. this.editor.off("changeSelection", this.$onChangeSelection);
  1092. this.editor.off("changeSession", this.$onChangeSession);
  1093. this.editor.commands.off("afterExec", this.$onAfterExec);
  1094. this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
  1095. this.editor.tabstopManager = null;
  1096. this.session = null;
  1097. this.editor = null;
  1098. };
  1099. TabstopManager.prototype.onChange = function (delta) {
  1100. var isRemove = delta.action[0] == "r";
  1101. var selectedTabstop = this.selectedTabstop || {};
  1102. var parents = selectedTabstop.parents || {};
  1103. var tabstops = this.tabstops.slice();
  1104. for (var i = 0; i < tabstops.length; i++) {
  1105. var ts = tabstops[i];
  1106. var active = ts == selectedTabstop || parents[ts.index];
  1107. ts.rangeList.$bias = active ? 0 : 1;
  1108. if (delta.action == "remove" && ts !== selectedTabstop) {
  1109. var parentActive = ts.parents && ts.parents[selectedTabstop.index];
  1110. var startIndex = ts.rangeList.pointIndex(delta.start, parentActive);
  1111. startIndex = startIndex < 0 ? -startIndex - 1 : startIndex + 1;
  1112. var endIndex = ts.rangeList.pointIndex(delta.end, parentActive);
  1113. endIndex = endIndex < 0 ? -endIndex - 1 : endIndex - 1;
  1114. var toRemove = ts.rangeList.ranges.slice(startIndex, endIndex);
  1115. for (var j = 0; j < toRemove.length; j++)
  1116. this.removeRange(toRemove[j]);
  1117. }
  1118. ts.rangeList.$onChange(delta);
  1119. }
  1120. var session = this.session;
  1121. if (!this.$inChange && isRemove && session.getLength() == 1 && !session.getValue())
  1122. this.detach();
  1123. };
  1124. TabstopManager.prototype.updateLinkedFields = function () {
  1125. var ts = this.selectedTabstop;
  1126. if (!ts || !ts.hasLinkedRanges || !ts.firstNonLinked)
  1127. return;
  1128. this.$inChange = true;
  1129. var session = this.session;
  1130. var text = session.getTextRange(ts.firstNonLinked);
  1131. for (var i = 0; i < ts.length; i++) {
  1132. var range = ts[i];
  1133. if (!range.linked)
  1134. continue;
  1135. var original = range.original;
  1136. var fmt = exports.snippetManager.tmStrFormat(text, original, this.editor);
  1137. session.replace(range, fmt);
  1138. }
  1139. this.$inChange = false;
  1140. };
  1141. TabstopManager.prototype.onAfterExec = function (e) {
  1142. if (e.command && !e.command.readOnly)
  1143. this.updateLinkedFields();
  1144. };
  1145. TabstopManager.prototype.onChangeSelection = function () {
  1146. if (!this.editor)
  1147. return;
  1148. var lead = this.editor.selection.lead;
  1149. var anchor = this.editor.selection.anchor;
  1150. var isEmpty = this.editor.selection.isEmpty();
  1151. for (var i = 0; i < this.ranges.length; i++) {
  1152. if (this.ranges[i].linked)
  1153. continue;
  1154. var containsLead = this.ranges[i].contains(lead.row, lead.column);
  1155. var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
  1156. if (containsLead && containsAnchor)
  1157. return;
  1158. }
  1159. this.detach();
  1160. };
  1161. TabstopManager.prototype.onChangeSession = function () {
  1162. this.detach();
  1163. };
  1164. TabstopManager.prototype.tabNext = function (dir) {
  1165. var max = this.tabstops.length;
  1166. var index = this.index + (dir || 1);
  1167. index = Math.min(Math.max(index, 1), max);
  1168. if (index == max)
  1169. index = 0;
  1170. this.selectTabstop(index);
  1171. this.updateTabstopMarkers();
  1172. if (index === 0) {
  1173. this.detach();
  1174. }
  1175. };
  1176. TabstopManager.prototype.selectTabstop = function (index) {
  1177. this.$openTabstops = null;
  1178. var ts = this.tabstops[this.index];
  1179. if (ts)
  1180. this.addTabstopMarkers(ts);
  1181. this.index = index;
  1182. ts = this.tabstops[this.index];
  1183. if (!ts || !ts.length)
  1184. return;
  1185. this.selectedTabstop = ts;
  1186. var range = ts.firstNonLinked || ts;
  1187. if (ts.choices)
  1188. range.cursor = range.start;
  1189. if (!this.editor.inVirtualSelectionMode) {
  1190. var sel = this.editor.multiSelect;
  1191. sel.toSingleRange(range);
  1192. for (var i = 0; i < ts.length; i++) {
  1193. if (ts.hasLinkedRanges && ts[i].linked)
  1194. continue;
  1195. sel.addRange(ts[i].clone(), true);
  1196. }
  1197. }
  1198. else {
  1199. this.editor.selection.fromOrientedRange(range);
  1200. }
  1201. this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
  1202. if (this.selectedTabstop && this.selectedTabstop.choices)
  1203. this.editor.execCommand("startAutocomplete", { matches: this.selectedTabstop.choices });
  1204. };
  1205. TabstopManager.prototype.addTabstops = function (tabstops, start, end) {
  1206. var useLink = this.useLink || !this.editor.getOption("enableMultiselect");
  1207. if (!this.$openTabstops)
  1208. this.$openTabstops = [];
  1209. if (!tabstops[0]) {
  1210. var p = Range.fromPoints(end, end);
  1211. moveRelative(p.start, start);
  1212. moveRelative(p.end, start);
  1213. tabstops[0] = [p];
  1214. tabstops[0].index = 0;
  1215. }
  1216. var i = this.index;
  1217. var arg = [i + 1, 0];
  1218. var ranges = this.ranges;
  1219. var snippetId = this.snippetId = (this.snippetId || 0) + 1;
  1220. tabstops.forEach(function (ts, index) {
  1221. var dest = this.$openTabstops[index] || ts;
  1222. dest.snippetId = snippetId;
  1223. for (var i = 0; i < ts.length; i++) {
  1224. var p = ts[i];
  1225. var range = Range.fromPoints(p.start, p.end || p.start);
  1226. movePoint(range.start, start);
  1227. movePoint(range.end, start);
  1228. range.original = p;
  1229. range.tabstop = dest;
  1230. ranges.push(range);
  1231. if (dest != ts)
  1232. dest.unshift(range);
  1233. else
  1234. dest[i] = range;
  1235. if (p.fmtString || (dest.firstNonLinked && useLink)) {
  1236. range.linked = true;
  1237. dest.hasLinkedRanges = true;
  1238. }
  1239. else if (!dest.firstNonLinked)
  1240. dest.firstNonLinked = range;
  1241. }
  1242. if (!dest.firstNonLinked)
  1243. dest.hasLinkedRanges = false;
  1244. if (dest === ts) {
  1245. arg.push(dest);
  1246. this.$openTabstops[index] = dest;
  1247. }
  1248. this.addTabstopMarkers(dest);
  1249. dest.rangeList = dest.rangeList || new RangeList();
  1250. dest.rangeList.$bias = 0;
  1251. dest.rangeList.addList(dest);
  1252. }, this);
  1253. if (arg.length > 2) {
  1254. if (this.tabstops.length)
  1255. arg.push(arg.splice(2, 1)[0]);
  1256. this.tabstops.splice.apply(this.tabstops, arg);
  1257. }
  1258. };
  1259. TabstopManager.prototype.addTabstopMarkers = function (ts) {
  1260. var session = this.session;
  1261. ts.forEach(function (range) {
  1262. if (!range.markerId)
  1263. range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
  1264. });
  1265. };
  1266. TabstopManager.prototype.removeTabstopMarkers = function (ts) {
  1267. var session = this.session;
  1268. ts.forEach(function (range) {
  1269. session.removeMarker(range.markerId);
  1270. range.markerId = null;
  1271. });
  1272. };
  1273. TabstopManager.prototype.updateTabstopMarkers = function () {
  1274. if (!this.selectedTabstop)
  1275. return;
  1276. var currentSnippetId = this.selectedTabstop.snippetId;
  1277. if (this.selectedTabstop.index === 0) {
  1278. currentSnippetId--;
  1279. }
  1280. this.tabstops.forEach(function (ts) {
  1281. if (ts.snippetId === currentSnippetId)
  1282. this.addTabstopMarkers(ts);
  1283. else
  1284. this.removeTabstopMarkers(ts);
  1285. }, this);
  1286. };
  1287. TabstopManager.prototype.removeRange = function (range) {
  1288. var i = range.tabstop.indexOf(range);
  1289. if (i != -1)
  1290. range.tabstop.splice(i, 1);
  1291. i = this.ranges.indexOf(range);
  1292. if (i != -1)
  1293. this.ranges.splice(i, 1);
  1294. i = range.tabstop.rangeList.ranges.indexOf(range);
  1295. if (i != -1)
  1296. range.tabstop.splice(i, 1);
  1297. this.session.removeMarker(range.markerId);
  1298. if (!range.tabstop.length) {
  1299. i = this.tabstops.indexOf(range.tabstop);
  1300. if (i != -1)
  1301. this.tabstops.splice(i, 1);
  1302. if (!this.tabstops.length)
  1303. this.detach();
  1304. }
  1305. };
  1306. return TabstopManager;
  1307. }());
  1308. TabstopManager.prototype.keyboardHandler = new HashHandler();
  1309. TabstopManager.prototype.keyboardHandler.bindKeys({
  1310. "Tab": function (editor) {
  1311. if (exports.snippetManager && exports.snippetManager.expandWithTab(editor))
  1312. return;
  1313. editor.tabstopManager.tabNext(1);
  1314. editor.renderer.scrollCursorIntoView();
  1315. },
  1316. "Shift-Tab": function (editor) {
  1317. editor.tabstopManager.tabNext(-1);
  1318. editor.renderer.scrollCursorIntoView();
  1319. },
  1320. "Esc": function (editor) {
  1321. editor.tabstopManager.detach();
  1322. }
  1323. });
  1324. var movePoint = function (point, diff) {
  1325. if (point.row == 0)
  1326. point.column += diff.column;
  1327. point.row += diff.row;
  1328. };
  1329. var moveRelative = function (point, start) {
  1330. if (point.row == start.row)
  1331. point.column -= start.column;
  1332. point.row -= start.row;
  1333. };
  1334. 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);
  1335. exports.snippetManager = new SnippetManager();
  1336. var Editor = require("./editor").Editor;
  1337. (function () {
  1338. this.insertSnippet = function (content, options) {
  1339. return exports.snippetManager.insertSnippet(this, content, options);
  1340. };
  1341. this.expandSnippet = function (options) {
  1342. return exports.snippetManager.expandWithTab(this, options);
  1343. };
  1344. }).call(Editor.prototype);
  1345. });
  1346. ace.define("ace/autocomplete/inline_screenreader",["require","exports","module"], function(require, exports, module){"use strict";
  1347. var AceInlineScreenReader = /** @class */ (function () {
  1348. function AceInlineScreenReader(editor) {
  1349. this.editor = editor;
  1350. this.screenReaderDiv = document.createElement("div");
  1351. this.screenReaderDiv.classList.add("ace_screenreader-only");
  1352. this.editor.container.appendChild(this.screenReaderDiv);
  1353. }
  1354. AceInlineScreenReader.prototype.setScreenReaderContent = function (content) {
  1355. if (!this.popup && this.editor.completer && /**@type{import("../autocomplete").Autocomplete}*/ (this.editor.completer).popup) {
  1356. this.popup = /**@type{import("../autocomplete").Autocomplete}*/ (this.editor.completer).popup;
  1357. this.popup.renderer.on("afterRender", function () {
  1358. var row = this.popup.getRow();
  1359. var t = this.popup.renderer.$textLayer;
  1360. var selected = t.element.childNodes[row - t.config.firstRow];
  1361. if (selected) {
  1362. var idString = "doc-tooltip ";
  1363. for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) {
  1364. idString += "ace-inline-screenreader-line-".concat(lineIndex, " ");
  1365. }
  1366. selected.setAttribute("aria-describedby", idString);
  1367. }
  1368. }.bind(this));
  1369. }
  1370. while (this.screenReaderDiv.firstChild) {
  1371. this.screenReaderDiv.removeChild(this.screenReaderDiv.firstChild);
  1372. }
  1373. this._lines = content.split(/\r\n|\r|\n/);
  1374. var codeElement = this.createCodeBlock();
  1375. this.screenReaderDiv.appendChild(codeElement);
  1376. };
  1377. AceInlineScreenReader.prototype.destroy = function () {
  1378. this.screenReaderDiv.remove();
  1379. };
  1380. AceInlineScreenReader.prototype.createCodeBlock = function () {
  1381. var container = document.createElement("pre");
  1382. container.setAttribute("id", "ace-inline-screenreader");
  1383. for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) {
  1384. var codeElement = document.createElement("code");
  1385. codeElement.setAttribute("id", "ace-inline-screenreader-line-".concat(lineIndex));
  1386. var line = document.createTextNode(this._lines[lineIndex]);
  1387. codeElement.appendChild(line);
  1388. container.appendChild(codeElement);
  1389. }
  1390. return container;
  1391. };
  1392. return AceInlineScreenReader;
  1393. }());
  1394. exports.AceInlineScreenReader = AceInlineScreenReader;
  1395. });
  1396. ace.define("ace/autocomplete/inline",["require","exports","module","ace/snippets","ace/autocomplete/inline_screenreader"], function(require, exports, module){"use strict";
  1397. var snippetManager = require("../snippets").snippetManager;
  1398. var AceInlineScreenReader = require("./inline_screenreader").AceInlineScreenReader;
  1399. var AceInline = /** @class */ (function () {
  1400. function AceInline() {
  1401. this.editor = null;
  1402. }
  1403. AceInline.prototype.show = function (editor, completion, prefix) {
  1404. prefix = prefix || "";
  1405. if (editor && this.editor && this.editor !== editor) {
  1406. this.hide();
  1407. this.editor = null;
  1408. this.inlineScreenReader = null;
  1409. }
  1410. if (!editor || !completion) {
  1411. return false;
  1412. }
  1413. if (!this.inlineScreenReader) {
  1414. this.inlineScreenReader = new AceInlineScreenReader(editor);
  1415. }
  1416. var displayText = completion.snippet ? snippetManager.getDisplayTextForSnippet(editor, completion.snippet) : completion.value;
  1417. if (completion.hideInlinePreview || !displayText || !displayText.startsWith(prefix)) {
  1418. return false;
  1419. }
  1420. this.editor = editor;
  1421. this.inlineScreenReader.setScreenReaderContent(displayText);
  1422. displayText = displayText.slice(prefix.length);
  1423. if (displayText === "") {
  1424. editor.removeGhostText();
  1425. }
  1426. else {
  1427. editor.setGhostText(displayText);
  1428. }
  1429. return true;
  1430. };
  1431. AceInline.prototype.isOpen = function () {
  1432. if (!this.editor) {
  1433. return false;
  1434. }
  1435. return !!this.editor.renderer.$ghostText;
  1436. };
  1437. AceInline.prototype.hide = function () {
  1438. if (!this.editor) {
  1439. return false;
  1440. }
  1441. this.editor.removeGhostText();
  1442. return true;
  1443. };
  1444. AceInline.prototype.destroy = function () {
  1445. this.hide();
  1446. this.editor = null;
  1447. if (this.inlineScreenReader) {
  1448. this.inlineScreenReader.destroy();
  1449. this.inlineScreenReader = null;
  1450. }
  1451. };
  1452. return AceInline;
  1453. }());
  1454. exports.AceInline = AceInline;
  1455. });
  1456. ace.define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module){"use strict";
  1457. exports.parForEach = function (array, fn, callback) {
  1458. var completed = 0;
  1459. var arLength = array.length;
  1460. if (arLength === 0)
  1461. callback();
  1462. for (var i = 0; i < arLength; i++) {
  1463. fn(array[i], function (result, err) {
  1464. completed++;
  1465. if (completed === arLength)
  1466. callback(result, err);
  1467. });
  1468. }
  1469. };
  1470. var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\u2000\u2070-\uFFFF]/;
  1471. exports.retrievePrecedingIdentifier = function (text, pos, regex) {
  1472. regex = regex || ID_REGEX;
  1473. var buf = [];
  1474. for (var i = pos - 1; i >= 0; i--) {
  1475. if (regex.test(text[i]))
  1476. buf.push(text[i]);
  1477. else
  1478. break;
  1479. }
  1480. return buf.reverse().join("");
  1481. };
  1482. exports.retrieveFollowingIdentifier = function (text, pos, regex) {
  1483. regex = regex || ID_REGEX;
  1484. var buf = [];
  1485. for (var i = pos; i < text.length; i++) {
  1486. if (regex.test(text[i]))
  1487. buf.push(text[i]);
  1488. else
  1489. break;
  1490. }
  1491. return buf;
  1492. };
  1493. exports.getCompletionPrefix = function (editor) {
  1494. var pos = editor.getCursorPosition();
  1495. var line = editor.session.getLine(pos.row);
  1496. var prefix;
  1497. editor.completers.forEach(function (completer) {
  1498. if (completer.identifierRegexps) {
  1499. completer.identifierRegexps.forEach(function (identifierRegex) {
  1500. if (!prefix && identifierRegex)
  1501. prefix = this.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
  1502. }.bind(this));
  1503. }
  1504. }.bind(this));
  1505. return prefix || this.retrievePrecedingIdentifier(line, pos.column);
  1506. };
  1507. exports.triggerAutocomplete = function (editor, previousChar) {
  1508. var previousChar = previousChar == null
  1509. ? editor.session.getPrecedingCharacter()
  1510. : previousChar;
  1511. return editor.completers.some(function (completer) {
  1512. if (completer.triggerCharacters && Array.isArray(completer.triggerCharacters)) {
  1513. return completer.triggerCharacters.includes(previousChar);
  1514. }
  1515. });
  1516. };
  1517. });
  1518. 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";
  1519. var HashHandler = require("./keyboard/hash_handler").HashHandler;
  1520. var AcePopup = require("./autocomplete/popup").AcePopup;
  1521. var AceInline = require("./autocomplete/inline").AceInline;
  1522. var getAriaId = require("./autocomplete/popup").getAriaId;
  1523. var util = require("./autocomplete/util");
  1524. var lang = require("./lib/lang");
  1525. var dom = require("./lib/dom");
  1526. var snippetManager = require("./snippets").snippetManager;
  1527. var config = require("./config");
  1528. var event = require("./lib/event");
  1529. var preventParentScroll = require("./lib/scroll").preventParentScroll;
  1530. var destroyCompleter = function (e, editor) {
  1531. editor.completer && editor.completer.destroy();
  1532. };
  1533. var Autocomplete = /** @class */ (function () {
  1534. function Autocomplete() {
  1535. this.autoInsert = false;
  1536. this.autoSelect = true;
  1537. this.autoShown = false;
  1538. this.exactMatch = false;
  1539. this.inlineEnabled = false;
  1540. this.keyboardHandler = new HashHandler();
  1541. this.keyboardHandler.bindKeys(this.commands);
  1542. this.parentNode = null;
  1543. this.setSelectOnHover = false;
  1544. this.hasSeen = new Set();
  1545. this.showLoadingState = false;
  1546. this.stickySelectionDelay = 500;
  1547. this.blurListener = this.blurListener.bind(this);
  1548. this.changeListener = this.changeListener.bind(this);
  1549. this.mousedownListener = this.mousedownListener.bind(this);
  1550. this.mousewheelListener = this.mousewheelListener.bind(this);
  1551. this.onLayoutChange = this.onLayoutChange.bind(this);
  1552. this.changeTimer = lang.delayedCall(function () {
  1553. this.updateCompletions(true);
  1554. }.bind(this));
  1555. this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50);
  1556. this.popupTimer = lang.delayedCall(this.$updatePopupPosition.bind(this), 50);
  1557. this.stickySelectionTimer = lang.delayedCall(function () {
  1558. this.stickySelection = true;
  1559. }.bind(this), this.stickySelectionDelay);
  1560. this.$firstOpenTimer = lang.delayedCall(/**@this{Autocomplete}*/ function () {
  1561. var initialPosition = this.completionProvider && this.completionProvider.initialPosition;
  1562. if (this.autoShown || (this.popup && this.popup.isOpen) || !initialPosition || this.editor.completers.length === 0)
  1563. return;
  1564. this.completions = new FilteredList(Autocomplete.completionsForLoading);
  1565. this.openPopup(this.editor, initialPosition.prefix, false);
  1566. this.popup.renderer.setStyle("ace_loading", true);
  1567. }.bind(this), this.stickySelectionDelay);
  1568. }
  1569. Object.defineProperty(Autocomplete, "completionsForLoading", {
  1570. get: function () {
  1571. return [{
  1572. caption: config.nls("autocomplete.loading", "Loading..."),
  1573. value: ""
  1574. }];
  1575. },
  1576. enumerable: false,
  1577. configurable: true
  1578. });
  1579. Autocomplete.prototype.$init = function () {
  1580. this.popup = new AcePopup(this.parentNode || document.body || document.documentElement);
  1581. this.popup.on("click", function (e) {
  1582. this.insertMatch();
  1583. e.stop();
  1584. }.bind(this));
  1585. this.popup.focus = this.editor.focus.bind(this.editor);
  1586. this.popup.on("show", this.$onPopupShow.bind(this));
  1587. this.popup.on("hide", this.$onHidePopup.bind(this));
  1588. this.popup.on("select", this.$onPopupChange.bind(this));
  1589. event.addListener(this.popup.container, "mouseout", this.mouseOutListener.bind(this));
  1590. this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null));
  1591. this.popup.renderer.on("afterRender", this.$onPopupRender.bind(this));
  1592. return this.popup;
  1593. };
  1594. Autocomplete.prototype.$initInline = function () {
  1595. if (!this.inlineEnabled || this.inlineRenderer)
  1596. return;
  1597. this.inlineRenderer = new AceInline();
  1598. return this.inlineRenderer;
  1599. };
  1600. Autocomplete.prototype.getPopup = function () {
  1601. return this.popup || this.$init();
  1602. };
  1603. Autocomplete.prototype.$onHidePopup = function () {
  1604. if (this.inlineRenderer) {
  1605. this.inlineRenderer.hide();
  1606. }
  1607. this.hideDocTooltip();
  1608. this.stickySelectionTimer.cancel();
  1609. this.popupTimer.cancel();
  1610. this.stickySelection = false;
  1611. };
  1612. Autocomplete.prototype.$seen = function (completion) {
  1613. if (!this.hasSeen.has(completion) && completion && completion.completer && completion.completer.onSeen && typeof completion.completer.onSeen === "function") {
  1614. completion.completer.onSeen(this.editor, completion);
  1615. this.hasSeen.add(completion);
  1616. }
  1617. };
  1618. Autocomplete.prototype.$onPopupChange = function (hide) {
  1619. if (this.inlineRenderer && this.inlineEnabled) {
  1620. var completion = hide ? null : this.popup.getData(this.popup.getRow());
  1621. this.$updateGhostText(completion);
  1622. if (this.popup.isMouseOver && this.setSelectOnHover) {
  1623. this.tooltipTimer.call(null, null);
  1624. return;
  1625. }
  1626. this.popupTimer.schedule();
  1627. this.tooltipTimer.schedule();
  1628. }
  1629. else {
  1630. this.popupTimer.call(null, null);
  1631. this.tooltipTimer.call(null, null);
  1632. }
  1633. };
  1634. Autocomplete.prototype.$updateGhostText = function (completion) {
  1635. var row = this.base.row;
  1636. var column = this.base.column;
  1637. var cursorColumn = this.editor.getCursorPosition().column;
  1638. var prefix = this.editor.session.getLine(row).slice(column, cursorColumn);
  1639. if (!this.inlineRenderer.show(this.editor, completion, prefix)) {
  1640. this.inlineRenderer.hide();
  1641. }
  1642. else {
  1643. this.$seen(completion);
  1644. }
  1645. };
  1646. Autocomplete.prototype.$onPopupRender = function () {
  1647. var inlineEnabled = this.inlineRenderer && this.inlineEnabled;
  1648. if (this.completions && this.completions.filtered && this.completions.filtered.length > 0) {
  1649. for (var i = this.popup.getFirstVisibleRow(); i <= this.popup.getLastVisibleRow(); i++) {
  1650. var completion = this.popup.getData(i);
  1651. if (completion && (!inlineEnabled || completion.hideInlinePreview)) {
  1652. this.$seen(completion);
  1653. }
  1654. }
  1655. }
  1656. };
  1657. Autocomplete.prototype.$onPopupShow = function (hide) {
  1658. this.$onPopupChange(hide);
  1659. this.stickySelection = false;
  1660. if (this.stickySelectionDelay >= 0)
  1661. this.stickySelectionTimer.schedule(this.stickySelectionDelay);
  1662. };
  1663. Autocomplete.prototype.observeLayoutChanges = function () {
  1664. if (this.$elements || !this.editor)
  1665. return;
  1666. window.addEventListener("resize", this.onLayoutChange, { passive: true });
  1667. window.addEventListener("wheel", this.mousewheelListener);
  1668. var el = this.editor.container.parentNode;
  1669. var elements = [];
  1670. while (el) {
  1671. elements.push(el);
  1672. el.addEventListener("scroll", this.onLayoutChange, { passive: true });
  1673. el = el.parentNode;
  1674. }
  1675. this.$elements = elements;
  1676. };
  1677. Autocomplete.prototype.unObserveLayoutChanges = function () {
  1678. var _this = this;
  1679. window.removeEventListener("resize", this.onLayoutChange, { passive: true });
  1680. window.removeEventListener("wheel", this.mousewheelListener);
  1681. this.$elements && this.$elements.forEach(function (el) {
  1682. el.removeEventListener("scroll", _this.onLayoutChange, { passive: true });
  1683. });
  1684. this.$elements = null;
  1685. };
  1686. Autocomplete.prototype.onLayoutChange = function () {
  1687. if (!this.popup.isOpen)
  1688. return this.unObserveLayoutChanges();
  1689. this.$updatePopupPosition();
  1690. this.updateDocTooltip();
  1691. };
  1692. Autocomplete.prototype.$updatePopupPosition = function () {
  1693. var editor = this.editor;
  1694. var renderer = editor.renderer;
  1695. var lineHeight = renderer.layerConfig.lineHeight;
  1696. var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
  1697. pos.left -= this.popup.getTextLeftOffset();
  1698. var rect = editor.container.getBoundingClientRect();
  1699. pos.top += rect.top - renderer.layerConfig.offset;
  1700. pos.left += rect.left - editor.renderer.scrollLeft;
  1701. pos.left += renderer.gutterWidth;
  1702. var posGhostText = {
  1703. top: pos.top,
  1704. left: pos.left
  1705. };
  1706. if (renderer.$ghostText && renderer.$ghostTextWidget) {
  1707. if (this.base.row === renderer.$ghostText.position.row) {
  1708. posGhostText.top += renderer.$ghostTextWidget.el.offsetHeight;
  1709. }
  1710. }
  1711. var editorContainerBottom = editor.container.getBoundingClientRect().bottom - lineHeight;
  1712. var lowestPosition = editorContainerBottom < posGhostText.top ?
  1713. { top: editorContainerBottom, left: posGhostText.left } :
  1714. posGhostText;
  1715. if (this.popup.tryShow(lowestPosition, lineHeight, "bottom")) {
  1716. return;
  1717. }
  1718. if (this.popup.tryShow(pos, lineHeight, "top")) {
  1719. return;
  1720. }
  1721. this.popup.show(pos, lineHeight);
  1722. };
  1723. Autocomplete.prototype.openPopup = function (editor, prefix, keepPopupPosition) {
  1724. this.$firstOpenTimer.cancel();
  1725. if (!this.popup)
  1726. this.$init();
  1727. if (this.inlineEnabled && !this.inlineRenderer)
  1728. this.$initInline();
  1729. this.popup.autoSelect = this.autoSelect;
  1730. this.popup.setSelectOnHover(this.setSelectOnHover);
  1731. var oldRow = this.popup.getRow();
  1732. var previousSelectedItem = this.popup.data[oldRow];
  1733. this.popup.setData(this.completions.filtered, this.completions.filterText);
  1734. if (this.editor.textInput.setAriaOptions) {
  1735. this.editor.textInput.setAriaOptions({
  1736. activeDescendant: getAriaId(this.popup.getRow()),
  1737. inline: this.inlineEnabled
  1738. });
  1739. }
  1740. editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
  1741. var newRow;
  1742. if (this.stickySelection)
  1743. newRow = this.popup.data.indexOf(previousSelectedItem);
  1744. if (!newRow || newRow === -1)
  1745. newRow = 0;
  1746. this.popup.setRow(this.autoSelect ? newRow : -1);
  1747. if (newRow === oldRow && previousSelectedItem !== this.completions.filtered[newRow])
  1748. this.$onPopupChange();
  1749. var inlineEnabled = this.inlineRenderer && this.inlineEnabled;
  1750. if (newRow === oldRow && inlineEnabled) {
  1751. var completion = this.popup.getData(this.popup.getRow());
  1752. this.$updateGhostText(completion);
  1753. }
  1754. if (!keepPopupPosition) {
  1755. this.popup.setTheme(editor.getTheme());
  1756. this.popup.setFontSize(editor.getFontSize());
  1757. this.$updatePopupPosition();
  1758. if (this.tooltipNode) {
  1759. this.updateDocTooltip();
  1760. }
  1761. }
  1762. this.changeTimer.cancel();
  1763. this.observeLayoutChanges();
  1764. };
  1765. Autocomplete.prototype.detach = function () {
  1766. if (this.editor) {
  1767. this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
  1768. this.editor.off("changeSelection", this.changeListener);
  1769. this.editor.off("blur", this.blurListener);
  1770. this.editor.off("mousedown", this.mousedownListener);
  1771. this.editor.off("mousewheel", this.mousewheelListener);
  1772. }
  1773. this.$firstOpenTimer.cancel();
  1774. this.changeTimer.cancel();
  1775. this.hideDocTooltip();
  1776. if (this.completionProvider) {
  1777. this.completionProvider.detach();
  1778. }
  1779. if (this.popup && this.popup.isOpen)
  1780. this.popup.hide();
  1781. if (this.popup && this.popup.renderer) {
  1782. this.popup.renderer.off("afterRender", this.$onPopupRender);
  1783. }
  1784. if (this.base)
  1785. this.base.detach();
  1786. this.activated = false;
  1787. this.completionProvider = this.completions = this.base = null;
  1788. this.unObserveLayoutChanges();
  1789. };
  1790. Autocomplete.prototype.changeListener = function (e) {
  1791. var cursor = this.editor.selection.lead;
  1792. if (cursor.row != this.base.row || cursor.column < this.base.column) {
  1793. this.detach();
  1794. }
  1795. if (this.activated)
  1796. this.changeTimer.schedule();
  1797. else
  1798. this.detach();
  1799. };
  1800. Autocomplete.prototype.blurListener = function (e) {
  1801. var el = document.activeElement;
  1802. var text = this.editor.textInput.getElement();
  1803. var fromTooltip = e.relatedTarget && this.tooltipNode && this.tooltipNode.contains(e.relatedTarget);
  1804. var container = this.popup && this.popup.container;
  1805. if (el != text && el.parentNode != container && !fromTooltip
  1806. && el != this.tooltipNode && e.relatedTarget != text) {
  1807. this.detach();
  1808. }
  1809. };
  1810. Autocomplete.prototype.mousedownListener = function (e) {
  1811. this.detach();
  1812. };
  1813. Autocomplete.prototype.mousewheelListener = function (e) {
  1814. if (this.popup && !this.popup.isMouseOver)
  1815. this.detach();
  1816. };
  1817. Autocomplete.prototype.mouseOutListener = function (e) {
  1818. if (this.popup.isOpen)
  1819. this.$updatePopupPosition();
  1820. };
  1821. Autocomplete.prototype.goTo = function (where) {
  1822. this.popup.goTo(where);
  1823. };
  1824. Autocomplete.prototype.insertMatch = function (data, options) {
  1825. if (!data)
  1826. data = this.popup.getData(this.popup.getRow());
  1827. if (!data)
  1828. return false;
  1829. if (data.value === "") // Explicitly given nothing to insert, e.g. "No suggestion state"
  1830. return this.detach();
  1831. var completions = this.completions;
  1832. var result = this.getCompletionProvider().insertMatch(this.editor, data, completions.filterText, options);
  1833. if (this.completions == completions)
  1834. this.detach();
  1835. return result;
  1836. };
  1837. Autocomplete.prototype.showPopup = function (editor, options) {
  1838. if (this.editor)
  1839. this.detach();
  1840. this.activated = true;
  1841. this.editor = editor;
  1842. if (editor.completer != this) {
  1843. if (editor.completer)
  1844. editor.completer.detach();
  1845. editor.completer = this;
  1846. }
  1847. editor.on("changeSelection", this.changeListener);
  1848. editor.on("blur", this.blurListener);
  1849. editor.on("mousedown", this.mousedownListener);
  1850. editor.on("mousewheel", this.mousewheelListener);
  1851. this.updateCompletions(false, options);
  1852. };
  1853. Autocomplete.prototype.getCompletionProvider = function (initialPosition) {
  1854. if (!this.completionProvider)
  1855. this.completionProvider = new CompletionProvider(initialPosition);
  1856. return this.completionProvider;
  1857. };
  1858. Autocomplete.prototype.gatherCompletions = function (editor, callback) {
  1859. return this.getCompletionProvider().gatherCompletions(editor, callback);
  1860. };
  1861. Autocomplete.prototype.updateCompletions = function (keepPopupPosition, options) {
  1862. if (keepPopupPosition && this.base && this.completions) {
  1863. var pos = this.editor.getCursorPosition();
  1864. var prefix = this.editor.session.getTextRange({ start: this.base, end: pos });
  1865. if (prefix == this.completions.filterText)
  1866. return;
  1867. this.completions.setFilter(prefix);
  1868. if (!this.completions.filtered.length)
  1869. return this.detach();
  1870. if (this.completions.filtered.length == 1
  1871. && this.completions.filtered[0].value == prefix
  1872. && !this.completions.filtered[0].snippet)
  1873. return this.detach();
  1874. this.openPopup(this.editor, prefix, keepPopupPosition);
  1875. return;
  1876. }
  1877. if (options && options.matches) {
  1878. var pos = this.editor.getSelectionRange().start;
  1879. this.base = this.editor.session.doc.createAnchor(pos.row, pos.column);
  1880. this.base.$insertRight = true;
  1881. this.completions = new FilteredList(options.matches);
  1882. this.getCompletionProvider().completions = this.completions;
  1883. return this.openPopup(this.editor, "", keepPopupPosition);
  1884. }
  1885. var session = this.editor.getSession();
  1886. var pos = this.editor.getCursorPosition();
  1887. var prefix = util.getCompletionPrefix(this.editor);
  1888. this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
  1889. this.base.$insertRight = true;
  1890. var completionOptions = {
  1891. exactMatch: this.exactMatch,
  1892. ignoreCaption: this.ignoreCaption
  1893. };
  1894. this.getCompletionProvider({
  1895. prefix: prefix,
  1896. pos: pos
  1897. }).provideCompletions(this.editor, completionOptions,
  1898. function (err, completions, finished) {
  1899. var filtered = completions.filtered;
  1900. var prefix = util.getCompletionPrefix(this.editor);
  1901. this.$firstOpenTimer.cancel();
  1902. if (finished) {
  1903. if (!filtered.length) {
  1904. var emptyMessage = !this.autoShown && this.emptyMessage;
  1905. if (typeof emptyMessage == "function")
  1906. emptyMessage = this.emptyMessage(prefix);
  1907. if (emptyMessage) {
  1908. var completionsForEmpty = [{
  1909. caption: emptyMessage,
  1910. value: ""
  1911. }
  1912. ];
  1913. this.completions = new FilteredList(completionsForEmpty);
  1914. this.openPopup(this.editor, prefix, keepPopupPosition);
  1915. this.popup.renderer.setStyle("ace_loading", false);
  1916. this.popup.renderer.setStyle("ace_empty-message", true);
  1917. return;
  1918. }
  1919. return this.detach();
  1920. }
  1921. if (filtered.length == 1 && filtered[0].value == prefix
  1922. && !filtered[0].snippet)
  1923. return this.detach();
  1924. if (this.autoInsert && !this.autoShown && filtered.length == 1)
  1925. return this.insertMatch(filtered[0]);
  1926. }
  1927. this.completions = !finished && this.showLoadingState ?
  1928. new FilteredList(Autocomplete.completionsForLoading.concat(filtered), completions.filterText) :
  1929. completions;
  1930. this.openPopup(this.editor, prefix, keepPopupPosition);
  1931. this.popup.renderer.setStyle("ace_empty-message", false);
  1932. this.popup.renderer.setStyle("ace_loading", !finished);
  1933. }.bind(this));
  1934. if (this.showLoadingState && !this.autoShown && !(this.popup && this.popup.isOpen)) {
  1935. this.$firstOpenTimer.delay(this.stickySelectionDelay / 2);
  1936. }
  1937. };
  1938. Autocomplete.prototype.cancelContextMenu = function () {
  1939. this.editor.$mouseHandler.cancelContextMenu();
  1940. };
  1941. Autocomplete.prototype.updateDocTooltip = function () {
  1942. var popup = this.popup;
  1943. var all = this.completions && this.completions.filtered;
  1944. var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]);
  1945. var doc = null;
  1946. if (!selected || !this.editor || !this.popup.isOpen)
  1947. return this.hideDocTooltip();
  1948. var completersLength = this.editor.completers.length;
  1949. for (var i = 0; i < completersLength; i++) {
  1950. var completer = this.editor.completers[i];
  1951. if (completer.getDocTooltip && selected.completerId === completer.id) {
  1952. doc = completer.getDocTooltip(selected);
  1953. break;
  1954. }
  1955. }
  1956. if (!doc && typeof selected != "string")
  1957. doc = selected;
  1958. if (typeof doc == "string")
  1959. doc = { docText: doc };
  1960. if (!doc || !(doc.docHTML || doc.docText))
  1961. return this.hideDocTooltip();
  1962. this.showDocTooltip(doc);
  1963. };
  1964. Autocomplete.prototype.showDocTooltip = function (item) {
  1965. if (!this.tooltipNode) {
  1966. this.tooltipNode = dom.createElement("div");
  1967. this.tooltipNode.style.margin = "0";
  1968. this.tooltipNode.style.pointerEvents = "auto";
  1969. this.tooltipNode.style.overscrollBehavior = "contain";
  1970. this.tooltipNode.tabIndex = -1;
  1971. this.tooltipNode.onblur = this.blurListener.bind(this);
  1972. this.tooltipNode.onclick = this.onTooltipClick.bind(this);
  1973. this.tooltipNode.id = "doc-tooltip";
  1974. this.tooltipNode.setAttribute("role", "tooltip");
  1975. this.tooltipNode.addEventListener("wheel", preventParentScroll);
  1976. }
  1977. var theme = this.editor.renderer.theme;
  1978. this.tooltipNode.className = "ace_tooltip ace_doc-tooltip " +
  1979. (theme.isDark ? "ace_dark " : "") + (theme.cssClass || "");
  1980. var tooltipNode = this.tooltipNode;
  1981. if (item.docHTML) {
  1982. tooltipNode.innerHTML = item.docHTML;
  1983. }
  1984. else if (item.docText) {
  1985. tooltipNode.textContent = item.docText;
  1986. }
  1987. if (!tooltipNode.parentNode)
  1988. this.popup.container.appendChild(this.tooltipNode);
  1989. var popup = this.popup;
  1990. var rect = popup.container.getBoundingClientRect();
  1991. var targetWidth = 400;
  1992. var targetHeight = 300;
  1993. var scrollBarSize = popup.renderer.scrollBar.width || 10;
  1994. var leftSize = rect.left;
  1995. var rightSize = window.innerWidth - rect.right - scrollBarSize;
  1996. var topSize = popup.isTopdown ? rect.top : window.innerHeight - scrollBarSize - rect.bottom;
  1997. var scores = [
  1998. Math.min(rightSize / targetWidth, 1),
  1999. Math.min(leftSize / targetWidth, 1),
  2000. Math.min(topSize / targetHeight * 0.9),
  2001. ];
  2002. var max = Math.max.apply(Math, scores);
  2003. var tooltipStyle = tooltipNode.style;
  2004. tooltipStyle.display = "block";
  2005. if (max == scores[0]) {
  2006. tooltipStyle.left = (rect.right + 1) + "px";
  2007. tooltipStyle.right = "";
  2008. tooltipStyle.maxWidth = targetWidth * max + "px";
  2009. tooltipStyle.top = rect.top + "px";
  2010. tooltipStyle.bottom = "";
  2011. tooltipStyle.maxHeight = Math.min(window.innerHeight - scrollBarSize - rect.top, targetHeight) + "px";
  2012. }
  2013. else if (max == scores[1]) {
  2014. tooltipStyle.right = window.innerWidth - rect.left + "px";
  2015. tooltipStyle.left = "";
  2016. tooltipStyle.maxWidth = targetWidth * max + "px";
  2017. tooltipStyle.top = rect.top + "px";
  2018. tooltipStyle.bottom = "";
  2019. tooltipStyle.maxHeight = Math.min(window.innerHeight - scrollBarSize - rect.top, targetHeight) + "px";
  2020. }
  2021. else if (max == scores[2]) {
  2022. tooltipStyle.left = window.innerWidth - rect.left + "px";
  2023. tooltipStyle.maxWidth = Math.min(targetWidth, window.innerWidth) + "px";
  2024. if (popup.isTopdown) {
  2025. tooltipStyle.top = rect.bottom + "px";
  2026. tooltipStyle.left = rect.left + "px";
  2027. tooltipStyle.right = "";
  2028. tooltipStyle.bottom = "";
  2029. tooltipStyle.maxHeight = Math.min(window.innerHeight - scrollBarSize - rect.bottom, targetHeight) + "px";
  2030. }
  2031. else {
  2032. tooltipStyle.top = popup.container.offsetTop - tooltipNode.offsetHeight + "px";
  2033. tooltipStyle.left = rect.left + "px";
  2034. tooltipStyle.right = "";
  2035. tooltipStyle.bottom = "";
  2036. tooltipStyle.maxHeight = Math.min(popup.container.offsetTop, targetHeight) + "px";
  2037. }
  2038. }
  2039. };
  2040. Autocomplete.prototype.hideDocTooltip = function () {
  2041. this.tooltipTimer.cancel();
  2042. if (!this.tooltipNode)
  2043. return;
  2044. var el = this.tooltipNode;
  2045. if (!this.editor.isFocused() && document.activeElement == el)
  2046. this.editor.focus();
  2047. this.tooltipNode = null;
  2048. if (el.parentNode)
  2049. el.parentNode.removeChild(el);
  2050. };
  2051. Autocomplete.prototype.onTooltipClick = function (e) {
  2052. var a = e.target;
  2053. while (a && a != this.tooltipNode) {
  2054. if (a.nodeName == "A" && a.href) {
  2055. a.rel = "noreferrer";
  2056. a.target = "_blank";
  2057. break;
  2058. }
  2059. a = a.parentNode;
  2060. }
  2061. };
  2062. Autocomplete.prototype.destroy = function () {
  2063. this.detach();
  2064. if (this.popup) {
  2065. this.popup.destroy();
  2066. var el = this.popup.container;
  2067. if (el && el.parentNode)
  2068. el.parentNode.removeChild(el);
  2069. }
  2070. if (this.editor && this.editor.completer == this) {
  2071. this.editor.off("destroy", destroyCompleter);
  2072. this.editor.completer = null;
  2073. }
  2074. this.inlineRenderer = this.popup = this.editor = null;
  2075. };
  2076. Autocomplete.for = function (editor) {
  2077. if (editor.completer instanceof Autocomplete) {
  2078. return editor.completer;
  2079. }
  2080. if (editor.completer) {
  2081. editor.completer.destroy();
  2082. editor.completer = null;
  2083. }
  2084. if (config.get("sharedPopups")) {
  2085. if (!Autocomplete["$sharedInstance"])
  2086. Autocomplete["$sharedInstance"] = new Autocomplete();
  2087. editor.completer = Autocomplete["$sharedInstance"];
  2088. }
  2089. else {
  2090. editor.completer = new Autocomplete();
  2091. editor.once("destroy", destroyCompleter);
  2092. }
  2093. return editor.completer;
  2094. };
  2095. return Autocomplete;
  2096. }());
  2097. Autocomplete.prototype.commands = {
  2098. "Up": function (editor) { editor.completer.goTo("up"); },
  2099. "Down": function (editor) { editor.completer.goTo("down"); },
  2100. "Ctrl-Up|Ctrl-Home": function (editor) { editor.completer.goTo("start"); },
  2101. "Ctrl-Down|Ctrl-End": function (editor) { editor.completer.goTo("end"); },
  2102. "Esc": function (editor) { editor.completer.detach(); },
  2103. "Return": function (editor) { return editor.completer.insertMatch(); },
  2104. "Shift-Return": function (editor) { editor.completer.insertMatch(null, { deleteSuffix: true }); },
  2105. "Tab": function (editor) {
  2106. var result = editor.completer.insertMatch();
  2107. if (!result && !editor.tabstopManager)
  2108. editor.completer.goTo("down");
  2109. else
  2110. return result;
  2111. },
  2112. "Backspace": function (editor) {
  2113. editor.execCommand("backspace");
  2114. var prefix = util.getCompletionPrefix(editor);
  2115. if (!prefix && editor.completer)
  2116. editor.completer.detach();
  2117. },
  2118. "PageUp": function (editor) { editor.completer.popup.gotoPageUp(); },
  2119. "PageDown": function (editor) { editor.completer.popup.gotoPageDown(); }
  2120. };
  2121. Autocomplete.startCommand = {
  2122. name: "startAutocomplete",
  2123. exec: function (editor, options) {
  2124. var completer = Autocomplete.for(editor);
  2125. completer.autoInsert = false;
  2126. completer.autoSelect = true;
  2127. completer.autoShown = false;
  2128. completer.showPopup(editor, options);
  2129. completer.cancelContextMenu();
  2130. },
  2131. bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
  2132. };
  2133. var CompletionProvider = /** @class */ (function () {
  2134. function CompletionProvider(initialPosition) {
  2135. this.initialPosition = initialPosition;
  2136. this.active = true;
  2137. }
  2138. CompletionProvider.prototype.insertByIndex = function (editor, index, options) {
  2139. if (!this.completions || !this.completions.filtered) {
  2140. return false;
  2141. }
  2142. return this.insertMatch(editor, this.completions.filtered[index], options);
  2143. };
  2144. CompletionProvider.prototype.insertMatch = function (editor, data, options) {
  2145. if (!data)
  2146. return false;
  2147. editor.startOperation({ command: { name: "insertMatch" } });
  2148. if (data.completer && data.completer.insertMatch) {
  2149. data.completer.insertMatch(editor, data);
  2150. }
  2151. else {
  2152. if (!this.completions)
  2153. return false;
  2154. var replaceBefore = this.completions.filterText.length;
  2155. var replaceAfter = 0;
  2156. if (data.range && data.range.start.row === data.range.end.row) {
  2157. replaceBefore -= this.initialPosition.prefix.length;
  2158. replaceBefore += this.initialPosition.pos.column - data.range.start.column;
  2159. replaceAfter += data.range.end.column - this.initialPosition.pos.column;
  2160. }
  2161. if (replaceBefore || replaceAfter) {
  2162. var ranges;
  2163. if (editor.selection.getAllRanges) {
  2164. ranges = editor.selection.getAllRanges();
  2165. }
  2166. else {
  2167. ranges = [editor.getSelectionRange()];
  2168. }
  2169. for (var i = 0, range; range = ranges[i]; i++) {
  2170. range.start.column -= replaceBefore;
  2171. range.end.column += replaceAfter;
  2172. editor.session.remove(range);
  2173. }
  2174. }
  2175. if (data.snippet) {
  2176. snippetManager.insertSnippet(editor, data.snippet);
  2177. }
  2178. else {
  2179. this.$insertString(editor, data);
  2180. }
  2181. if (data.completer && data.completer.onInsert && typeof data.completer.onInsert == "function") {
  2182. data.completer.onInsert(editor, data);
  2183. }
  2184. if (data.command && data.command === "startAutocomplete") {
  2185. editor.execCommand(data.command);
  2186. }
  2187. }
  2188. editor.endOperation();
  2189. return true;
  2190. };
  2191. CompletionProvider.prototype.$insertString = function (editor, data) {
  2192. var text = data.value || data;
  2193. editor.execCommand("insertstring", text);
  2194. };
  2195. CompletionProvider.prototype.gatherCompletions = function (editor, callback) {
  2196. var session = editor.getSession();
  2197. var pos = editor.getCursorPosition();
  2198. var prefix = util.getCompletionPrefix(editor);
  2199. var matches = [];
  2200. this.completers = editor.completers;
  2201. var total = editor.completers.length;
  2202. editor.completers.forEach(function (completer, i) {
  2203. completer.getCompletions(editor, session, pos, prefix, function (err, results) {
  2204. if (completer.hideInlinePreview)
  2205. results = results.map(function (result) {
  2206. return Object.assign(result, { hideInlinePreview: completer.hideInlinePreview });
  2207. });
  2208. if (!err && results)
  2209. matches = matches.concat(results);
  2210. callback(null, {
  2211. prefix: util.getCompletionPrefix(editor),
  2212. matches: matches,
  2213. finished: (--total === 0)
  2214. });
  2215. });
  2216. });
  2217. return true;
  2218. };
  2219. CompletionProvider.prototype.provideCompletions = function (editor, options, callback) {
  2220. var processResults = function (results) {
  2221. var prefix = results.prefix;
  2222. var matches = results.matches;
  2223. this.completions = new FilteredList(matches);
  2224. if (options.exactMatch)
  2225. this.completions.exactMatch = true;
  2226. if (options.ignoreCaption)
  2227. this.completions.ignoreCaption = true;
  2228. this.completions.setFilter(prefix);
  2229. if (results.finished || this.completions.filtered.length)
  2230. callback(null, this.completions, results.finished);
  2231. }.bind(this);
  2232. var isImmediate = true;
  2233. var immediateResults = null;
  2234. this.gatherCompletions(editor, function (err, results) {
  2235. if (!this.active) {
  2236. return;
  2237. }
  2238. if (err) {
  2239. callback(err, [], true);
  2240. this.detach();
  2241. }
  2242. var prefix = results.prefix;
  2243. if (prefix.indexOf(results.prefix) !== 0)
  2244. return;
  2245. if (isImmediate) {
  2246. immediateResults = results;
  2247. return;
  2248. }
  2249. processResults(results);
  2250. }.bind(this));
  2251. isImmediate = false;
  2252. if (immediateResults) {
  2253. var results = immediateResults;
  2254. immediateResults = null;
  2255. processResults(results);
  2256. }
  2257. };
  2258. CompletionProvider.prototype.detach = function () {
  2259. this.active = false;
  2260. this.completers && this.completers.forEach(function (completer) {
  2261. if (typeof completer.cancel === "function") {
  2262. completer.cancel();
  2263. }
  2264. });
  2265. };
  2266. return CompletionProvider;
  2267. }());
  2268. var FilteredList = /** @class */ (function () {
  2269. function FilteredList(array, filterText) {
  2270. this.all = array;
  2271. this.filtered = array;
  2272. this.filterText = filterText || "";
  2273. this.exactMatch = false;
  2274. this.ignoreCaption = false;
  2275. }
  2276. FilteredList.prototype.setFilter = function (str) {
  2277. if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
  2278. var matches = this.filtered;
  2279. else
  2280. var matches = this.all;
  2281. this.filterText = str;
  2282. matches = this.filterCompletions(matches, this.filterText);
  2283. matches = matches.sort(function (a, b) {
  2284. return b.exactMatch - a.exactMatch || b.$score - a.$score
  2285. || (a.caption || a.value).localeCompare(b.caption || b.value);
  2286. });
  2287. var prev = null;
  2288. matches = matches.filter(function (item) {
  2289. var caption = item.snippet || item.caption || item.value;
  2290. if (caption === prev)
  2291. return false;
  2292. prev = caption;
  2293. return true;
  2294. });
  2295. this.filtered = matches;
  2296. };
  2297. FilteredList.prototype.filterCompletions = function (items, needle) {
  2298. var results = [];
  2299. var upper = needle.toUpperCase();
  2300. var lower = needle.toLowerCase();
  2301. loop: for (var i = 0, item; item = items[i]; i++) {
  2302. if (item.skipFilter) {
  2303. item.$score = item.score;
  2304. results.push(item);
  2305. continue;
  2306. }
  2307. var caption = (!this.ignoreCaption && item.caption) || item.value || item.snippet;
  2308. if (!caption)
  2309. continue;
  2310. var lastIndex = -1;
  2311. var matchMask = 0;
  2312. var penalty = 0;
  2313. var index, distance;
  2314. if (this.exactMatch) {
  2315. if (needle !== caption.substr(0, needle.length))
  2316. continue loop;
  2317. }
  2318. else {
  2319. var fullMatchIndex = caption.toLowerCase().indexOf(lower);
  2320. if (fullMatchIndex > -1) {
  2321. penalty = fullMatchIndex;
  2322. }
  2323. else {
  2324. for (var j = 0; j < needle.length; j++) {
  2325. var i1 = caption.indexOf(lower[j], lastIndex + 1);
  2326. var i2 = caption.indexOf(upper[j], lastIndex + 1);
  2327. index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
  2328. if (index < 0)
  2329. continue loop;
  2330. distance = index - lastIndex - 1;
  2331. if (distance > 0) {
  2332. if (lastIndex === -1)
  2333. penalty += 10;
  2334. penalty += distance;
  2335. matchMask = matchMask | (1 << j);
  2336. }
  2337. lastIndex = index;
  2338. }
  2339. }
  2340. }
  2341. item.matchMask = matchMask;
  2342. item.exactMatch = penalty ? 0 : 1;
  2343. item.$score = (item.score || 0) - penalty;
  2344. results.push(item);
  2345. }
  2346. return results;
  2347. };
  2348. return FilteredList;
  2349. }());
  2350. exports.Autocomplete = Autocomplete;
  2351. exports.CompletionProvider = CompletionProvider;
  2352. exports.FilteredList = FilteredList;
  2353. });
  2354. ace.define("ace/ext/menu_tools/settings_menu.css",["require","exports","module"], function(require, exports, module){module.exports = "#ace_settingsmenu, #kbshortcutmenu {\n background-color: #F7F7F7;\n color: black;\n box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\n padding: 1em 0.5em 2em 1em;\n overflow: auto;\n position: absolute;\n margin: 0;\n bottom: 0;\n right: 0;\n top: 0;\n z-index: 9991;\n cursor: default;\n}\n\n.ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\n box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\n background-color: rgba(255, 255, 255, 0.6);\n color: black;\n}\n\n.ace_optionsMenuEntry:hover {\n background-color: rgba(100, 100, 100, 0.1);\n transition: all 0.3s\n}\n\n.ace_closeButton {\n background: rgba(245, 146, 146, 0.5);\n border: 1px solid #F48A8A;\n border-radius: 50%;\n padding: 7px;\n position: absolute;\n right: -8px;\n top: -8px;\n z-index: 100000;\n}\n.ace_closeButton{\n background: rgba(245, 146, 146, 0.9);\n}\n.ace_optionsMenuKey {\n color: darkslateblue;\n font-weight: bold;\n}\n.ace_optionsMenuCommand {\n color: darkcyan;\n font-weight: normal;\n}\n.ace_optionsMenuEntry input, .ace_optionsMenuEntry button {\n vertical-align: middle;\n}\n\n.ace_optionsMenuEntry button[ace_selected_button=true] {\n background: #e7e7e7;\n box-shadow: 1px 0px 2px 0px #adadad inset;\n border-color: #adadad;\n}\n.ace_optionsMenuEntry button {\n background: white;\n border: 1px solid lightgray;\n margin: 0px;\n}\n.ace_optionsMenuEntry button:hover{\n background: #f0f0f0;\n}";
  2355. });
  2356. ace.define("ace/ext/menu_tools/overlay_page",["require","exports","module","ace/lib/dom","ace/ext/menu_tools/settings_menu.css"], function(require, exports, module){/*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
  2357. 'use strict';
  2358. var dom = require("../../lib/dom");
  2359. var cssText = require("./settings_menu.css");
  2360. dom.importCssString(cssText, "settings_menu.css", false);
  2361. module.exports.overlayPage = function overlayPage(editor, contentElement, callback) {
  2362. var closer = document.createElement('div');
  2363. var ignoreFocusOut = false;
  2364. function documentEscListener(e) {
  2365. if (e.keyCode === 27) {
  2366. close();
  2367. }
  2368. }
  2369. function close() {
  2370. if (!closer)
  2371. return;
  2372. document.removeEventListener('keydown', documentEscListener);
  2373. closer.parentNode.removeChild(closer);
  2374. if (editor) {
  2375. editor.focus();
  2376. }
  2377. closer = null;
  2378. callback && callback();
  2379. }
  2380. function setIgnoreFocusOut(ignore) {
  2381. ignoreFocusOut = ignore;
  2382. if (ignore) {
  2383. closer.style.pointerEvents = "none";
  2384. contentElement.style.pointerEvents = "auto";
  2385. }
  2386. }
  2387. closer.style.cssText = 'margin: 0; padding: 0; ' +
  2388. 'position: fixed; top:0; bottom:0; left:0; right:0;' +
  2389. 'z-index: 9990; ' +
  2390. (editor ? 'background-color: rgba(0, 0, 0, 0.3);' : '');
  2391. closer.addEventListener('click', function (e) {
  2392. if (!ignoreFocusOut) {
  2393. close();
  2394. }
  2395. });
  2396. document.addEventListener('keydown', documentEscListener);
  2397. contentElement.addEventListener('click', function (e) {
  2398. e.stopPropagation();
  2399. });
  2400. closer.appendChild(contentElement);
  2401. document.body.appendChild(closer);
  2402. if (editor) {
  2403. editor.blur();
  2404. }
  2405. return {
  2406. close: close,
  2407. setIgnoreFocusOut: setIgnoreFocusOut
  2408. };
  2409. };
  2410. });
  2411. ace.define("ace/ext/modelist",["require","exports","module"], function(require, exports, module){"use strict";
  2412. var modes = [];
  2413. function getModeForPath(path) {
  2414. var mode = modesByName.text;
  2415. var fileName = path.split(/[\/\\]/).pop();
  2416. for (var i = 0; i < modes.length; i++) {
  2417. if (modes[i].supportsFile(fileName)) {
  2418. mode = modes[i];
  2419. break;
  2420. }
  2421. }
  2422. return mode;
  2423. }
  2424. var Mode = /** @class */ (function () {
  2425. function Mode(name, caption, extensions) {
  2426. this.name = name;
  2427. this.caption = caption;
  2428. this.mode = "ace/mode/" + name;
  2429. this.extensions = extensions;
  2430. var re;
  2431. if (/\^/.test(extensions)) {
  2432. re = extensions.replace(/\|(\^)?/g, function (a, b) {
  2433. return "$|" + (b ? "^" : "^.*\\.");
  2434. }) + "$";
  2435. }
  2436. else {
  2437. re = "\\.(" + extensions + ")$";
  2438. }
  2439. this.extRe = new RegExp(re, "gi");
  2440. }
  2441. Mode.prototype.supportsFile = function (filename) {
  2442. return filename.match(this.extRe);
  2443. };
  2444. return Mode;
  2445. }());
  2446. var supportedModes = {
  2447. ABAP: ["abap"],
  2448. ABC: ["abc"],
  2449. ActionScript: ["as"],
  2450. ADA: ["ada|adb"],
  2451. Alda: ["alda"],
  2452. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  2453. Apex: ["apex|cls|trigger|tgr"],
  2454. AQL: ["aql"],
  2455. AsciiDoc: ["asciidoc|adoc"],
  2456. ASL: ["dsl|asl|asl.json"],
  2457. Assembly_ARM32: ["s"],
  2458. Assembly_x86: ["asm|a"],
  2459. Astro: ["astro"],
  2460. AutoHotKey: ["ahk"],
  2461. BatchFile: ["bat|cmd"],
  2462. Basic: ["bas|bak"],
  2463. BibTeX: ["bib"],
  2464. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"],
  2465. C9Search: ["c9search_results"],
  2466. Cirru: ["cirru|cr"],
  2467. Clojure: ["clj|cljs"],
  2468. Cobol: ["CBL|COB"],
  2469. coffee: ["coffee|cf|cson|^Cakefile"],
  2470. ColdFusion: ["cfm|cfc"],
  2471. Crystal: ["cr"],
  2472. CSharp: ["cs"],
  2473. Csound_Document: ["csd"],
  2474. Csound_Orchestra: ["orc"],
  2475. Csound_Score: ["sco"],
  2476. CSS: ["css"],
  2477. CSV: ["csv"],
  2478. Curly: ["curly"],
  2479. Cuttlefish: ["conf"],
  2480. D: ["d|di"],
  2481. Dart: ["dart"],
  2482. Diff: ["diff|patch"],
  2483. Django: ["djt|html.djt|dj.html|djhtml"],
  2484. Dockerfile: ["^Dockerfile"],
  2485. Dot: ["dot"],
  2486. Drools: ["drl"],
  2487. Edifact: ["edi"],
  2488. Eiffel: ["e|ge"],
  2489. EJS: ["ejs"],
  2490. Elixir: ["ex|exs"],
  2491. Elm: ["elm"],
  2492. Erlang: ["erl|hrl"],
  2493. Flix: ["flix"],
  2494. Forth: ["frt|fs|ldr|fth|4th"],
  2495. Fortran: ["f|f90"],
  2496. FSharp: ["fsi|fs|ml|mli|fsx|fsscript"],
  2497. FSL: ["fsl"],
  2498. FTL: ["ftl"],
  2499. Gcode: ["gcode"],
  2500. Gherkin: ["feature"],
  2501. Gitignore: ["^.gitignore"],
  2502. Glsl: ["glsl|frag|vert"],
  2503. Gobstones: ["gbs"],
  2504. golang: ["go"],
  2505. GraphQLSchema: ["gql"],
  2506. Groovy: ["groovy"],
  2507. HAML: ["haml"],
  2508. Handlebars: ["hbs|handlebars|tpl|mustache"],
  2509. Haskell: ["hs"],
  2510. Haskell_Cabal: ["cabal"],
  2511. haXe: ["hx"],
  2512. Hjson: ["hjson"],
  2513. HTML: ["html|htm|xhtml|we|wpy"],
  2514. HTML_Elixir: ["eex|html.eex"],
  2515. HTML_Ruby: ["erb|rhtml|html.erb"],
  2516. INI: ["ini|conf|cfg|prefs"],
  2517. Io: ["io"],
  2518. Ion: ["ion"],
  2519. Jack: ["jack"],
  2520. Jade: ["jade|pug"],
  2521. Java: ["java"],
  2522. JavaScript: ["js|jsm|cjs|mjs"],
  2523. JEXL: ["jexl"],
  2524. JSON: ["json"],
  2525. JSON5: ["json5"],
  2526. JSONiq: ["jq"],
  2527. JSP: ["jsp"],
  2528. JSSM: ["jssm|jssm_state"],
  2529. JSX: ["jsx"],
  2530. Julia: ["jl"],
  2531. Kotlin: ["kt|kts"],
  2532. LaTeX: ["tex|latex|ltx|bib"],
  2533. Latte: ["latte"],
  2534. LESS: ["less"],
  2535. Liquid: ["liquid"],
  2536. Lisp: ["lisp"],
  2537. LiveScript: ["ls"],
  2538. Log: ["log"],
  2539. LogiQL: ["logic|lql"],
  2540. Logtalk: ["lgt"],
  2541. LSL: ["lsl"],
  2542. Lua: ["lua"],
  2543. LuaPage: ["lp"],
  2544. Lucene: ["lucene"],
  2545. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  2546. Markdown: ["md|markdown"],
  2547. Mask: ["mask"],
  2548. MATLAB: ["matlab"],
  2549. Maze: ["mz"],
  2550. MediaWiki: ["wiki|mediawiki"],
  2551. MEL: ["mel"],
  2552. MIPS: ["s|asm"],
  2553. MIXAL: ["mixal"],
  2554. MUSHCode: ["mc|mush"],
  2555. MySQL: ["mysql"],
  2556. Nasal: ["nas"],
  2557. Nginx: ["nginx|conf"],
  2558. Nim: ["nim"],
  2559. Nix: ["nix"],
  2560. NSIS: ["nsi|nsh"],
  2561. Nunjucks: ["nunjucks|nunjs|nj|njk"],
  2562. ObjectiveC: ["m|mm"],
  2563. OCaml: ["ml|mli"],
  2564. Odin: ["odin"],
  2565. PartiQL: ["partiql|pql"],
  2566. Pascal: ["pas|p"],
  2567. Perl: ["pl|pm"],
  2568. pgSQL: ["pgsql"],
  2569. PHP: ["php|inc|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"],
  2570. PHP_Laravel_blade: ["blade.php"],
  2571. Pig: ["pig"],
  2572. PLSQL: ["plsql"],
  2573. Powershell: ["ps1"],
  2574. Praat: ["praat|praatscript|psc|proc"],
  2575. Prisma: ["prisma"],
  2576. Prolog: ["plg|prolog"],
  2577. Properties: ["properties"],
  2578. Protobuf: ["proto"],
  2579. PRQL: ["prql"],
  2580. Puppet: ["epp|pp"],
  2581. Python: ["py"],
  2582. QML: ["qml"],
  2583. R: ["r"],
  2584. Raku: ["raku|rakumod|rakutest|p6|pl6|pm6"],
  2585. Razor: ["cshtml|asp"],
  2586. RDoc: ["Rd"],
  2587. Red: ["red|reds"],
  2588. RHTML: ["Rhtml"],
  2589. Robot: ["robot|resource"],
  2590. RST: ["rst"],
  2591. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  2592. Rust: ["rs"],
  2593. SaC: ["sac"],
  2594. SASS: ["sass"],
  2595. SCAD: ["scad"],
  2596. Scala: ["scala|sbt"],
  2597. Scheme: ["scm|sm|rkt|oak|scheme"],
  2598. Scrypt: ["scrypt"],
  2599. SCSS: ["scss"],
  2600. SH: ["sh|bash|^.bashrc"],
  2601. SJS: ["sjs"],
  2602. Slim: ["slim|skim"],
  2603. Smarty: ["smarty|tpl"],
  2604. Smithy: ["smithy"],
  2605. snippets: ["snippets"],
  2606. Soy_Template: ["soy"],
  2607. Space: ["space"],
  2608. SPARQL: ["rq"],
  2609. SQL: ["sql"],
  2610. SQLServer: ["sqlserver"],
  2611. Stylus: ["styl|stylus"],
  2612. SVG: ["svg"],
  2613. Swift: ["swift"],
  2614. Tcl: ["tcl"],
  2615. Terraform: ["tf", "tfvars", "terragrunt"],
  2616. Tex: ["tex"],
  2617. Text: ["txt"],
  2618. Textile: ["textile"],
  2619. Toml: ["toml"],
  2620. TSV: ["tsv"],
  2621. TSX: ["tsx"],
  2622. Turtle: ["ttl"],
  2623. Twig: ["twig|swig"],
  2624. Typescript: ["ts|mts|cts|typescript|str"],
  2625. Vala: ["vala"],
  2626. VBScript: ["vbs|vb"],
  2627. Velocity: ["vm"],
  2628. Verilog: ["v|vh|sv|svh"],
  2629. VHDL: ["vhd|vhdl"],
  2630. Visualforce: ["vfp|component|page"],
  2631. Vue: ["vue"],
  2632. Wollok: ["wlk|wpgm|wtest"],
  2633. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],
  2634. XQuery: ["xq"],
  2635. YAML: ["yaml|yml"],
  2636. Zeek: ["zeek|bro"],
  2637. Zig: ["zig"]
  2638. };
  2639. var nameOverrides = {
  2640. ObjectiveC: "Objective-C",
  2641. CSharp: "C#",
  2642. golang: "Go",
  2643. C_Cpp: "C and C++",
  2644. Csound_Document: "Csound Document",
  2645. Csound_Orchestra: "Csound",
  2646. Csound_Score: "Csound Score",
  2647. coffee: "CoffeeScript",
  2648. HTML_Ruby: "HTML (Ruby)",
  2649. HTML_Elixir: "HTML (Elixir)",
  2650. FTL: "FreeMarker",
  2651. PHP_Laravel_blade: "PHP (Blade Template)",
  2652. Perl6: "Perl 6",
  2653. AutoHotKey: "AutoHotkey / AutoIt"
  2654. };
  2655. var modesByName = {};
  2656. for (var name in supportedModes) {
  2657. var data = supportedModes[name];
  2658. var displayName = (nameOverrides[name] || name).replace(/_/g, " ");
  2659. var filename = name.toLowerCase();
  2660. var mode = new Mode(filename, displayName, data[0]);
  2661. modesByName[filename] = mode;
  2662. modes.push(mode);
  2663. }
  2664. module.exports = {
  2665. getModeForPath: getModeForPath,
  2666. modes: modes,
  2667. modesByName: modesByName
  2668. };
  2669. });
  2670. ace.define("ace/ext/prompt",["require","exports","module","ace/config","ace/range","ace/lib/dom","ace/autocomplete","ace/autocomplete/popup","ace/autocomplete/popup","ace/undomanager","ace/tokenizer","ace/ext/menu_tools/overlay_page","ace/ext/modelist"], function(require, exports, module){/**
  2671. * @typedef {import("../editor").Editor} Editor
  2672. */
  2673. "use strict";
  2674. var nls = require("../config").nls;
  2675. var Range = require("../range").Range;
  2676. var dom = require("../lib/dom");
  2677. var FilteredList = require("../autocomplete").FilteredList;
  2678. var AcePopup = require('../autocomplete/popup').AcePopup;
  2679. var $singleLineEditor = require('../autocomplete/popup').$singleLineEditor;
  2680. var UndoManager = require("../undomanager").UndoManager;
  2681. var Tokenizer = require("../tokenizer").Tokenizer;
  2682. var overlayPage = require("./menu_tools/overlay_page").overlayPage;
  2683. var modelist = require("./modelist");
  2684. var openPrompt;
  2685. function prompt(editor, message, options, callback) {
  2686. if (typeof message == "object") {
  2687. return prompt(editor, "", message, options);
  2688. }
  2689. if (openPrompt) {
  2690. var lastPrompt = openPrompt;
  2691. editor = lastPrompt.editor;
  2692. lastPrompt.close();
  2693. if (lastPrompt.name && lastPrompt.name == options.name)
  2694. return;
  2695. }
  2696. if (options.$type)
  2697. return prompt[options.$type](editor, callback);
  2698. var cmdLine = $singleLineEditor();
  2699. cmdLine.session.setUndoManager(new UndoManager());
  2700. var el = dom.buildDom(["div", { class: "ace_prompt_container" + (options.hasDescription ? " input-box-with-description" : "") }]);
  2701. var overlay = overlayPage(editor, el, done);
  2702. el.appendChild(cmdLine.container);
  2703. if (editor) {
  2704. editor.cmdLine = cmdLine;
  2705. cmdLine.setOption("fontSize", editor.getOption("fontSize"));
  2706. }
  2707. if (message) {
  2708. cmdLine.setValue(message, 1);
  2709. }
  2710. if (options.selection) {
  2711. cmdLine.selection.setRange({
  2712. start: cmdLine.session.doc.indexToPosition(options.selection[0]),
  2713. end: cmdLine.session.doc.indexToPosition(options.selection[1])
  2714. });
  2715. }
  2716. if (options.getCompletions) {
  2717. var popup = new AcePopup();
  2718. popup.renderer.setStyle("ace_autocomplete_inline");
  2719. popup.container.style.display = "block";
  2720. popup.container.style.maxWidth = "600px";
  2721. popup.container.style.width = "100%";
  2722. popup.container.style.marginTop = "3px";
  2723. popup.renderer.setScrollMargin(2, 2, 0, 0);
  2724. popup.autoSelect = false;
  2725. popup.renderer.$maxLines = 15;
  2726. popup.setRow(-1);
  2727. popup.on("click", function (e) {
  2728. var data = popup.getData(popup.getRow());
  2729. if (!data["error"]) {
  2730. cmdLine.setValue(data.value || data["name"] || data);
  2731. accept();
  2732. e.stop();
  2733. }
  2734. });
  2735. el.appendChild(popup.container);
  2736. updateCompletions();
  2737. }
  2738. if (options.$rules) {
  2739. var tokenizer = new Tokenizer(options.$rules);
  2740. cmdLine.session.bgTokenizer.setTokenizer(tokenizer);
  2741. }
  2742. if (options.placeholder) {
  2743. cmdLine.setOption("placeholder", options.placeholder);
  2744. }
  2745. if (options.hasDescription) {
  2746. var promptTextContainer = dom.buildDom(["div", { class: "ace_prompt_text_container" }]);
  2747. dom.buildDom(options.prompt || "Press 'Enter' to confirm or 'Escape' to cancel", promptTextContainer);
  2748. el.appendChild(promptTextContainer);
  2749. }
  2750. overlay.setIgnoreFocusOut(options.ignoreFocusOut);
  2751. function accept() {
  2752. var val;
  2753. if (popup && popup.getCursorPosition().row > 0) {
  2754. val = valueFromRecentList();
  2755. }
  2756. else {
  2757. val = cmdLine.getValue();
  2758. }
  2759. var curData = popup ? popup.getData(popup.getRow()) : val;
  2760. if (curData && !curData["error"]) {
  2761. done();
  2762. options.onAccept && options.onAccept({
  2763. value: val,
  2764. item: curData
  2765. }, cmdLine);
  2766. }
  2767. }
  2768. var keys = {
  2769. "Enter": accept,
  2770. "Esc|Shift-Esc": function () {
  2771. options.onCancel && options.onCancel(cmdLine.getValue(), cmdLine);
  2772. done();
  2773. }
  2774. };
  2775. if (popup) {
  2776. Object.assign(keys, {
  2777. "Up": function (editor) { popup.goTo("up"); valueFromRecentList(); },
  2778. "Down": function (editor) { popup.goTo("down"); valueFromRecentList(); },
  2779. "Ctrl-Up|Ctrl-Home": function (editor) { popup.goTo("start"); valueFromRecentList(); },
  2780. "Ctrl-Down|Ctrl-End": function (editor) { popup.goTo("end"); valueFromRecentList(); },
  2781. "Tab": function (editor) {
  2782. popup.goTo("down");
  2783. valueFromRecentList();
  2784. },
  2785. "PageUp": function (editor) { popup.gotoPageUp(); valueFromRecentList(); },
  2786. "PageDown": function (editor) { popup.gotoPageDown(); valueFromRecentList(); }
  2787. });
  2788. }
  2789. cmdLine.commands.bindKeys(keys);
  2790. function done() {
  2791. overlay.close();
  2792. callback && callback();
  2793. openPrompt = null;
  2794. }
  2795. cmdLine.on("input", function () {
  2796. options.onInput && options.onInput();
  2797. updateCompletions();
  2798. });
  2799. function updateCompletions() {
  2800. if (options.getCompletions) {
  2801. var prefix;
  2802. if (options.getPrefix) {
  2803. prefix = options.getPrefix(cmdLine);
  2804. }
  2805. var completions = options.getCompletions(cmdLine);
  2806. popup.setData(completions, prefix);
  2807. popup.resize(true);
  2808. }
  2809. }
  2810. function valueFromRecentList() {
  2811. var current = popup.getData(popup.getRow());
  2812. if (current && !current["error"])
  2813. return current.value || current.caption || current;
  2814. }
  2815. cmdLine.resize(true);
  2816. if (popup) {
  2817. popup.resize(true);
  2818. }
  2819. cmdLine.focus();
  2820. openPrompt = {
  2821. close: done,
  2822. name: options.name,
  2823. editor: editor
  2824. };
  2825. }
  2826. prompt.gotoLine = function (editor, callback) {
  2827. function stringifySelection(selection) {
  2828. if (!Array.isArray(selection))
  2829. selection = [selection];
  2830. return selection.map(function (r) {
  2831. var cursor = r.isBackwards ? r.start : r.end;
  2832. var anchor = r.isBackwards ? r.end : r.start;
  2833. var row = anchor.row;
  2834. var s = (row + 1) + ":" + anchor.column;
  2835. if (anchor.row == cursor.row) {
  2836. if (anchor.column != cursor.column)
  2837. s += ">" + ":" + cursor.column;
  2838. }
  2839. else {
  2840. s += ">" + (cursor.row + 1) + ":" + cursor.column;
  2841. }
  2842. return s;
  2843. }).reverse().join(", ");
  2844. }
  2845. prompt(editor, ":" + stringifySelection(editor.selection.toJSON()), {
  2846. name: "gotoLine",
  2847. selection: [1, Number.MAX_VALUE],
  2848. onAccept: function (data) {
  2849. var value = data.value;
  2850. var _history = prompt.gotoLine["_history"];
  2851. if (!_history)
  2852. prompt.gotoLine["_history"] = _history = [];
  2853. if (_history.indexOf(value) != -1)
  2854. _history.splice(_history.indexOf(value), 1);
  2855. _history.unshift(value);
  2856. if (_history.length > 20)
  2857. _history.length = 20;
  2858. var pos = editor.getCursorPosition();
  2859. var ranges = [];
  2860. value.replace(/^:/, "").split(/,/).map(function (str) {
  2861. var parts = str.split(/([<>:+-]|c?\d+)|[^c\d<>:+-]+/).filter(Boolean);
  2862. var i = 0;
  2863. function readPosition() {
  2864. var c = parts[i++];
  2865. if (!c)
  2866. return;
  2867. if (c[0] == "c") {
  2868. var index = parseInt(c.slice(1)) || 0;
  2869. return editor.session.doc.indexToPosition(index);
  2870. }
  2871. var row = pos.row;
  2872. var column = 0;
  2873. if (/\d/.test(c)) {
  2874. row = parseInt(c) - 1;
  2875. c = parts[i++];
  2876. }
  2877. if (c == ":") {
  2878. c = parts[i++];
  2879. if (/\d/.test(c)) {
  2880. column = parseInt(c) || 0;
  2881. }
  2882. }
  2883. return { row: row, column: column };
  2884. }
  2885. pos = readPosition();
  2886. var range = Range.fromPoints(pos, pos);
  2887. if (parts[i] == ">") {
  2888. i++;
  2889. range.end = readPosition();
  2890. }
  2891. else if (parts[i] == "<") {
  2892. i++;
  2893. range.start = readPosition();
  2894. }
  2895. ranges.unshift(range);
  2896. });
  2897. editor.selection.fromJSON(ranges);
  2898. var scrollTop = editor.renderer.scrollTop;
  2899. editor.renderer.scrollSelectionIntoView(editor.selection.anchor, editor.selection.cursor, 0.5);
  2900. editor.renderer.animateScrolling(scrollTop);
  2901. },
  2902. history: function () {
  2903. if (!prompt.gotoLine["_history"])
  2904. return [];
  2905. return prompt.gotoLine["_history"];
  2906. },
  2907. getCompletions: function (cmdLine) {
  2908. var value = cmdLine.getValue();
  2909. var m = value.replace(/^:/, "").split(":");
  2910. var row = Math.min(parseInt(m[0]) || 1, editor.session.getLength()) - 1;
  2911. var line = editor.session.getLine(row);
  2912. var current = value + " " + line;
  2913. return [current].concat(this.history());
  2914. },
  2915. $rules: {
  2916. start: [{
  2917. regex: /\d+/,
  2918. token: "string"
  2919. }, {
  2920. regex: /[:,><+\-c]/,
  2921. token: "keyword"
  2922. }]
  2923. }
  2924. });
  2925. };
  2926. prompt.commands = function (editor, callback) {
  2927. function normalizeName(name) {
  2928. return (name || "").replace(/^./, function (x) {
  2929. return x.toUpperCase(x);
  2930. }).replace(/[a-z][A-Z]/g, function (x) {
  2931. return x[0] + " " + x[1].toLowerCase(x);
  2932. });
  2933. }
  2934. function getEditorCommandsByName(excludeCommands) {
  2935. var commandsByName = [];
  2936. var commandMap = {};
  2937. editor.keyBinding.$handlers.forEach(function (handler) {
  2938. var platform = handler["platform"];
  2939. var cbn = handler["byName"];
  2940. for (var i in cbn) {
  2941. var key = cbn[i].bindKey;
  2942. if (typeof key !== "string") {
  2943. key = key && key[platform] || "";
  2944. }
  2945. var commands = cbn[i];
  2946. var description = commands.description || normalizeName(commands.name);
  2947. if (!Array.isArray(commands))
  2948. commands = [commands];
  2949. commands.forEach(function (command) {
  2950. if (typeof command != "string")
  2951. command = command.name;
  2952. var needle = excludeCommands.find(function (el) {
  2953. return el === command;
  2954. });
  2955. if (!needle) {
  2956. if (commandMap[command]) {
  2957. commandMap[command].key += "|" + key;
  2958. }
  2959. else {
  2960. commandMap[command] = { key: key, command: command, description: description };
  2961. commandsByName.push(commandMap[command]);
  2962. }
  2963. }
  2964. });
  2965. }
  2966. });
  2967. return commandsByName;
  2968. }
  2969. var excludeCommandsList = ["insertstring", "inserttext", "setIndentation", "paste"];
  2970. var shortcutsArray = getEditorCommandsByName(excludeCommandsList);
  2971. shortcutsArray = shortcutsArray.map(function (item) {
  2972. return { value: item.description, meta: item.key, command: item.command };
  2973. });
  2974. prompt(editor, "", {
  2975. name: "commands",
  2976. selection: [0, Number.MAX_VALUE],
  2977. maxHistoryCount: 5,
  2978. onAccept: function (data) {
  2979. if (data.item) {
  2980. var commandName = data.item.command;
  2981. this.addToHistory(data.item);
  2982. editor.execCommand(commandName);
  2983. }
  2984. },
  2985. addToHistory: function (item) {
  2986. var history = this.history();
  2987. history.unshift(item);
  2988. delete item.message;
  2989. for (var i = 1; i < history.length; i++) {
  2990. if (history[i]["command"] == item.command) {
  2991. history.splice(i, 1);
  2992. break;
  2993. }
  2994. }
  2995. if (this.maxHistoryCount > 0 && history.length > this.maxHistoryCount) {
  2996. history.splice(history.length - 1, 1);
  2997. }
  2998. prompt.commands["history"] = history;
  2999. },
  3000. history: function () {
  3001. return prompt.commands["history"] || [];
  3002. },
  3003. getPrefix: function (cmdLine) {
  3004. var currentPos = cmdLine.getCursorPosition();
  3005. var filterValue = cmdLine.getValue();
  3006. return filterValue.substring(0, currentPos.column);
  3007. },
  3008. getCompletions: function (cmdLine) {
  3009. function getFilteredCompletions(commands, prefix) {
  3010. var resultCommands = JSON.parse(JSON.stringify(commands));
  3011. var filtered = new FilteredList(resultCommands);
  3012. return filtered.filterCompletions(resultCommands, prefix);
  3013. }
  3014. function getUniqueCommandList(commands, usedCommands) {
  3015. if (!usedCommands || !usedCommands.length) {
  3016. return commands;
  3017. }
  3018. var excludeCommands = [];
  3019. usedCommands.forEach(function (item) {
  3020. excludeCommands.push(item.command);
  3021. });
  3022. var resultCommands = [];
  3023. commands.forEach(function (item) {
  3024. if (excludeCommands.indexOf(item.command) === -1) {
  3025. resultCommands.push(item);
  3026. }
  3027. });
  3028. return resultCommands;
  3029. }
  3030. var prefix = this.getPrefix(cmdLine);
  3031. var recentlyUsedCommands = getFilteredCompletions(this.history(), prefix);
  3032. var otherCommands = getUniqueCommandList(shortcutsArray, recentlyUsedCommands);
  3033. otherCommands = getFilteredCompletions(otherCommands, prefix);
  3034. if (recentlyUsedCommands.length && otherCommands.length) {
  3035. recentlyUsedCommands[0].message = nls("prompt.recently-used", "Recently used");
  3036. otherCommands[0].message = nls("prompt.other-commands", "Other commands");
  3037. }
  3038. var completions = recentlyUsedCommands.concat(otherCommands);
  3039. return completions.length > 0 ? completions : [{
  3040. value: nls("prompt.no-matching-commands", "No matching commands"),
  3041. error: 1
  3042. }];
  3043. }
  3044. });
  3045. };
  3046. prompt.modes = function (editor, callback) {
  3047. var modesArray = modelist.modes;
  3048. modesArray = modesArray.map(function (item) {
  3049. return { value: item.caption, mode: item.name };
  3050. });
  3051. prompt(editor, "", {
  3052. name: "modes",
  3053. selection: [0, Number.MAX_VALUE],
  3054. onAccept: function (data) {
  3055. if (data.item) {
  3056. var modeName = "ace/mode/" + data.item.mode;
  3057. editor.session.setMode(modeName);
  3058. }
  3059. },
  3060. getPrefix: function (cmdLine) {
  3061. var currentPos = cmdLine.getCursorPosition();
  3062. var filterValue = cmdLine.getValue();
  3063. return filterValue.substring(0, currentPos.column);
  3064. },
  3065. getCompletions: function (cmdLine) {
  3066. function getFilteredCompletions(modes, prefix) {
  3067. var resultCommands = JSON.parse(JSON.stringify(modes));
  3068. var filtered = new FilteredList(resultCommands);
  3069. return filtered.filterCompletions(resultCommands, prefix);
  3070. }
  3071. var prefix = this.getPrefix(cmdLine);
  3072. var completions = getFilteredCompletions(modesArray, prefix);
  3073. return completions.length > 0 ? completions : [{
  3074. "caption": "No mode matching",
  3075. "value": "No mode matching",
  3076. "error": 1
  3077. }];
  3078. }
  3079. });
  3080. };
  3081. dom.importCssString(".ace_prompt_container {\n max-width: 603px;\n width: 100%;\n margin: 20px auto;\n padding: 3px;\n background: white;\n border-radius: 2px;\n box-shadow: 0px 2px 3px 0px #555;\n}", "promtp.css", false);
  3082. exports.prompt = prompt;
  3083. }); (function() {
  3084. ace.require(["ace/ext/prompt"], function(m) {
  3085. if (typeof module == "object" && typeof exports == "object" && module) {
  3086. module.exports = m;
  3087. }
  3088. });
  3089. })();