f6b7365909bf728ce87657ca9f4d571f.js 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421
  1. ace.define("ace/snippets",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/range_list","ace/keyboard/hash_handler","ace/tokenizer","ace/clipboard","ace/editor"], function(require, exports, module){"use strict";
  2. var dom = require("./lib/dom");
  3. var oop = require("./lib/oop");
  4. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  5. var lang = require("./lib/lang");
  6. var Range = require("./range").Range;
  7. var RangeList = require("./range_list").RangeList;
  8. var HashHandler = require("./keyboard/hash_handler").HashHandler;
  9. var Tokenizer = require("./tokenizer").Tokenizer;
  10. var clipboard = require("./clipboard");
  11. var VARIABLES = {
  12. CURRENT_WORD: function (editor) {
  13. return editor.session.getTextRange(editor.session.getWordRange());
  14. },
  15. SELECTION: function (editor, name, indentation) {
  16. var text = editor.session.getTextRange();
  17. if (indentation)
  18. return text.replace(/\n\r?([ \t]*\S)/g, "\n" + indentation + "$1");
  19. return text;
  20. },
  21. CURRENT_LINE: function (editor) {
  22. return editor.session.getLine(editor.getCursorPosition().row);
  23. },
  24. PREV_LINE: function (editor) {
  25. return editor.session.getLine(editor.getCursorPosition().row - 1);
  26. },
  27. LINE_INDEX: function (editor) {
  28. return editor.getCursorPosition().row;
  29. },
  30. LINE_NUMBER: function (editor) {
  31. return editor.getCursorPosition().row + 1;
  32. },
  33. SOFT_TABS: function (editor) {
  34. return editor.session.getUseSoftTabs() ? "YES" : "NO";
  35. },
  36. TAB_SIZE: function (editor) {
  37. return editor.session.getTabSize();
  38. },
  39. CLIPBOARD: function (editor) {
  40. return clipboard.getText && clipboard.getText();
  41. },
  42. FILENAME: function (editor) {
  43. return /[^/\\]*$/.exec(this.FILEPATH(editor))[0];
  44. },
  45. FILENAME_BASE: function (editor) {
  46. return /[^/\\]*$/.exec(this.FILEPATH(editor))[0].replace(/\.[^.]*$/, "");
  47. },
  48. DIRECTORY: function (editor) {
  49. return this.FILEPATH(editor).replace(/[^/\\]*$/, "");
  50. },
  51. FILEPATH: function (editor) { return "/not implemented.txt"; },
  52. WORKSPACE_NAME: function () { return "Unknown"; },
  53. FULLNAME: function () { return "Unknown"; },
  54. BLOCK_COMMENT_START: function (editor) {
  55. var mode = editor.session.$mode || {};
  56. return mode.blockComment && mode.blockComment.start || "";
  57. },
  58. BLOCK_COMMENT_END: function (editor) {
  59. var mode = editor.session.$mode || {};
  60. return mode.blockComment && mode.blockComment.end || "";
  61. },
  62. LINE_COMMENT: function (editor) {
  63. var mode = editor.session.$mode || {};
  64. return mode.lineCommentStart || "";
  65. },
  66. CURRENT_YEAR: date.bind(null, { year: "numeric" }),
  67. CURRENT_YEAR_SHORT: date.bind(null, { year: "2-digit" }),
  68. CURRENT_MONTH: date.bind(null, { month: "numeric" }),
  69. CURRENT_MONTH_NAME: date.bind(null, { month: "long" }),
  70. CURRENT_MONTH_NAME_SHORT: date.bind(null, { month: "short" }),
  71. CURRENT_DATE: date.bind(null, { day: "2-digit" }),
  72. CURRENT_DAY_NAME: date.bind(null, { weekday: "long" }),
  73. CURRENT_DAY_NAME_SHORT: date.bind(null, { weekday: "short" }),
  74. CURRENT_HOUR: date.bind(null, { hour: "2-digit", hour12: false }),
  75. CURRENT_MINUTE: date.bind(null, { minute: "2-digit" }),
  76. CURRENT_SECOND: date.bind(null, { second: "2-digit" })
  77. };
  78. VARIABLES.SELECTED_TEXT = VARIABLES.SELECTION;
  79. function date(dateFormat) {
  80. var str = new Date().toLocaleString("en-us", dateFormat);
  81. return str.length == 1 ? "0" + str : str;
  82. }
  83. var SnippetManager = /** @class */ (function () {
  84. function SnippetManager() {
  85. this.snippetMap = {};
  86. this.snippetNameMap = {};
  87. this.variables = VARIABLES;
  88. }
  89. SnippetManager.prototype.getTokenizer = function () {
  90. return SnippetManager["$tokenizer"] || this.createTokenizer();
  91. };
  92. SnippetManager.prototype.createTokenizer = function () {
  93. function TabstopToken(str) {
  94. str = str.substr(1);
  95. if (/^\d+$/.test(str))
  96. return [{ tabstopId: parseInt(str, 10) }];
  97. return [{ text: str }];
  98. }
  99. function escape(ch) {
  100. return "(?:[^\\\\" + ch + "]|\\\\.)";
  101. }
  102. var formatMatcher = {
  103. regex: "/(" + escape("/") + "+)/",
  104. onMatch: function (val, state, stack) {
  105. var ts = stack[0];
  106. ts.fmtString = true;
  107. ts.guard = val.slice(1, -1);
  108. ts.flag = "";
  109. return "";
  110. },
  111. next: "formatString"
  112. };
  113. SnippetManager["$tokenizer"] = new Tokenizer({
  114. start: [
  115. { regex: /\\./, onMatch: function (val, state, stack) {
  116. var ch = val[1];
  117. if (ch == "}" && stack.length) {
  118. val = ch;
  119. }
  120. else if ("`$\\".indexOf(ch) != -1) {
  121. val = ch;
  122. }
  123. return [val];
  124. } },
  125. { regex: /}/, onMatch: function (val, state, stack) {
  126. return [stack.length ? stack.shift() : val];
  127. } },
  128. { regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken },
  129. { regex: /\$\{[\dA-Z_a-z]+/, onMatch: function (str, state, stack) {
  130. var t = TabstopToken(str.substr(1));
  131. stack.unshift(t[0]);
  132. return t;
  133. }, next: "snippetVar" },
  134. { regex: /\n/, token: "newline", merge: false }
  135. ],
  136. snippetVar: [
  137. { regex: "\\|" + escape("\\|") + "*\\|", onMatch: function (val, state, stack) {
  138. var choices = val.slice(1, -1).replace(/\\[,|\\]|,/g, function (operator) {
  139. return operator.length == 2 ? operator[1] : "\x00";
  140. }).split("\x00").map(function (value) {
  141. return { value: value };
  142. });
  143. stack[0].choices = choices;
  144. return [choices[0]];
  145. }, next: "start" },
  146. formatMatcher,
  147. { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start" }
  148. ],
  149. formatString: [
  150. { regex: /:/, onMatch: function (val, state, stack) {
  151. if (stack.length && stack[0].expectElse) {
  152. stack[0].expectElse = false;
  153. stack[0].ifEnd = { elseEnd: stack[0] };
  154. return [stack[0].ifEnd];
  155. }
  156. return ":";
  157. } },
  158. { regex: /\\./, onMatch: function (val, state, stack) {
  159. var ch = val[1];
  160. if (ch == "}" && stack.length)
  161. val = ch;
  162. else if ("`$\\".indexOf(ch) != -1)
  163. val = ch;
  164. else if (ch == "n")
  165. val = "\n";
  166. else if (ch == "t")
  167. val = "\t";
  168. else if ("ulULE".indexOf(ch) != -1)
  169. val = { changeCase: ch, local: ch > "a" };
  170. return [val];
  171. } },
  172. { regex: "/\\w*}", onMatch: function (val, state, stack) {
  173. var next = stack.shift();
  174. if (next)
  175. next.flag = val.slice(1, -1);
  176. this.next = next && next.tabstopId ? "start" : "";
  177. return [next || val];
  178. }, next: "start" },
  179. { regex: /\$(?:\d+|\w+)/, onMatch: function (val, state, stack) {
  180. return [{ text: val.slice(1) }];
  181. } },
  182. { regex: /\${\w+/, onMatch: function (val, state, stack) {
  183. var token = { text: val.slice(2) };
  184. stack.unshift(token);
  185. return [token];
  186. }, next: "formatStringVar" },
  187. { regex: /\n/, token: "newline", merge: false },
  188. { regex: /}/, onMatch: function (val, state, stack) {
  189. var next = stack.shift();
  190. this.next = next && next.tabstopId ? "start" : "";
  191. return [next || val];
  192. }, next: "start" }
  193. ],
  194. formatStringVar: [
  195. { regex: /:\/\w+}/, onMatch: function (val, state, stack) {
  196. var ts = stack[0];
  197. ts.formatFunction = val.slice(2, -1);
  198. return [stack.shift()];
  199. }, next: "formatString" },
  200. formatMatcher,
  201. { regex: /:[\?\-+]?/, onMatch: function (val, state, stack) {
  202. if (val[1] == "+")
  203. stack[0].ifEnd = stack[0];
  204. if (val[1] == "?")
  205. stack[0].expectElse = true;
  206. }, next: "formatString" },
  207. { regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "formatString" }
  208. ]
  209. });
  210. return SnippetManager["$tokenizer"];
  211. };
  212. SnippetManager.prototype.tokenizeTmSnippet = function (str, startState) {
  213. return this.getTokenizer().getLineTokens(str, startState).tokens.map(function (x) {
  214. return x.value || x;
  215. });
  216. };
  217. SnippetManager.prototype.getVariableValue = function (editor, name, indentation) {
  218. if (/^\d+$/.test(name))
  219. return (this.variables.__ || {})[name] || "";
  220. if (/^[A-Z]\d+$/.test(name))
  221. return (this.variables[name[0] + "__"] || {})[name.substr(1)] || "";
  222. name = name.replace(/^TM_/, "");
  223. if (!this.variables.hasOwnProperty(name))
  224. return "";
  225. var value = this.variables[name];
  226. if (typeof value == "function")
  227. value = this.variables[name](editor, name, indentation);
  228. return value == null ? "" : value;
  229. };
  230. SnippetManager.prototype.tmStrFormat = function (str, ch, editor) {
  231. if (!ch.fmt)
  232. return str;
  233. var flag = ch.flag || "";
  234. var re = ch.guard;
  235. re = new RegExp(re, flag.replace(/[^gim]/g, ""));
  236. var fmtTokens = typeof ch.fmt == "string" ? this.tokenizeTmSnippet(ch.fmt, "formatString") : ch.fmt;
  237. var _self = this;
  238. var formatted = str.replace(re, function () {
  239. var oldArgs = _self.variables.__;
  240. _self.variables.__ = [].slice.call(arguments);
  241. var fmtParts = _self.resolveVariables(fmtTokens, editor);
  242. var gChangeCase = "E";
  243. for (var i = 0; i < fmtParts.length; i++) {
  244. var ch = fmtParts[i];
  245. if (typeof ch == "object") {
  246. fmtParts[i] = "";
  247. if (ch.changeCase && ch.local) {
  248. var next = fmtParts[i + 1];
  249. if (next && typeof next == "string") {
  250. if (ch.changeCase == "u")
  251. fmtParts[i] = next[0].toUpperCase();
  252. else
  253. fmtParts[i] = next[0].toLowerCase();
  254. fmtParts[i + 1] = next.substr(1);
  255. }
  256. }
  257. else if (ch.changeCase) {
  258. gChangeCase = ch.changeCase;
  259. }
  260. }
  261. else if (gChangeCase == "U") {
  262. fmtParts[i] = ch.toUpperCase();
  263. }
  264. else if (gChangeCase == "L") {
  265. fmtParts[i] = ch.toLowerCase();
  266. }
  267. }
  268. _self.variables.__ = oldArgs;
  269. return fmtParts.join("");
  270. });
  271. return formatted;
  272. };
  273. SnippetManager.prototype.tmFormatFunction = function (str, ch, editor) {
  274. if (ch.formatFunction == "upcase")
  275. return str.toUpperCase();
  276. if (ch.formatFunction == "downcase")
  277. return str.toLowerCase();
  278. return str;
  279. };
  280. SnippetManager.prototype.resolveVariables = function (snippet, editor) {
  281. var result = [];
  282. var indentation = "";
  283. var afterNewLine = true;
  284. for (var i = 0; i < snippet.length; i++) {
  285. var ch = snippet[i];
  286. if (typeof ch == "string") {
  287. result.push(ch);
  288. if (ch == "\n") {
  289. afterNewLine = true;
  290. indentation = "";
  291. }
  292. else if (afterNewLine) {
  293. indentation = /^\t*/.exec(ch)[0];
  294. afterNewLine = /\S/.test(ch);
  295. }
  296. continue;
  297. }
  298. if (!ch)
  299. continue;
  300. afterNewLine = false;
  301. if (ch.fmtString) {
  302. var j = snippet.indexOf(ch, i + 1);
  303. if (j == -1)
  304. j = snippet.length;
  305. ch.fmt = snippet.slice(i + 1, j);
  306. i = j;
  307. }
  308. if (ch.text) {
  309. var value = this.getVariableValue(editor, ch.text, indentation) + "";
  310. if (ch.fmtString)
  311. value = this.tmStrFormat(value, ch, editor);
  312. if (ch.formatFunction)
  313. value = this.tmFormatFunction(value, ch, editor);
  314. if (value && !ch.ifEnd) {
  315. result.push(value);
  316. gotoNext(ch);
  317. }
  318. else if (!value && ch.ifEnd) {
  319. gotoNext(ch.ifEnd);
  320. }
  321. }
  322. else if (ch.elseEnd) {
  323. gotoNext(ch.elseEnd);
  324. }
  325. else if (ch.tabstopId != null) {
  326. result.push(ch);
  327. }
  328. else if (ch.changeCase != null) {
  329. result.push(ch);
  330. }
  331. }
  332. function gotoNext(ch) {
  333. var i1 = snippet.indexOf(ch, i + 1);
  334. if (i1 != -1)
  335. i = i1;
  336. }
  337. return result;
  338. };
  339. SnippetManager.prototype.getDisplayTextForSnippet = function (editor, snippetText) {
  340. var processedSnippet = processSnippetText.call(this, editor, snippetText);
  341. return processedSnippet.text;
  342. };
  343. SnippetManager.prototype.insertSnippetForSelection = function (editor, snippetText, options) {
  344. if (options === void 0) { options = {}; }
  345. var processedSnippet = processSnippetText.call(this, editor, snippetText, options);
  346. var range = editor.getSelectionRange();
  347. var end = editor.session.replace(range, processedSnippet.text);
  348. var tabstopManager = new TabstopManager(editor);
  349. var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
  350. tabstopManager.addTabstops(processedSnippet.tabstops, range.start, end, selectionId);
  351. };
  352. SnippetManager.prototype.insertSnippet = function (editor, snippetText, options) {
  353. if (options === void 0) { options = {}; }
  354. var self = this;
  355. if (editor.inVirtualSelectionMode)
  356. return self.insertSnippetForSelection(editor, snippetText, options);
  357. editor.forEachSelection(function () {
  358. self.insertSnippetForSelection(editor, snippetText, options);
  359. }, null, { keepOrder: true });
  360. if (editor.tabstopManager)
  361. editor.tabstopManager.tabNext();
  362. };
  363. SnippetManager.prototype.$getScope = function (editor) {
  364. var scope = editor.session.$mode.$id || "";
  365. scope = scope.split("/").pop();
  366. if (scope === "html" || scope === "php") {
  367. if (scope === "php" && !editor.session.$mode.inlinePhp)
  368. scope = "html";
  369. var c = editor.getCursorPosition();
  370. var state = editor.session.getState(c.row);
  371. if (typeof state === "object") {
  372. state = state[0];
  373. }
  374. if (state.substring) {
  375. if (state.substring(0, 3) == "js-")
  376. scope = "javascript";
  377. else if (state.substring(0, 4) == "css-")
  378. scope = "css";
  379. else if (state.substring(0, 4) == "php-")
  380. scope = "php";
  381. }
  382. }
  383. return scope;
  384. };
  385. SnippetManager.prototype.getActiveScopes = function (editor) {
  386. var scope = this.$getScope(editor);
  387. var scopes = [scope];
  388. var snippetMap = this.snippetMap;
  389. if (snippetMap[scope] && snippetMap[scope].includeScopes) {
  390. scopes.push.apply(scopes, snippetMap[scope].includeScopes);
  391. }
  392. scopes.push("_");
  393. return scopes;
  394. };
  395. SnippetManager.prototype.expandWithTab = function (editor, options) {
  396. var self = this;
  397. var result = editor.forEachSelection(function () {
  398. return self.expandSnippetForSelection(editor, options);
  399. }, null, { keepOrder: true });
  400. if (result && editor.tabstopManager)
  401. editor.tabstopManager.tabNext();
  402. return result;
  403. };
  404. SnippetManager.prototype.expandSnippetForSelection = function (editor, options) {
  405. var cursor = editor.getCursorPosition();
  406. var line = editor.session.getLine(cursor.row);
  407. var before = line.substring(0, cursor.column);
  408. var after = line.substr(cursor.column);
  409. var snippetMap = this.snippetMap;
  410. var snippet;
  411. this.getActiveScopes(editor).some(function (scope) {
  412. var snippets = snippetMap[scope];
  413. if (snippets)
  414. snippet = this.findMatchingSnippet(snippets, before, after);
  415. return !!snippet;
  416. }, this);
  417. if (!snippet)
  418. return false;
  419. if (options && options.dryRun)
  420. return true;
  421. editor.session.doc.removeInLine(cursor.row, cursor.column - snippet.replaceBefore.length, cursor.column + snippet.replaceAfter.length);
  422. this.variables.M__ = snippet.matchBefore;
  423. this.variables.T__ = snippet.matchAfter;
  424. this.insertSnippetForSelection(editor, snippet.content);
  425. this.variables.M__ = this.variables.T__ = null;
  426. return true;
  427. };
  428. SnippetManager.prototype.findMatchingSnippet = function (snippetList, before, after) {
  429. for (var i = snippetList.length; i--;) {
  430. var s = snippetList[i];
  431. if (s.startRe && !s.startRe.test(before))
  432. continue;
  433. if (s.endRe && !s.endRe.test(after))
  434. continue;
  435. if (!s.startRe && !s.endRe)
  436. continue;
  437. s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
  438. s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
  439. s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
  440. s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
  441. return s;
  442. }
  443. };
  444. SnippetManager.prototype.register = function (snippets, scope) {
  445. var snippetMap = this.snippetMap;
  446. var snippetNameMap = this.snippetNameMap;
  447. var self = this;
  448. if (!snippets)
  449. snippets = [];
  450. function wrapRegexp(src) {
  451. if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
  452. src = "(?:" + src + ")";
  453. return src || "";
  454. }
  455. function guardedRegexp(re, guard, opening) {
  456. re = wrapRegexp(re);
  457. guard = wrapRegexp(guard);
  458. if (opening) {
  459. re = guard + re;
  460. if (re && re[re.length - 1] != "$")
  461. re = re + "$";
  462. }
  463. else {
  464. re = re + guard;
  465. if (re && re[0] != "^")
  466. re = "^" + re;
  467. }
  468. return new RegExp(re);
  469. }
  470. function addSnippet(s) {
  471. if (!s.scope)
  472. s.scope = scope || "_";
  473. scope = s.scope;
  474. if (!snippetMap[scope]) {
  475. snippetMap[scope] = [];
  476. snippetNameMap[scope] = {};
  477. }
  478. var map = snippetNameMap[scope];
  479. if (s.name) {
  480. var old = map[s.name];
  481. if (old)
  482. self.unregister(old);
  483. map[s.name] = s;
  484. }
  485. snippetMap[scope].push(s);
  486. if (s.prefix)
  487. s.tabTrigger = s.prefix;
  488. if (!s.content && s.body)
  489. s.content = Array.isArray(s.body) ? s.body.join("\n") : s.body;
  490. if (s.tabTrigger && !s.trigger) {
  491. if (!s.guard && /^\w/.test(s.tabTrigger))
  492. s.guard = "\\b";
  493. s.trigger = lang.escapeRegExp(s.tabTrigger);
  494. }
  495. if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard)
  496. return;
  497. s.startRe = guardedRegexp(s.trigger, s.guard, true);
  498. s.triggerRe = new RegExp(s.trigger);
  499. s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
  500. s.endTriggerRe = new RegExp(s.endTrigger);
  501. }
  502. if (Array.isArray(snippets)) {
  503. snippets.forEach(addSnippet);
  504. }
  505. else {
  506. Object.keys(snippets).forEach(function (key) {
  507. addSnippet(snippets[key]);
  508. });
  509. }
  510. this._signal("registerSnippets", { scope: scope });
  511. };
  512. SnippetManager.prototype.unregister = function (snippets, scope) {
  513. var snippetMap = this.snippetMap;
  514. var snippetNameMap = this.snippetNameMap;
  515. function removeSnippet(s) {
  516. var nameMap = snippetNameMap[s.scope || scope];
  517. if (nameMap && nameMap[s.name]) {
  518. delete nameMap[s.name];
  519. var map = snippetMap[s.scope || scope];
  520. var i = map && map.indexOf(s);
  521. if (i >= 0)
  522. map.splice(i, 1);
  523. }
  524. }
  525. if (snippets.content)
  526. removeSnippet(snippets);
  527. else if (Array.isArray(snippets))
  528. snippets.forEach(removeSnippet);
  529. };
  530. SnippetManager.prototype.parseSnippetFile = function (str) {
  531. str = str.replace(/\r/g, "");
  532. var list = [], /**@type{Snippet}*/ snippet = {};
  533. var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
  534. var m;
  535. while (m = re.exec(str)) {
  536. if (m[1]) {
  537. try {
  538. snippet = JSON.parse(m[1]);
  539. list.push(snippet);
  540. }
  541. catch (e) { }
  542. }
  543. if (m[4]) {
  544. snippet.content = m[4].replace(/^\t/gm, "");
  545. list.push(snippet);
  546. snippet = {};
  547. }
  548. else {
  549. var key = m[2], val = m[3];
  550. if (key == "regex") {
  551. var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
  552. snippet.guard = guardRe.exec(val)[1];
  553. snippet.trigger = guardRe.exec(val)[1];
  554. snippet.endTrigger = guardRe.exec(val)[1];
  555. snippet.endGuard = guardRe.exec(val)[1];
  556. }
  557. else if (key == "snippet") {
  558. snippet.tabTrigger = val.match(/^\S*/)[0];
  559. if (!snippet.name)
  560. snippet.name = val;
  561. }
  562. else if (key) {
  563. snippet[key] = val;
  564. }
  565. }
  566. }
  567. return list;
  568. };
  569. SnippetManager.prototype.getSnippetByName = function (name, editor) {
  570. var snippetMap = this.snippetNameMap;
  571. var snippet;
  572. this.getActiveScopes(editor).some(function (scope) {
  573. var snippets = snippetMap[scope];
  574. if (snippets)
  575. snippet = snippets[name];
  576. return !!snippet;
  577. }, this);
  578. return snippet;
  579. };
  580. return SnippetManager;
  581. }());
  582. oop.implement(SnippetManager.prototype, EventEmitter);
  583. var processSnippetText = function (editor, snippetText, options) {
  584. if (options === void 0) { options = {}; }
  585. var cursor = editor.getCursorPosition();
  586. var line = editor.session.getLine(cursor.row);
  587. var tabString = editor.session.getTabString();
  588. var indentString = line.match(/^\s*/)[0];
  589. if (cursor.column < indentString.length)
  590. indentString = indentString.slice(0, cursor.column);
  591. snippetText = snippetText.replace(/\r/g, "");
  592. var tokens = this.tokenizeTmSnippet(snippetText);
  593. tokens = this.resolveVariables(tokens, editor);
  594. tokens = tokens.map(function (x) {
  595. if (x == "\n" && !options.excludeExtraIndent)
  596. return x + indentString;
  597. if (typeof x == "string")
  598. return x.replace(/\t/g, tabString);
  599. return x;
  600. });
  601. var tabstops = [];
  602. tokens.forEach(function (p, i) {
  603. if (typeof p != "object")
  604. return;
  605. var id = p.tabstopId;
  606. var ts = tabstops[id];
  607. if (!ts) {
  608. ts = tabstops[id] = [];
  609. ts.index = id;
  610. ts.value = "";
  611. ts.parents = {};
  612. }
  613. if (ts.indexOf(p) !== -1)
  614. return;
  615. if (p.choices && !ts.choices)
  616. ts.choices = p.choices;
  617. ts.push(p);
  618. var i1 = tokens.indexOf(p, i + 1);
  619. if (i1 === -1)
  620. return;
  621. var value = tokens.slice(i + 1, i1);
  622. var isNested = value.some(function (t) { return typeof t === "object"; });
  623. if (isNested && !ts.value) {
  624. ts.value = value;
  625. }
  626. else if (value.length && (!ts.value || typeof ts.value !== "string")) {
  627. ts.value = value.join("");
  628. }
  629. });
  630. tabstops.forEach(function (ts) { ts.length = 0; });
  631. var expanding = {};
  632. function copyValue(val) {
  633. var copy = [];
  634. for (var i = 0; i < val.length; i++) {
  635. var p = val[i];
  636. if (typeof p == "object") {
  637. if (expanding[p.tabstopId])
  638. continue;
  639. var j = val.lastIndexOf(p, i - 1);
  640. p = copy[j] || { tabstopId: p.tabstopId };
  641. }
  642. copy[i] = p;
  643. }
  644. return copy;
  645. }
  646. for (var i = 0; i < tokens.length; i++) {
  647. var p = tokens[i];
  648. if (typeof p != "object")
  649. continue;
  650. var id = p.tabstopId;
  651. var ts = tabstops[id];
  652. var i1 = tokens.indexOf(p, i + 1);
  653. if (expanding[id]) {
  654. if (expanding[id] === p) {
  655. delete expanding[id];
  656. Object.keys(expanding).forEach(function (parentId) {
  657. ts.parents[parentId] = true;
  658. });
  659. }
  660. continue;
  661. }
  662. expanding[id] = p;
  663. var value = ts.value;
  664. if (typeof value !== "string")
  665. value = copyValue(value);
  666. else if (p.fmt)
  667. value = this.tmStrFormat(value, p, editor);
  668. tokens.splice.apply(tokens, [i + 1, Math.max(0, i1 - i)].concat(value, p));
  669. if (ts.indexOf(p) === -1)
  670. ts.push(p);
  671. }
  672. var row = 0, column = 0;
  673. var text = "";
  674. tokens.forEach(function (t) {
  675. if (typeof t === "string") {
  676. var lines = t.split("\n");
  677. if (lines.length > 1) {
  678. column = lines[lines.length - 1].length;
  679. row += lines.length - 1;
  680. }
  681. else
  682. column += t.length;
  683. text += t;
  684. }
  685. else if (t) {
  686. if (!t.start)
  687. t.start = { row: row, column: column };
  688. else
  689. t.end = { row: row, column: column };
  690. }
  691. });
  692. return {
  693. text: text,
  694. tabstops: tabstops,
  695. tokens: tokens
  696. };
  697. };
  698. var TabstopManager = /** @class */ (function () {
  699. function TabstopManager(editor) {
  700. this.index = 0;
  701. this.ranges = [];
  702. this.tabstops = [];
  703. if (editor.tabstopManager)
  704. return editor.tabstopManager;
  705. editor.tabstopManager = this;
  706. this.$onChange = this.onChange.bind(this);
  707. this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
  708. this.$onChangeSession = this.onChangeSession.bind(this);
  709. this.$onAfterExec = this.onAfterExec.bind(this);
  710. this.attach(editor);
  711. }
  712. TabstopManager.prototype.attach = function (editor) {
  713. this.$openTabstops = null;
  714. this.selectedTabstop = null;
  715. this.editor = editor;
  716. this.session = editor.session;
  717. this.editor.on("change", this.$onChange);
  718. this.editor.on("changeSelection", this.$onChangeSelection);
  719. this.editor.on("changeSession", this.$onChangeSession);
  720. this.editor.commands.on("afterExec", this.$onAfterExec);
  721. this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
  722. };
  723. TabstopManager.prototype.detach = function () {
  724. this.tabstops.forEach(this.removeTabstopMarkers, this);
  725. this.ranges.length = 0;
  726. this.tabstops.length = 0;
  727. this.selectedTabstop = null;
  728. this.editor.off("change", this.$onChange);
  729. this.editor.off("changeSelection", this.$onChangeSelection);
  730. this.editor.off("changeSession", this.$onChangeSession);
  731. this.editor.commands.off("afterExec", this.$onAfterExec);
  732. this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
  733. this.editor.tabstopManager = null;
  734. this.session = null;
  735. this.editor = null;
  736. };
  737. TabstopManager.prototype.onChange = function (delta) {
  738. var isRemove = delta.action[0] == "r";
  739. var selectedTabstop = this.selectedTabstop || {};
  740. var parents = selectedTabstop.parents || {};
  741. var tabstops = this.tabstops.slice();
  742. for (var i = 0; i < tabstops.length; i++) {
  743. var ts = tabstops[i];
  744. var active = ts == selectedTabstop || parents[ts.index];
  745. ts.rangeList.$bias = active ? 0 : 1;
  746. if (delta.action == "remove" && ts !== selectedTabstop) {
  747. var parentActive = ts.parents && ts.parents[selectedTabstop.index];
  748. var startIndex = ts.rangeList.pointIndex(delta.start, parentActive);
  749. startIndex = startIndex < 0 ? -startIndex - 1 : startIndex + 1;
  750. var endIndex = ts.rangeList.pointIndex(delta.end, parentActive);
  751. endIndex = endIndex < 0 ? -endIndex - 1 : endIndex - 1;
  752. var toRemove = ts.rangeList.ranges.slice(startIndex, endIndex);
  753. for (var j = 0; j < toRemove.length; j++)
  754. this.removeRange(toRemove[j]);
  755. }
  756. ts.rangeList.$onChange(delta);
  757. }
  758. var session = this.session;
  759. if (!this.$inChange && isRemove && session.getLength() == 1 && !session.getValue())
  760. this.detach();
  761. };
  762. TabstopManager.prototype.updateLinkedFields = function () {
  763. var ts = this.selectedTabstop;
  764. if (!ts || !ts.hasLinkedRanges || !ts.firstNonLinked)
  765. return;
  766. this.$inChange = true;
  767. var session = this.session;
  768. var text = session.getTextRange(ts.firstNonLinked);
  769. for (var i = 0; i < ts.length; i++) {
  770. var range = ts[i];
  771. if (!range.linked)
  772. continue;
  773. var original = range.original;
  774. var fmt = exports.snippetManager.tmStrFormat(text, original, this.editor);
  775. session.replace(range, fmt);
  776. }
  777. this.$inChange = false;
  778. };
  779. TabstopManager.prototype.onAfterExec = function (e) {
  780. if (e.command && !e.command.readOnly)
  781. this.updateLinkedFields();
  782. };
  783. TabstopManager.prototype.onChangeSelection = function () {
  784. if (!this.editor)
  785. return;
  786. var lead = this.editor.selection.lead;
  787. var anchor = this.editor.selection.anchor;
  788. var isEmpty = this.editor.selection.isEmpty();
  789. for (var i = 0; i < this.ranges.length; i++) {
  790. if (this.ranges[i].linked)
  791. continue;
  792. var containsLead = this.ranges[i].contains(lead.row, lead.column);
  793. var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
  794. if (containsLead && containsAnchor)
  795. return;
  796. }
  797. this.detach();
  798. };
  799. TabstopManager.prototype.onChangeSession = function () {
  800. this.detach();
  801. };
  802. TabstopManager.prototype.tabNext = function (dir) {
  803. var max = this.tabstops.length;
  804. var index = this.index + (dir || 1);
  805. index = Math.min(Math.max(index, 1), max);
  806. if (index == max)
  807. index = 0;
  808. this.selectTabstop(index);
  809. this.updateTabstopMarkers();
  810. if (index === 0) {
  811. this.detach();
  812. }
  813. };
  814. TabstopManager.prototype.selectTabstop = function (index) {
  815. this.$openTabstops = null;
  816. var ts = this.tabstops[this.index];
  817. if (ts)
  818. this.addTabstopMarkers(ts);
  819. this.index = index;
  820. ts = this.tabstops[this.index];
  821. if (!ts || !ts.length)
  822. return;
  823. this.selectedTabstop = ts;
  824. var range = ts.firstNonLinked || ts;
  825. if (ts.choices)
  826. range.cursor = range.start;
  827. if (!this.editor.inVirtualSelectionMode) {
  828. var sel = this.editor.multiSelect;
  829. sel.toSingleRange(range);
  830. for (var i = 0; i < ts.length; i++) {
  831. if (ts.hasLinkedRanges && ts[i].linked)
  832. continue;
  833. sel.addRange(ts[i].clone(), true);
  834. }
  835. }
  836. else {
  837. this.editor.selection.fromOrientedRange(range);
  838. }
  839. this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
  840. if (this.selectedTabstop && this.selectedTabstop.choices)
  841. this.editor.execCommand("startAutocomplete", { matches: this.selectedTabstop.choices });
  842. };
  843. TabstopManager.prototype.addTabstops = function (tabstops, start, end) {
  844. var useLink = this.useLink || !this.editor.getOption("enableMultiselect");
  845. if (!this.$openTabstops)
  846. this.$openTabstops = [];
  847. if (!tabstops[0]) {
  848. var p = Range.fromPoints(end, end);
  849. moveRelative(p.start, start);
  850. moveRelative(p.end, start);
  851. tabstops[0] = [p];
  852. tabstops[0].index = 0;
  853. }
  854. var i = this.index;
  855. var arg = [i + 1, 0];
  856. var ranges = this.ranges;
  857. var snippetId = this.snippetId = (this.snippetId || 0) + 1;
  858. tabstops.forEach(function (ts, index) {
  859. var dest = this.$openTabstops[index] || ts;
  860. dest.snippetId = snippetId;
  861. for (var i = 0; i < ts.length; i++) {
  862. var p = ts[i];
  863. var range = Range.fromPoints(p.start, p.end || p.start);
  864. movePoint(range.start, start);
  865. movePoint(range.end, start);
  866. range.original = p;
  867. range.tabstop = dest;
  868. ranges.push(range);
  869. if (dest != ts)
  870. dest.unshift(range);
  871. else
  872. dest[i] = range;
  873. if (p.fmtString || (dest.firstNonLinked && useLink)) {
  874. range.linked = true;
  875. dest.hasLinkedRanges = true;
  876. }
  877. else if (!dest.firstNonLinked)
  878. dest.firstNonLinked = range;
  879. }
  880. if (!dest.firstNonLinked)
  881. dest.hasLinkedRanges = false;
  882. if (dest === ts) {
  883. arg.push(dest);
  884. this.$openTabstops[index] = dest;
  885. }
  886. this.addTabstopMarkers(dest);
  887. dest.rangeList = dest.rangeList || new RangeList();
  888. dest.rangeList.$bias = 0;
  889. dest.rangeList.addList(dest);
  890. }, this);
  891. if (arg.length > 2) {
  892. if (this.tabstops.length)
  893. arg.push(arg.splice(2, 1)[0]);
  894. this.tabstops.splice.apply(this.tabstops, arg);
  895. }
  896. };
  897. TabstopManager.prototype.addTabstopMarkers = function (ts) {
  898. var session = this.session;
  899. ts.forEach(function (range) {
  900. if (!range.markerId)
  901. range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
  902. });
  903. };
  904. TabstopManager.prototype.removeTabstopMarkers = function (ts) {
  905. var session = this.session;
  906. ts.forEach(function (range) {
  907. session.removeMarker(range.markerId);
  908. range.markerId = null;
  909. });
  910. };
  911. TabstopManager.prototype.updateTabstopMarkers = function () {
  912. if (!this.selectedTabstop)
  913. return;
  914. var currentSnippetId = this.selectedTabstop.snippetId;
  915. if (this.selectedTabstop.index === 0) {
  916. currentSnippetId--;
  917. }
  918. this.tabstops.forEach(function (ts) {
  919. if (ts.snippetId === currentSnippetId)
  920. this.addTabstopMarkers(ts);
  921. else
  922. this.removeTabstopMarkers(ts);
  923. }, this);
  924. };
  925. TabstopManager.prototype.removeRange = function (range) {
  926. var i = range.tabstop.indexOf(range);
  927. if (i != -1)
  928. range.tabstop.splice(i, 1);
  929. i = this.ranges.indexOf(range);
  930. if (i != -1)
  931. this.ranges.splice(i, 1);
  932. i = range.tabstop.rangeList.ranges.indexOf(range);
  933. if (i != -1)
  934. range.tabstop.splice(i, 1);
  935. this.session.removeMarker(range.markerId);
  936. if (!range.tabstop.length) {
  937. i = this.tabstops.indexOf(range.tabstop);
  938. if (i != -1)
  939. this.tabstops.splice(i, 1);
  940. if (!this.tabstops.length)
  941. this.detach();
  942. }
  943. };
  944. return TabstopManager;
  945. }());
  946. TabstopManager.prototype.keyboardHandler = new HashHandler();
  947. TabstopManager.prototype.keyboardHandler.bindKeys({
  948. "Tab": function (editor) {
  949. if (exports.snippetManager && exports.snippetManager.expandWithTab(editor))
  950. return;
  951. editor.tabstopManager.tabNext(1);
  952. editor.renderer.scrollCursorIntoView();
  953. },
  954. "Shift-Tab": function (editor) {
  955. editor.tabstopManager.tabNext(-1);
  956. editor.renderer.scrollCursorIntoView();
  957. },
  958. "Esc": function (editor) {
  959. editor.tabstopManager.detach();
  960. }
  961. });
  962. var movePoint = function (point, diff) {
  963. if (point.row == 0)
  964. point.column += diff.column;
  965. point.row += diff.row;
  966. };
  967. var moveRelative = function (point, start) {
  968. if (point.row == start.row)
  969. point.column -= start.column;
  970. point.row -= start.row;
  971. };
  972. dom.importCssString("\n.ace_snippet-marker {\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n background: rgba(194, 193, 208, 0.09);\n border: 1px dotted rgba(211, 208, 235, 0.62);\n position: absolute;\n}", "snippets.css", false);
  973. exports.snippetManager = new SnippetManager();
  974. var Editor = require("./editor").Editor;
  975. (function () {
  976. this.insertSnippet = function (content, options) {
  977. return exports.snippetManager.insertSnippet(this, content, options);
  978. };
  979. this.expandSnippet = function (options) {
  980. return exports.snippetManager.expandWithTab(this, options);
  981. };
  982. }).call(Editor.prototype);
  983. });
  984. ace.define("ace/autocomplete/inline_screenreader",["require","exports","module"], function(require, exports, module){"use strict";
  985. var AceInlineScreenReader = /** @class */ (function () {
  986. function AceInlineScreenReader(editor) {
  987. this.editor = editor;
  988. this.screenReaderDiv = document.createElement("div");
  989. this.screenReaderDiv.classList.add("ace_screenreader-only");
  990. this.editor.container.appendChild(this.screenReaderDiv);
  991. }
  992. AceInlineScreenReader.prototype.setScreenReaderContent = function (content) {
  993. if (!this.popup && this.editor.completer && /**@type{import("../autocomplete").Autocomplete}*/ (this.editor.completer).popup) {
  994. this.popup = /**@type{import("../autocomplete").Autocomplete}*/ (this.editor.completer).popup;
  995. this.popup.renderer.on("afterRender", function () {
  996. var row = this.popup.getRow();
  997. var t = this.popup.renderer.$textLayer;
  998. var selected = t.element.childNodes[row - t.config.firstRow];
  999. if (selected) {
  1000. var idString = "doc-tooltip ";
  1001. for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) {
  1002. idString += "ace-inline-screenreader-line-".concat(lineIndex, " ");
  1003. }
  1004. selected.setAttribute("aria-describedby", idString);
  1005. }
  1006. }.bind(this));
  1007. }
  1008. while (this.screenReaderDiv.firstChild) {
  1009. this.screenReaderDiv.removeChild(this.screenReaderDiv.firstChild);
  1010. }
  1011. this._lines = content.split(/\r\n|\r|\n/);
  1012. var codeElement = this.createCodeBlock();
  1013. this.screenReaderDiv.appendChild(codeElement);
  1014. };
  1015. AceInlineScreenReader.prototype.destroy = function () {
  1016. this.screenReaderDiv.remove();
  1017. };
  1018. AceInlineScreenReader.prototype.createCodeBlock = function () {
  1019. var container = document.createElement("pre");
  1020. container.setAttribute("id", "ace-inline-screenreader");
  1021. for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex++) {
  1022. var codeElement = document.createElement("code");
  1023. codeElement.setAttribute("id", "ace-inline-screenreader-line-".concat(lineIndex));
  1024. var line = document.createTextNode(this._lines[lineIndex]);
  1025. codeElement.appendChild(line);
  1026. container.appendChild(codeElement);
  1027. }
  1028. return container;
  1029. };
  1030. return AceInlineScreenReader;
  1031. }());
  1032. exports.AceInlineScreenReader = AceInlineScreenReader;
  1033. });
  1034. ace.define("ace/autocomplete/inline",["require","exports","module","ace/snippets","ace/autocomplete/inline_screenreader"], function(require, exports, module){"use strict";
  1035. var snippetManager = require("../snippets").snippetManager;
  1036. var AceInlineScreenReader = require("./inline_screenreader").AceInlineScreenReader;
  1037. var AceInline = /** @class */ (function () {
  1038. function AceInline() {
  1039. this.editor = null;
  1040. }
  1041. AceInline.prototype.show = function (editor, completion, prefix) {
  1042. prefix = prefix || "";
  1043. if (editor && this.editor && this.editor !== editor) {
  1044. this.hide();
  1045. this.editor = null;
  1046. this.inlineScreenReader = null;
  1047. }
  1048. if (!editor || !completion) {
  1049. return false;
  1050. }
  1051. if (!this.inlineScreenReader) {
  1052. this.inlineScreenReader = new AceInlineScreenReader(editor);
  1053. }
  1054. var displayText = completion.snippet ? snippetManager.getDisplayTextForSnippet(editor, completion.snippet) : completion.value;
  1055. if (completion.hideInlinePreview || !displayText || !displayText.startsWith(prefix)) {
  1056. return false;
  1057. }
  1058. this.editor = editor;
  1059. this.inlineScreenReader.setScreenReaderContent(displayText);
  1060. displayText = displayText.slice(prefix.length);
  1061. if (displayText === "") {
  1062. editor.removeGhostText();
  1063. }
  1064. else {
  1065. editor.setGhostText(displayText);
  1066. }
  1067. return true;
  1068. };
  1069. AceInline.prototype.isOpen = function () {
  1070. if (!this.editor) {
  1071. return false;
  1072. }
  1073. return !!this.editor.renderer.$ghostText;
  1074. };
  1075. AceInline.prototype.hide = function () {
  1076. if (!this.editor) {
  1077. return false;
  1078. }
  1079. this.editor.removeGhostText();
  1080. return true;
  1081. };
  1082. AceInline.prototype.destroy = function () {
  1083. this.hide();
  1084. this.editor = null;
  1085. if (this.inlineScreenReader) {
  1086. this.inlineScreenReader.destroy();
  1087. this.inlineScreenReader = null;
  1088. }
  1089. };
  1090. return AceInline;
  1091. }());
  1092. exports.AceInline = AceInline;
  1093. });
  1094. 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";
  1095. var Renderer = require("../virtual_renderer").VirtualRenderer;
  1096. var Editor = require("../editor").Editor;
  1097. var Range = require("../range").Range;
  1098. var event = require("../lib/event");
  1099. var lang = require("../lib/lang");
  1100. var dom = require("../lib/dom");
  1101. var nls = require("../config").nls;
  1102. var userAgent = require("./../lib/useragent");
  1103. var getAriaId = function (index) {
  1104. return "suggest-aria-id:".concat(index);
  1105. };
  1106. var popupAriaRole = userAgent.isSafari ? "menu" : "listbox";
  1107. var optionAriaRole = userAgent.isSafari ? "menuitem" : "option";
  1108. var ariaActiveState = userAgent.isSafari ? "aria-current" : "aria-selected";
  1109. var $singleLineEditor = function (el) {
  1110. var renderer = new Renderer(el);
  1111. renderer.$maxLines = 4;
  1112. var editor = new Editor(renderer);
  1113. editor.setHighlightActiveLine(false);
  1114. editor.setShowPrintMargin(false);
  1115. editor.renderer.setShowGutter(false);
  1116. editor.renderer.setHighlightGutterLine(false);
  1117. editor.$mouseHandler.$focusTimeout = 0;
  1118. editor.$highlightTagPending = true;
  1119. return editor;
  1120. };
  1121. var AcePopup = /** @class */ (function () {
  1122. function AcePopup(parentNode) {
  1123. var el = dom.createElement("div");
  1124. var popup = $singleLineEditor(el);
  1125. if (parentNode) {
  1126. parentNode.appendChild(el);
  1127. }
  1128. el.style.display = "none";
  1129. popup.renderer.content.style.cursor = "default";
  1130. popup.renderer.setStyle("ace_autocomplete");
  1131. popup.renderer.$textLayer.element.setAttribute("role", popupAriaRole);
  1132. popup.renderer.$textLayer.element.setAttribute("aria-roledescription", nls("autocomplete.popup.aria-roledescription", "Autocomplete suggestions"));
  1133. popup.renderer.$textLayer.element.setAttribute("aria-label", nls("autocomplete.popup.aria-label", "Autocomplete suggestions"));
  1134. popup.renderer.textarea.setAttribute("aria-hidden", "true");
  1135. popup.setOption("displayIndentGuides", false);
  1136. popup.setOption("dragDelay", 150);
  1137. var noop = function () { };
  1138. popup.focus = noop;
  1139. popup.$isFocused = true;
  1140. popup.renderer.$cursorLayer.restartTimer = noop;
  1141. popup.renderer.$cursorLayer.element.style.opacity = "0";
  1142. popup.renderer.$maxLines = 8;
  1143. popup.renderer.$keepTextAreaAtCursor = false;
  1144. popup.setHighlightActiveLine(false);
  1145. popup.session.highlight("");
  1146. popup.session.$searchHighlight.clazz = "ace_highlight-marker";
  1147. popup.on("mousedown", function (e) {
  1148. var pos = e.getDocumentPosition();
  1149. popup.selection.moveToPosition(pos);
  1150. selectionMarker.start.row = selectionMarker.end.row = pos.row;
  1151. e.stop();
  1152. });
  1153. var lastMouseEvent;
  1154. var hoverMarker = new Range(-1, 0, -1, Infinity);
  1155. var selectionMarker = new Range(-1, 0, -1, Infinity);
  1156. selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
  1157. popup.setSelectOnHover = function (val) {
  1158. if (!val) {
  1159. hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
  1160. }
  1161. else if (hoverMarker.id) {
  1162. popup.session.removeMarker(hoverMarker.id);
  1163. hoverMarker.id = null;
  1164. }
  1165. };
  1166. popup.setSelectOnHover(false);
  1167. popup.on("mousemove", function (e) {
  1168. if (!lastMouseEvent) {
  1169. lastMouseEvent = e;
  1170. return;
  1171. }
  1172. if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
  1173. return;
  1174. }
  1175. lastMouseEvent = e;
  1176. lastMouseEvent.scrollTop = popup.renderer.scrollTop;
  1177. popup.isMouseOver = true;
  1178. var row = lastMouseEvent.getDocumentPosition().row;
  1179. if (hoverMarker.start.row != row) {
  1180. if (!hoverMarker.id)
  1181. popup.setRow(row);
  1182. setHoverMarker(row);
  1183. }
  1184. });
  1185. popup.renderer.on("beforeRender", function () {
  1186. if (lastMouseEvent && hoverMarker.start.row != -1) {
  1187. lastMouseEvent.$pos = null;
  1188. var row = lastMouseEvent.getDocumentPosition().row;
  1189. if (!hoverMarker.id)
  1190. popup.setRow(row);
  1191. setHoverMarker(row, true);
  1192. }
  1193. });
  1194. popup.renderer.on("afterRender", function () {
  1195. var t = popup.renderer.$textLayer;
  1196. for (var row = t.config.firstRow, l = t.config.lastRow; row <= l; row++) {
  1197. var popupRowElement = /** @type {HTMLElement|null} */ (t.element.childNodes[row - t.config.firstRow]);
  1198. popupRowElement.setAttribute("role", optionAriaRole);
  1199. popupRowElement.setAttribute("aria-roledescription", nls("autocomplete.popup.item.aria-roledescription", "item"));
  1200. popupRowElement.setAttribute("aria-setsize", popup.data.length);
  1201. popupRowElement.setAttribute("aria-describedby", "doc-tooltip");
  1202. popupRowElement.setAttribute("aria-posinset", row + 1);
  1203. var rowData = popup.getData(row);
  1204. if (rowData) {
  1205. var ariaLabel = "".concat(rowData.caption || rowData.value).concat(rowData.meta ? ", ".concat(rowData.meta) : '');
  1206. popupRowElement.setAttribute("aria-label", ariaLabel);
  1207. }
  1208. var highlightedSpans = popupRowElement.querySelectorAll(".ace_completion-highlight");
  1209. highlightedSpans.forEach(function (span) {
  1210. span.setAttribute("role", "mark");
  1211. });
  1212. }
  1213. });
  1214. popup.renderer.on("afterRender", function () {
  1215. var row = popup.getRow();
  1216. var t = popup.renderer.$textLayer;
  1217. var selected = /** @type {HTMLElement|null} */ (t.element.childNodes[row - t.config.firstRow]);
  1218. var el = document.activeElement; // Active element is textarea of main editor
  1219. if (selected !== popup.selectedNode && popup.selectedNode) {
  1220. dom.removeCssClass(popup.selectedNode, "ace_selected");
  1221. popup.selectedNode.removeAttribute(ariaActiveState);
  1222. popup.selectedNode.removeAttribute("id");
  1223. }
  1224. el.removeAttribute("aria-activedescendant");
  1225. popup.selectedNode = selected;
  1226. if (selected) {
  1227. var ariaId = getAriaId(row);
  1228. dom.addCssClass(selected, "ace_selected");
  1229. selected.id = ariaId;
  1230. t.element.setAttribute("aria-activedescendant", ariaId);
  1231. el.setAttribute("aria-activedescendant", ariaId);
  1232. selected.setAttribute(ariaActiveState, "true");
  1233. }
  1234. });
  1235. var hideHoverMarker = function () { setHoverMarker(-1); };
  1236. var setHoverMarker = function (row, suppressRedraw) {
  1237. if (row !== hoverMarker.start.row) {
  1238. hoverMarker.start.row = hoverMarker.end.row = row;
  1239. if (!suppressRedraw)
  1240. popup.session._emit("changeBackMarker");
  1241. popup._emit("changeHoverMarker");
  1242. }
  1243. };
  1244. popup.getHoveredRow = function () {
  1245. return hoverMarker.start.row;
  1246. };
  1247. event.addListener(popup.container, "mouseout", function () {
  1248. popup.isMouseOver = false;
  1249. hideHoverMarker();
  1250. });
  1251. popup.on("hide", hideHoverMarker);
  1252. popup.on("changeSelection", hideHoverMarker);
  1253. popup.session.doc.getLength = function () {
  1254. return popup.data.length;
  1255. };
  1256. popup.session.doc.getLine = function (i) {
  1257. var data = popup.data[i];
  1258. if (typeof data == "string")
  1259. return data;
  1260. return (data && data.value) || "";
  1261. };
  1262. var bgTokenizer = popup.session.bgTokenizer;
  1263. bgTokenizer.$tokenizeRow = function (row) {
  1264. var data = popup.data[row];
  1265. var tokens = [];
  1266. if (!data)
  1267. return tokens;
  1268. if (typeof data == "string")
  1269. data = { value: data };
  1270. var caption = data.caption || data.value || data.name;
  1271. function addToken(value, className) {
  1272. value && tokens.push({
  1273. type: (data.className || "") + (className || ""),
  1274. value: value
  1275. });
  1276. }
  1277. var lower = caption.toLowerCase();
  1278. var filterText = (popup.filterText || "").toLowerCase();
  1279. var lastIndex = 0;
  1280. var lastI = 0;
  1281. for (var i = 0; i <= filterText.length; i++) {
  1282. if (i != lastI && (data.matchMask & (1 << i) || i == filterText.length)) {
  1283. var sub = filterText.slice(lastI, i);
  1284. lastI = i;
  1285. var index = lower.indexOf(sub, lastIndex);
  1286. if (index == -1)
  1287. continue;
  1288. addToken(caption.slice(lastIndex, index), "");
  1289. lastIndex = index + sub.length;
  1290. addToken(caption.slice(index, lastIndex), "completion-highlight");
  1291. }
  1292. }
  1293. addToken(caption.slice(lastIndex, caption.length), "");
  1294. tokens.push({ type: "completion-spacer", value: " " });
  1295. if (data.meta)
  1296. tokens.push({ type: "completion-meta", value: data.meta });
  1297. if (data.message)
  1298. tokens.push({ type: "completion-message", value: data.message });
  1299. return tokens;
  1300. };
  1301. bgTokenizer.$updateOnChange = noop;
  1302. bgTokenizer.start = noop;
  1303. popup.session.$computeWidth = function () {
  1304. return this.screenWidth = 0;
  1305. };
  1306. popup.isOpen = false;
  1307. popup.isTopdown = false;
  1308. popup.autoSelect = true;
  1309. popup.filterText = "";
  1310. popup.isMouseOver = false;
  1311. popup.data = [];
  1312. popup.setData = function (list, filterText) {
  1313. popup.filterText = filterText || "";
  1314. popup.setValue(lang.stringRepeat("\n", list.length), -1);
  1315. popup.data = list || [];
  1316. popup.setRow(0);
  1317. };
  1318. popup.getData = function (row) {
  1319. return popup.data[row];
  1320. };
  1321. popup.getRow = function () {
  1322. return selectionMarker.start.row;
  1323. };
  1324. popup.setRow = function (line) {
  1325. line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line));
  1326. if (selectionMarker.start.row != line) {
  1327. popup.selection.clearSelection();
  1328. selectionMarker.start.row = selectionMarker.end.row = line || 0;
  1329. popup.session._emit("changeBackMarker");
  1330. popup.moveCursorTo(line || 0, 0);
  1331. if (popup.isOpen)
  1332. popup._signal("select");
  1333. }
  1334. };
  1335. popup.on("changeSelection", function () {
  1336. if (popup.isOpen)
  1337. popup.setRow(popup.selection.lead.row);
  1338. popup.renderer.scrollCursorIntoView();
  1339. });
  1340. popup.hide = function () {
  1341. this.container.style.display = "none";
  1342. popup.anchorPos = null;
  1343. popup.anchor = null;
  1344. if (popup.isOpen) {
  1345. popup.isOpen = false;
  1346. this._signal("hide");
  1347. }
  1348. };
  1349. popup.tryShow = function (pos, lineHeight, anchor, forceShow) {
  1350. if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor &&
  1351. popup.anchorPos.top === pos.top && popup.anchorPos.left === pos.left &&
  1352. popup.anchor === anchor) {
  1353. return true;
  1354. }
  1355. var el = this.container;
  1356. var scrollBarSize = this.renderer.scrollBar.width || 10;
  1357. var screenHeight = window.innerHeight - scrollBarSize;
  1358. var screenWidth = window.innerWidth - scrollBarSize;
  1359. var renderer = this.renderer;
  1360. var maxH = renderer.$maxLines * lineHeight * 1.4;
  1361. var dims = { top: 0, bottom: 0, left: 0 };
  1362. var spaceBelow = screenHeight - pos.top - 3 * this.$borderSize - lineHeight;
  1363. var spaceAbove = pos.top - 3 * this.$borderSize;
  1364. if (!anchor) {
  1365. if (spaceAbove <= spaceBelow || spaceBelow >= maxH) {
  1366. anchor = "bottom";
  1367. }
  1368. else {
  1369. anchor = "top";
  1370. }
  1371. }
  1372. if (anchor === "top") {
  1373. dims.bottom = pos.top - this.$borderSize;
  1374. dims.top = dims.bottom - maxH;
  1375. }
  1376. else if (anchor === "bottom") {
  1377. dims.top = pos.top + lineHeight + this.$borderSize;
  1378. dims.bottom = dims.top + maxH;
  1379. }
  1380. var fitsX = dims.top >= 0 && dims.bottom <= screenHeight;
  1381. if (!forceShow && !fitsX) {
  1382. return false;
  1383. }
  1384. if (!fitsX) {
  1385. if (anchor === "top") {
  1386. renderer.$maxPixelHeight = spaceAbove;
  1387. }
  1388. else {
  1389. renderer.$maxPixelHeight = spaceBelow;
  1390. }
  1391. }
  1392. else {
  1393. renderer.$maxPixelHeight = null;
  1394. }
  1395. if (anchor === "top") {
  1396. el.style.top = "";
  1397. el.style.bottom = (screenHeight + scrollBarSize - dims.bottom) + "px";
  1398. popup.isTopdown = false;
  1399. }
  1400. else {
  1401. el.style.top = dims.top + "px";
  1402. el.style.bottom = "";
  1403. popup.isTopdown = true;
  1404. }
  1405. el.style.display = "";
  1406. var left = pos.left;
  1407. if (left + el.offsetWidth > screenWidth)
  1408. left = screenWidth - el.offsetWidth;
  1409. el.style.left = left + "px";
  1410. el.style.right = "";
  1411. if (!popup.isOpen) {
  1412. popup.isOpen = true;
  1413. this._signal("show");
  1414. lastMouseEvent = null;
  1415. }
  1416. popup.anchorPos = pos;
  1417. popup.anchor = anchor;
  1418. return true;
  1419. };
  1420. popup.show = function (pos, lineHeight, topdownOnly) {
  1421. this.tryShow(pos, lineHeight, topdownOnly ? "bottom" : undefined, true);
  1422. };
  1423. popup.goTo = function (where) {
  1424. var row = this.getRow();
  1425. var max = this.session.getLength() - 1;
  1426. switch (where) {
  1427. case "up":
  1428. row = row <= 0 ? max : row - 1;
  1429. break;
  1430. case "down":
  1431. row = row >= max ? -1 : row + 1;
  1432. break;
  1433. case "start":
  1434. row = 0;
  1435. break;
  1436. case "end":
  1437. row = max;
  1438. break;
  1439. }
  1440. this.setRow(row);
  1441. };
  1442. popup.getTextLeftOffset = function () {
  1443. return this.$borderSize + this.renderer.$padding + this.$imageSize;
  1444. };
  1445. popup.$imageSize = 0;
  1446. popup.$borderSize = 1;
  1447. return popup;
  1448. }
  1449. return AcePopup;
  1450. }());
  1451. 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);
  1452. exports.AcePopup = AcePopup;
  1453. exports.$singleLineEditor = $singleLineEditor;
  1454. exports.getAriaId = getAriaId;
  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/command_bar",["require","exports","module","ace/tooltip","ace/lib/event_emitter","ace/lib/lang","ace/lib/dom","ace/lib/oop","ace/lib/useragent"], function(require, exports, module){var __values = (this && this.__values) || function(o) {
  2355. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  2356. if (m) return m.call(o);
  2357. if (o && typeof o.length === "number") return {
  2358. next: function () {
  2359. if (o && i >= o.length) o = void 0;
  2360. return { value: o && o[i++], done: !o };
  2361. }
  2362. };
  2363. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  2364. };
  2365. var Tooltip = require("../tooltip").Tooltip;
  2366. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  2367. var lang = require("../lib/lang");
  2368. var dom = require("../lib/dom");
  2369. var oop = require("../lib/oop");
  2370. var useragent = require("../lib/useragent");
  2371. var BUTTON_CLASS_NAME = 'command_bar_tooltip_button';
  2372. var VALUE_CLASS_NAME = 'command_bar_button_value';
  2373. var CAPTION_CLASS_NAME = 'command_bar_button_caption';
  2374. var KEYBINDING_CLASS_NAME = 'command_bar_keybinding';
  2375. var TOOLTIP_CLASS_NAME = 'command_bar_tooltip';
  2376. var MORE_OPTIONS_BUTTON_ID = 'MoreOptionsButton';
  2377. var defaultDelay = 100;
  2378. var defaultMaxElements = 4;
  2379. var minPosition = function (posA, posB) {
  2380. if (posB.row > posA.row) {
  2381. return posA;
  2382. }
  2383. else if (posB.row === posA.row && posB.column > posA.column) {
  2384. return posA;
  2385. }
  2386. return posB;
  2387. };
  2388. var keyDisplayMap = {
  2389. "Ctrl": { mac: "^" },
  2390. "Option": { mac: "⌥" },
  2391. "Command": { mac: "⌘" },
  2392. "Cmd": { mac: "⌘" },
  2393. "Shift": "⇧",
  2394. "Left": "←",
  2395. "Right": "→",
  2396. "Up": "↑",
  2397. "Down": "↓"
  2398. };
  2399. var CommandBarTooltip = /** @class */ (function () {
  2400. function CommandBarTooltip(parentNode, options) {
  2401. var e_1, _a;
  2402. options = options || {};
  2403. this.parentNode = parentNode;
  2404. this.tooltip = new Tooltip(this.parentNode);
  2405. this.moreOptions = new Tooltip(this.parentNode);
  2406. this.maxElementsOnTooltip = options.maxElementsOnTooltip || defaultMaxElements;
  2407. this.$alwaysShow = options.alwaysShow || false;
  2408. this.eventListeners = {};
  2409. this.elements = {};
  2410. this.commands = {};
  2411. this.tooltipEl = dom.buildDom(['div', { class: TOOLTIP_CLASS_NAME }], this.tooltip.getElement());
  2412. this.moreOptionsEl = dom.buildDom(['div', { class: TOOLTIP_CLASS_NAME + " tooltip_more_options" }], this.moreOptions.getElement());
  2413. this.$showTooltipTimer = lang.delayedCall(this.$showTooltip.bind(this), options.showDelay || defaultDelay);
  2414. this.$hideTooltipTimer = lang.delayedCall(this.$hideTooltip.bind(this), options.hideDelay || defaultDelay);
  2415. this.$tooltipEnter = this.$tooltipEnter.bind(this);
  2416. this.$onMouseMove = this.$onMouseMove.bind(this);
  2417. this.$onChangeScroll = this.$onChangeScroll.bind(this);
  2418. this.$onEditorChangeSession = this.$onEditorChangeSession.bind(this);
  2419. this.$scheduleTooltipForHide = this.$scheduleTooltipForHide.bind(this);
  2420. this.$preventMouseEvent = this.$preventMouseEvent.bind(this);
  2421. try {
  2422. for (var _b = __values(["mousedown", "mouseup", "click"]), _c = _b.next(); !_c.done; _c = _b.next()) {
  2423. var event = _c.value;
  2424. this.tooltip.getElement().addEventListener(event, this.$preventMouseEvent);
  2425. this.moreOptions.getElement().addEventListener(event, this.$preventMouseEvent);
  2426. }
  2427. }
  2428. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  2429. finally {
  2430. try {
  2431. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  2432. }
  2433. finally { if (e_1) throw e_1.error; }
  2434. }
  2435. }
  2436. CommandBarTooltip.prototype.registerCommand = function (id, command) {
  2437. var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip;
  2438. if (!registerForMainTooltip && !this.elements[MORE_OPTIONS_BUTTON_ID]) {
  2439. this.$createCommand(MORE_OPTIONS_BUTTON_ID, {
  2440. name: "···",
  2441. exec:
  2442. function () {
  2443. this.$shouldHideMoreOptions = false;
  2444. this.$setMoreOptionsVisibility(!this.isMoreOptionsShown());
  2445. }.bind(this),
  2446. type: "checkbox",
  2447. getValue: function () {
  2448. return this.isMoreOptionsShown();
  2449. }.bind(this),
  2450. enabled: true
  2451. }, true);
  2452. }
  2453. this.$createCommand(id, command, registerForMainTooltip);
  2454. if (this.isShown()) {
  2455. this.updatePosition();
  2456. }
  2457. };
  2458. CommandBarTooltip.prototype.isShown = function () {
  2459. return !!this.tooltip && this.tooltip.isOpen;
  2460. };
  2461. CommandBarTooltip.prototype.isMoreOptionsShown = function () {
  2462. return !!this.moreOptions && this.moreOptions.isOpen;
  2463. };
  2464. CommandBarTooltip.prototype.getAlwaysShow = function () {
  2465. return this.$alwaysShow;
  2466. };
  2467. CommandBarTooltip.prototype.setAlwaysShow = function (alwaysShow) {
  2468. this.$alwaysShow = alwaysShow;
  2469. this.$updateOnHoverHandlers(!this.$alwaysShow);
  2470. this._signal("alwaysShow", this.$alwaysShow);
  2471. };
  2472. CommandBarTooltip.prototype.attach = function (editor) {
  2473. if (!editor || (this.isShown() && this.editor === editor)) {
  2474. return;
  2475. }
  2476. this.detach();
  2477. this.editor = editor;
  2478. this.editor.on("changeSession", this.$onEditorChangeSession);
  2479. if (this.editor.session) {
  2480. this.editor.session.on("changeScrollLeft", this.$onChangeScroll);
  2481. this.editor.session.on("changeScrollTop", this.$onChangeScroll);
  2482. }
  2483. if (this.getAlwaysShow()) {
  2484. this.$showTooltip();
  2485. }
  2486. else {
  2487. this.$updateOnHoverHandlers(true);
  2488. }
  2489. };
  2490. CommandBarTooltip.prototype.updatePosition = function () {
  2491. if (!this.editor) {
  2492. return;
  2493. }
  2494. var renderer = this.editor.renderer;
  2495. var ranges;
  2496. if (this.editor.selection.getAllRanges) {
  2497. ranges = this.editor.selection.getAllRanges();
  2498. }
  2499. else {
  2500. ranges = [this.editor.getSelectionRange()];
  2501. }
  2502. if (!ranges.length) {
  2503. return;
  2504. }
  2505. var minPos = minPosition(ranges[0].start, ranges[0].end);
  2506. for (var i = 0, range; range = ranges[i]; i++) {
  2507. minPos = minPosition(minPos, minPosition(range.start, range.end));
  2508. }
  2509. var pos = renderer.$cursorLayer.getPixelPosition(minPos, true);
  2510. var tooltipEl = this.tooltip.getElement();
  2511. var screenWidth = window.innerWidth;
  2512. var screenHeight = window.innerHeight;
  2513. var rect = this.editor.container.getBoundingClientRect();
  2514. pos.top += rect.top - renderer.layerConfig.offset;
  2515. pos.left += rect.left + renderer.gutterWidth - renderer.scrollLeft;
  2516. var cursorVisible = pos.top >= rect.top && pos.top <= rect.bottom &&
  2517. pos.left >= rect.left + renderer.gutterWidth && pos.left <= rect.right;
  2518. if (!cursorVisible && this.isShown()) {
  2519. this.$hideTooltip();
  2520. return;
  2521. }
  2522. else if (cursorVisible && !this.isShown() && this.getAlwaysShow()) {
  2523. this.$showTooltip();
  2524. return;
  2525. }
  2526. var top = pos.top - tooltipEl.offsetHeight;
  2527. var left = Math.min(screenWidth - tooltipEl.offsetWidth, pos.left);
  2528. var tooltipFits = top >= 0 && top + tooltipEl.offsetHeight <= screenHeight &&
  2529. left >= 0 && left + tooltipEl.offsetWidth <= screenWidth;
  2530. if (!tooltipFits) {
  2531. this.$hideTooltip();
  2532. return;
  2533. }
  2534. this.tooltip.setPosition(left, top);
  2535. if (this.isMoreOptionsShown()) {
  2536. top = top + tooltipEl.offsetHeight;
  2537. left = this.elements[MORE_OPTIONS_BUTTON_ID].getBoundingClientRect().left;
  2538. var moreOptionsEl = this.moreOptions.getElement();
  2539. var screenHeight = window.innerHeight;
  2540. if (top + moreOptionsEl.offsetHeight > screenHeight) {
  2541. top -= tooltipEl.offsetHeight + moreOptionsEl.offsetHeight;
  2542. }
  2543. if (left + moreOptionsEl.offsetWidth > screenWidth) {
  2544. left = screenWidth - moreOptionsEl.offsetWidth;
  2545. }
  2546. this.moreOptions.setPosition(left, top);
  2547. }
  2548. };
  2549. CommandBarTooltip.prototype.update = function () {
  2550. Object.keys(this.elements).forEach(this.$updateElement.bind(this));
  2551. };
  2552. CommandBarTooltip.prototype.detach = function () {
  2553. this.tooltip.hide();
  2554. this.moreOptions.hide();
  2555. this.$updateOnHoverHandlers(false);
  2556. if (this.editor) {
  2557. this.editor.off("changeSession", this.$onEditorChangeSession);
  2558. if (this.editor.session) {
  2559. this.editor.session.off("changeScrollLeft", this.$onChangeScroll);
  2560. this.editor.session.off("changeScrollTop", this.$onChangeScroll);
  2561. }
  2562. }
  2563. this.$mouseInTooltip = false;
  2564. this.editor = null;
  2565. };
  2566. CommandBarTooltip.prototype.destroy = function () {
  2567. if (this.tooltip && this.moreOptions) {
  2568. this.detach();
  2569. this.tooltip.destroy();
  2570. this.moreOptions.destroy();
  2571. }
  2572. this.eventListeners = {};
  2573. this.commands = {};
  2574. this.elements = {};
  2575. this.tooltip = this.moreOptions = this.parentNode = null;
  2576. };
  2577. CommandBarTooltip.prototype.$createCommand = function (id, command, forMainTooltip) {
  2578. var parentEl = forMainTooltip ? this.tooltipEl : this.moreOptionsEl;
  2579. var keyParts = [];
  2580. var bindKey = command.bindKey;
  2581. if (bindKey) {
  2582. if (typeof bindKey === 'object') {
  2583. bindKey = useragent.isMac ? bindKey.mac : bindKey.win;
  2584. }
  2585. bindKey = bindKey.split("|")[0];
  2586. keyParts = bindKey.split("-");
  2587. keyParts = keyParts.map(function (key) {
  2588. if (keyDisplayMap[key]) {
  2589. if (typeof keyDisplayMap[key] === 'string') {
  2590. return keyDisplayMap[key];
  2591. }
  2592. else if (useragent.isMac && keyDisplayMap[key].mac) {
  2593. return keyDisplayMap[key].mac;
  2594. }
  2595. }
  2596. return key;
  2597. });
  2598. }
  2599. var buttonNode;
  2600. if (forMainTooltip && command.iconCssClass) {
  2601. buttonNode = [
  2602. 'div',
  2603. {
  2604. class: ["ace_icon_svg", command.iconCssClass].join(" "),
  2605. "aria-label": command.name + " (" + command.bindKey + ")"
  2606. }
  2607. ];
  2608. }
  2609. else {
  2610. buttonNode = [
  2611. ['div', { class: VALUE_CLASS_NAME }],
  2612. ['div', { class: CAPTION_CLASS_NAME }, command.name]
  2613. ];
  2614. if (keyParts.length) {
  2615. buttonNode.push([
  2616. 'div',
  2617. { class: KEYBINDING_CLASS_NAME },
  2618. keyParts.map(function (keyPart) {
  2619. return ['div', keyPart];
  2620. })
  2621. ]);
  2622. }
  2623. }
  2624. dom.buildDom(['div', { class: [BUTTON_CLASS_NAME, command.cssClass || ""].join(" "), ref: id }, buttonNode], parentEl, this.elements);
  2625. this.commands[id] = command;
  2626. var eventListener =
  2627. function (e) {
  2628. if (this.editor) {
  2629. this.editor.focus();
  2630. }
  2631. this.$shouldHideMoreOptions = this.isMoreOptionsShown();
  2632. if (!this.elements[id].disabled && command.exec) {
  2633. command.exec(this.editor);
  2634. }
  2635. if (this.$shouldHideMoreOptions) {
  2636. this.$setMoreOptionsVisibility(false);
  2637. }
  2638. this.update();
  2639. e.preventDefault();
  2640. }.bind(this);
  2641. this.eventListeners[id] = eventListener;
  2642. this.elements[id].addEventListener('click', eventListener.bind(this));
  2643. this.$updateElement(id);
  2644. };
  2645. CommandBarTooltip.prototype.$setMoreOptionsVisibility = function (visible) {
  2646. if (visible) {
  2647. this.moreOptions.setTheme(this.editor.renderer.theme);
  2648. this.moreOptions.setClassName(TOOLTIP_CLASS_NAME + "_wrapper");
  2649. this.moreOptions.show();
  2650. this.update();
  2651. this.updatePosition();
  2652. }
  2653. else {
  2654. this.moreOptions.hide();
  2655. }
  2656. };
  2657. CommandBarTooltip.prototype.$onEditorChangeSession = function (e) {
  2658. if (e.oldSession) {
  2659. e.oldSession.off("changeScrollTop", this.$onChangeScroll);
  2660. e.oldSession.off("changeScrollLeft", this.$onChangeScroll);
  2661. }
  2662. this.detach();
  2663. };
  2664. CommandBarTooltip.prototype.$onChangeScroll = function () {
  2665. if (this.editor.renderer && (this.isShown() || this.getAlwaysShow())) {
  2666. this.editor.renderer.once("afterRender", this.updatePosition.bind(this));
  2667. }
  2668. };
  2669. CommandBarTooltip.prototype.$onMouseMove = function (e) {
  2670. if (this.$mouseInTooltip) {
  2671. return;
  2672. }
  2673. var cursorPosition = this.editor.getCursorPosition();
  2674. var cursorScreenPosition = this.editor.renderer.textToScreenCoordinates(cursorPosition.row, cursorPosition.column);
  2675. var lineHeight = this.editor.renderer.lineHeight;
  2676. var isInCurrentLine = e.clientY >= cursorScreenPosition.pageY && e.clientY < cursorScreenPosition.pageY + lineHeight;
  2677. if (isInCurrentLine) {
  2678. if (!this.isShown() && !this.$showTooltipTimer.isPending()) {
  2679. this.$showTooltipTimer.delay();
  2680. }
  2681. if (this.$hideTooltipTimer.isPending()) {
  2682. this.$hideTooltipTimer.cancel();
  2683. }
  2684. }
  2685. else {
  2686. if (this.isShown() && !this.$hideTooltipTimer.isPending()) {
  2687. this.$hideTooltipTimer.delay();
  2688. }
  2689. if (this.$showTooltipTimer.isPending()) {
  2690. this.$showTooltipTimer.cancel();
  2691. }
  2692. }
  2693. };
  2694. CommandBarTooltip.prototype.$preventMouseEvent = function (e) {
  2695. if (this.editor) {
  2696. this.editor.focus();
  2697. }
  2698. e.preventDefault();
  2699. };
  2700. CommandBarTooltip.prototype.$scheduleTooltipForHide = function () {
  2701. this.$mouseInTooltip = false;
  2702. this.$showTooltipTimer.cancel();
  2703. this.$hideTooltipTimer.delay();
  2704. };
  2705. CommandBarTooltip.prototype.$tooltipEnter = function () {
  2706. this.$mouseInTooltip = true;
  2707. if (this.$showTooltipTimer.isPending()) {
  2708. this.$showTooltipTimer.cancel();
  2709. }
  2710. if (this.$hideTooltipTimer.isPending()) {
  2711. this.$hideTooltipTimer.cancel();
  2712. }
  2713. };
  2714. CommandBarTooltip.prototype.$updateOnHoverHandlers = function (enableHover) {
  2715. var tooltipEl = this.tooltip.getElement();
  2716. var moreOptionsEl = this.moreOptions.getElement();
  2717. if (enableHover) {
  2718. if (this.editor) {
  2719. this.editor.on("mousemove", this.$onMouseMove);
  2720. this.editor.renderer.getMouseEventTarget().addEventListener("mouseout", this.$scheduleTooltipForHide, true);
  2721. }
  2722. tooltipEl.addEventListener('mouseenter', this.$tooltipEnter);
  2723. tooltipEl.addEventListener('mouseleave', this.$scheduleTooltipForHide);
  2724. moreOptionsEl.addEventListener('mouseenter', this.$tooltipEnter);
  2725. moreOptionsEl.addEventListener('mouseleave', this.$scheduleTooltipForHide);
  2726. }
  2727. else {
  2728. if (this.editor) {
  2729. this.editor.off("mousemove", this.$onMouseMove);
  2730. this.editor.renderer.getMouseEventTarget().removeEventListener("mouseout", this.$scheduleTooltipForHide, true);
  2731. }
  2732. tooltipEl.removeEventListener('mouseenter', this.$tooltipEnter);
  2733. tooltipEl.removeEventListener('mouseleave', this.$scheduleTooltipForHide);
  2734. moreOptionsEl.removeEventListener('mouseenter', this.$tooltipEnter);
  2735. moreOptionsEl.removeEventListener('mouseleave', this.$scheduleTooltipForHide);
  2736. }
  2737. };
  2738. CommandBarTooltip.prototype.$showTooltip = function () {
  2739. if (this.isShown()) {
  2740. return;
  2741. }
  2742. this.tooltip.setTheme(this.editor.renderer.theme);
  2743. this.tooltip.setClassName(TOOLTIP_CLASS_NAME + "_wrapper");
  2744. this.tooltip.show();
  2745. this.update();
  2746. this.updatePosition();
  2747. this._signal("show");
  2748. };
  2749. CommandBarTooltip.prototype.$hideTooltip = function () {
  2750. this.$mouseInTooltip = false;
  2751. if (!this.isShown()) {
  2752. return;
  2753. }
  2754. this.moreOptions.hide();
  2755. this.tooltip.hide();
  2756. this._signal("hide");
  2757. };
  2758. CommandBarTooltip.prototype.$updateElement = function (id) {
  2759. var command = this.commands[id];
  2760. if (!command) {
  2761. return;
  2762. }
  2763. var el = this.elements[id];
  2764. var commandEnabled = command.enabled;
  2765. if (typeof commandEnabled === 'function') {
  2766. commandEnabled = commandEnabled(this.editor);
  2767. }
  2768. if (typeof command.getValue === 'function') {
  2769. var value = command.getValue(this.editor);
  2770. if (command.type === 'text') {
  2771. el.textContent = value;
  2772. }
  2773. else if (command.type === 'checkbox') {
  2774. var domCssFn = value ? dom.addCssClass : dom.removeCssClass;
  2775. var isOnTooltip = el.parentElement === this.tooltipEl;
  2776. el.ariaChecked = value;
  2777. if (isOnTooltip) {
  2778. domCssFn(el, "ace_selected");
  2779. }
  2780. else {
  2781. el = el.querySelector("." + VALUE_CLASS_NAME);
  2782. domCssFn(el, "ace_checkmark");
  2783. }
  2784. }
  2785. }
  2786. if (commandEnabled && el.disabled) {
  2787. dom.removeCssClass(el, "ace_disabled");
  2788. el.ariaDisabled = el.disabled = false;
  2789. el.removeAttribute("disabled");
  2790. }
  2791. else if (!commandEnabled && !el.disabled) {
  2792. dom.addCssClass(el, "ace_disabled");
  2793. el.ariaDisabled = el.disabled = true;
  2794. el.setAttribute("disabled", "");
  2795. }
  2796. };
  2797. return CommandBarTooltip;
  2798. }());
  2799. oop.implement(CommandBarTooltip.prototype, EventEmitter);
  2800. dom.importCssString("\n.ace_tooltip.".concat(TOOLTIP_CLASS_NAME, "_wrapper {\n padding: 0;\n}\n\n.ace_tooltip .").concat(TOOLTIP_CLASS_NAME, " {\n padding: 1px 5px;\n display: flex;\n pointer-events: auto;\n}\n\n.ace_tooltip .").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options {\n padding: 1px;\n flex-direction: column;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, " {\n display: inline-flex;\n cursor: pointer;\n margin: 1px;\n border-radius: 2px;\n padding: 2px 5px;\n align-items: center;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, ".ace_selected,\ndiv.").concat(BUTTON_CLASS_NAME, ":hover:not(.ace_disabled) {\n background-color: rgba(0, 0, 0, 0.1);\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, ".ace_disabled {\n color: #777;\n pointer-events: none;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, " .ace_icon_svg {\n height: 12px;\n background-color: #000;\n}\n\ndiv.").concat(BUTTON_CLASS_NAME, ".ace_disabled .ace_icon_svg {\n background-color: #777;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options .").concat(BUTTON_CLASS_NAME, " {\n display: flex;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".").concat(VALUE_CLASS_NAME, " {\n display: none;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options .").concat(VALUE_CLASS_NAME, " {\n display: inline-block;\n width: 12px;\n}\n\n.").concat(CAPTION_CLASS_NAME, " {\n display: inline-block;\n}\n\n.").concat(KEYBINDING_CLASS_NAME, " {\n margin: 0 2px;\n display: inline-block;\n font-size: 8px;\n}\n\n.").concat(TOOLTIP_CLASS_NAME, ".tooltip_more_options .").concat(KEYBINDING_CLASS_NAME, " {\n margin-left: auto;\n}\n\n.").concat(KEYBINDING_CLASS_NAME, " div {\n display: inline-block;\n min-width: 8px;\n padding: 2px;\n margin: 0 1px;\n border-radius: 2px;\n background-color: #ccc;\n text-align: center;\n}\n\n.ace_dark.ace_tooltip .").concat(TOOLTIP_CLASS_NAME, " {\n background-color: #373737;\n color: #eee;\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ".ace_disabled {\n color: #979797;\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ".ace_selected,\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ":hover:not(.ace_disabled) {\n background-color: rgba(255, 255, 255, 0.1);\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, " .ace_icon_svg {\n background-color: #eee;\n}\n\n.ace_dark div.").concat(BUTTON_CLASS_NAME, ".ace_disabled .ace_icon_svg {\n background-color: #979797;\n}\n\n.ace_dark .").concat(BUTTON_CLASS_NAME, ".ace_disabled {\n color: #979797;\n}\n\n.ace_dark .").concat(KEYBINDING_CLASS_NAME, " div {\n background-color: #575757;\n}\n\n.ace_checkmark::before {\n content: '\u2713';\n}\n"), "commandbar.css", false);
  2801. exports.CommandBarTooltip = CommandBarTooltip;
  2802. exports.TOOLTIP_CLASS_NAME = TOOLTIP_CLASS_NAME;
  2803. exports.BUTTON_CLASS_NAME = BUTTON_CLASS_NAME;
  2804. });
  2805. ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module){var Range = require("../range").Range;
  2806. var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
  2807. function getWordIndex(doc, pos) {
  2808. var textBefore = doc.getTextRange(Range.fromPoints({
  2809. row: 0,
  2810. column: 0
  2811. }, pos));
  2812. return textBefore.split(splitRegex).length - 1;
  2813. }
  2814. function wordDistance(doc, pos) {
  2815. var prefixPos = getWordIndex(doc, pos);
  2816. var words = doc.getValue().split(splitRegex);
  2817. var wordScores = Object.create(null);
  2818. var currentWord = words[prefixPos];
  2819. words.forEach(function (word, idx) {
  2820. if (!word || word === currentWord)
  2821. return;
  2822. var distance = Math.abs(prefixPos - idx);
  2823. var score = words.length - distance;
  2824. if (wordScores[word]) {
  2825. wordScores[word] = Math.max(score, wordScores[word]);
  2826. }
  2827. else {
  2828. wordScores[word] = score;
  2829. }
  2830. });
  2831. return wordScores;
  2832. }
  2833. exports.getCompletions = function (editor, session, pos, prefix, callback) {
  2834. var wordScore = wordDistance(session, pos);
  2835. var wordList = Object.keys(wordScore);
  2836. callback(null, wordList.map(function (word) {
  2837. return {
  2838. caption: word,
  2839. value: word,
  2840. score: wordScore[word],
  2841. meta: "local"
  2842. };
  2843. }));
  2844. };
  2845. });
  2846. ace.define("ace/ext/language_tools",["require","exports","module","ace/snippets","ace/autocomplete","ace/config","ace/lib/lang","ace/autocomplete/util","ace/autocomplete/text_completer","ace/editor","ace/config"], function(require, exports, module){"use strict";
  2847. var snippetManager = require("../snippets").snippetManager;
  2848. var Autocomplete = require("../autocomplete").Autocomplete;
  2849. var config = require("../config");
  2850. var lang = require("../lib/lang");
  2851. var util = require("../autocomplete/util");
  2852. var textCompleter = require("../autocomplete/text_completer");
  2853. var keyWordCompleter = {
  2854. getCompletions: function (editor, session, pos, prefix, callback) {
  2855. if (session.$mode.completer) {
  2856. return session.$mode.completer.getCompletions(editor, session, pos, prefix, callback);
  2857. }
  2858. var state = editor.session.getState(pos.row);
  2859. var completions = session.$mode.getCompletions(state, session, pos, prefix);
  2860. completions = completions.map(function (el) {
  2861. el.completerId = keyWordCompleter.id;
  2862. return el;
  2863. });
  2864. callback(null, completions);
  2865. },
  2866. id: "keywordCompleter"
  2867. };
  2868. var transformSnippetTooltip = function (str) {
  2869. var record = {};
  2870. return str.replace(/\${(\d+)(:(.*?))?}/g, function (_, p1, p2, p3) {
  2871. return (record[p1] = p3 || '');
  2872. }).replace(/\$(\d+?)/g, function (_, p1) {
  2873. return record[p1];
  2874. });
  2875. };
  2876. var snippetCompleter = {
  2877. getCompletions: function (editor, session, pos, prefix, callback) {
  2878. var scopes = [];
  2879. var token = session.getTokenAt(pos.row, pos.column);
  2880. if (token && token.type.match(/(tag-name|tag-open|tag-whitespace|attribute-name|attribute-value)\.xml$/))
  2881. scopes.push('html-tag');
  2882. else
  2883. scopes = snippetManager.getActiveScopes(editor);
  2884. var snippetMap = snippetManager.snippetMap;
  2885. var completions = [];
  2886. scopes.forEach(function (scope) {
  2887. var snippets = snippetMap[scope] || [];
  2888. for (var i = snippets.length; i--;) {
  2889. var s = snippets[i];
  2890. var caption = s.name || s.tabTrigger;
  2891. if (!caption)
  2892. continue;
  2893. completions.push({
  2894. caption: caption,
  2895. snippet: s.content,
  2896. meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet",
  2897. completerId: snippetCompleter.id
  2898. });
  2899. }
  2900. }, this);
  2901. callback(null, completions);
  2902. },
  2903. getDocTooltip: function (item) {
  2904. if (item.snippet && !item.docHTML) {
  2905. item.docHTML = [
  2906. "<b>", lang.escapeHTML(item.caption), "</b>", "<hr></hr>",
  2907. lang.escapeHTML(transformSnippetTooltip(item.snippet))
  2908. ].join("");
  2909. }
  2910. },
  2911. id: "snippetCompleter"
  2912. };
  2913. var completers = [snippetCompleter, textCompleter, keyWordCompleter];
  2914. exports.setCompleters = function (val) {
  2915. completers.length = 0;
  2916. if (val)
  2917. completers.push.apply(completers, val);
  2918. };
  2919. exports.addCompleter = function (completer) {
  2920. completers.push(completer);
  2921. };
  2922. exports.textCompleter = textCompleter;
  2923. exports.keyWordCompleter = keyWordCompleter;
  2924. exports.snippetCompleter = snippetCompleter;
  2925. var expandSnippet = {
  2926. name: "expandSnippet",
  2927. exec: function (editor) {
  2928. return snippetManager.expandWithTab(editor);
  2929. },
  2930. bindKey: "Tab"
  2931. };
  2932. var onChangeMode = function (e, editor) {
  2933. loadSnippetsForMode(editor.session.$mode);
  2934. };
  2935. var loadSnippetsForMode = function (mode) {
  2936. if (typeof mode == "string")
  2937. mode = config.$modes[mode];
  2938. if (!mode)
  2939. return;
  2940. if (!snippetManager.files)
  2941. snippetManager.files = {};
  2942. loadSnippetFile(mode.$id, mode.snippetFileId);
  2943. if (mode.modes)
  2944. mode.modes.forEach(loadSnippetsForMode);
  2945. };
  2946. var loadSnippetFile = function (id, snippetFilePath) {
  2947. if (!snippetFilePath || !id || snippetManager.files[id])
  2948. return;
  2949. snippetManager.files[id] = {};
  2950. config.loadModule(snippetFilePath, function (m) {
  2951. if (!m)
  2952. return;
  2953. snippetManager.files[id] = m;
  2954. if (!m.snippets && m.snippetText)
  2955. m.snippets = snippetManager.parseSnippetFile(m.snippetText);
  2956. snippetManager.register(m.snippets || [], m.scope);
  2957. if (m.includeScopes) {
  2958. snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
  2959. m.includeScopes.forEach(function (x) {
  2960. loadSnippetsForMode("ace/mode/" + x);
  2961. });
  2962. }
  2963. });
  2964. };
  2965. var doLiveAutocomplete = function (e) {
  2966. var editor = e.editor;
  2967. var hasCompleter = editor.completer && editor.completer.activated;
  2968. if (e.command.name === "backspace") {
  2969. if (hasCompleter && !util.getCompletionPrefix(editor))
  2970. editor.completer.detach();
  2971. }
  2972. else if (e.command.name === "insertstring" && !hasCompleter) {
  2973. lastExecEvent = e;
  2974. var delay = e.editor.$liveAutocompletionDelay;
  2975. if (delay) {
  2976. liveAutocompleteTimer.delay(delay);
  2977. }
  2978. else {
  2979. showLiveAutocomplete(e);
  2980. }
  2981. }
  2982. };
  2983. var lastExecEvent;
  2984. var liveAutocompleteTimer = lang.delayedCall(function () {
  2985. showLiveAutocomplete(lastExecEvent);
  2986. }, 0);
  2987. var showLiveAutocomplete = function (e) {
  2988. var editor = e.editor;
  2989. var prefix = util.getCompletionPrefix(editor);
  2990. var previousChar = e.args;
  2991. var triggerAutocomplete = util.triggerAutocomplete(editor, previousChar);
  2992. if (prefix && prefix.length >= editor.$liveAutocompletionThreshold || triggerAutocomplete) {
  2993. var completer = Autocomplete.for(editor);
  2994. completer.autoShown = true;
  2995. completer.showPopup(editor);
  2996. }
  2997. };
  2998. var Editor = require("../editor").Editor;
  2999. require("../config").defineOptions(Editor.prototype, "editor", {
  3000. enableBasicAutocompletion: {
  3001. set: function (val) {
  3002. if (val) {
  3003. if (!this.completers)
  3004. this.completers = Array.isArray(val) ? val : completers;
  3005. this.commands.addCommand(Autocomplete.startCommand);
  3006. }
  3007. else {
  3008. this.commands.removeCommand(Autocomplete.startCommand);
  3009. }
  3010. },
  3011. value: false
  3012. },
  3013. enableLiveAutocompletion: {
  3014. set: function (val) {
  3015. if (val) {
  3016. if (!this.completers)
  3017. this.completers = Array.isArray(val) ? val : completers;
  3018. this.commands.on('afterExec', doLiveAutocomplete);
  3019. }
  3020. else {
  3021. this.commands.off('afterExec', doLiveAutocomplete);
  3022. }
  3023. },
  3024. value: false
  3025. },
  3026. liveAutocompletionDelay: {
  3027. initialValue: 0
  3028. },
  3029. liveAutocompletionThreshold: {
  3030. initialValue: 0
  3031. },
  3032. enableSnippets: {
  3033. set: function (val) {
  3034. if (val) {
  3035. this.commands.addCommand(expandSnippet);
  3036. this.on("changeMode", onChangeMode);
  3037. onChangeMode(null, this);
  3038. }
  3039. else {
  3040. this.commands.removeCommand(expandSnippet);
  3041. this.off("changeMode", onChangeMode);
  3042. }
  3043. },
  3044. value: false
  3045. }
  3046. });
  3047. });
  3048. ace.define("ace/ext/inline_autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/inline","ace/autocomplete","ace/autocomplete","ace/editor","ace/autocomplete/util","ace/lib/dom","ace/lib/lang","ace/ext/command_bar","ace/ext/command_bar","ace/ext/language_tools","ace/ext/language_tools","ace/ext/language_tools","ace/config"], function(require, exports, module){"use strict";
  3049. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  3050. var AceInline = require("../autocomplete/inline").AceInline;
  3051. var FilteredList = require("../autocomplete").FilteredList;
  3052. var CompletionProvider = require("../autocomplete").CompletionProvider;
  3053. var Editor = require("../editor").Editor;
  3054. var util = require("../autocomplete/util");
  3055. var dom = require("../lib/dom");
  3056. var lang = require("../lib/lang");
  3057. var CommandBarTooltip = require("./command_bar").CommandBarTooltip;
  3058. var BUTTON_CLASS_NAME = require("./command_bar").BUTTON_CLASS_NAME;
  3059. var snippetCompleter = require("./language_tools").snippetCompleter;
  3060. var textCompleter = require("./language_tools").textCompleter;
  3061. var keyWordCompleter = require("./language_tools").keyWordCompleter;
  3062. var destroyCompleter = function (e, editor) {
  3063. editor.completer && editor.completer.destroy();
  3064. };
  3065. var InlineAutocomplete = /** @class */ (function () {
  3066. function InlineAutocomplete(editor) {
  3067. this.editor = editor;
  3068. this.keyboardHandler = new HashHandler(this.commands);
  3069. this.$index = -1;
  3070. this.blurListener = this.blurListener.bind(this);
  3071. this.changeListener = this.changeListener.bind(this);
  3072. this.changeTimer = lang.delayedCall(function () {
  3073. this.updateCompletions();
  3074. }.bind(this));
  3075. }
  3076. InlineAutocomplete.prototype.getInlineRenderer = function () {
  3077. if (!this.inlineRenderer)
  3078. this.inlineRenderer = new AceInline();
  3079. return this.inlineRenderer;
  3080. };
  3081. InlineAutocomplete.prototype.getInlineTooltip = function () {
  3082. if (!this.inlineTooltip) {
  3083. this.inlineTooltip = InlineAutocomplete.createInlineTooltip(document.body || document.documentElement);
  3084. }
  3085. return this.inlineTooltip;
  3086. };
  3087. InlineAutocomplete.prototype.show = function (options) {
  3088. this.activated = true;
  3089. if (this.editor.completer !== this) {
  3090. if (this.editor.completer)
  3091. this.editor.completer.detach();
  3092. this.editor.completer = this;
  3093. }
  3094. this.editor.on("changeSelection", this.changeListener);
  3095. this.editor.on("blur", this.blurListener);
  3096. this.updateCompletions(options);
  3097. };
  3098. InlineAutocomplete.prototype.$open = function () {
  3099. if (this.editor.textInput.setAriaOptions) {
  3100. this.editor.textInput.setAriaOptions({});
  3101. }
  3102. this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
  3103. this.getInlineTooltip().attach(this.editor);
  3104. if (this.$index === -1) {
  3105. this.setIndex(0);
  3106. }
  3107. else {
  3108. this.$showCompletion();
  3109. }
  3110. this.changeTimer.cancel();
  3111. };
  3112. InlineAutocomplete.prototype.insertMatch = function () {
  3113. var result = this.getCompletionProvider().insertByIndex(this.editor, this.$index);
  3114. this.detach();
  3115. return result;
  3116. };
  3117. InlineAutocomplete.prototype.changeListener = function (e) {
  3118. var cursor = this.editor.selection.lead;
  3119. if (cursor.row != this.base.row || cursor.column < this.base.column) {
  3120. this.detach();
  3121. }
  3122. if (this.activated)
  3123. this.changeTimer.schedule();
  3124. else
  3125. this.detach();
  3126. };
  3127. InlineAutocomplete.prototype.blurListener = function (e) {
  3128. this.detach();
  3129. };
  3130. InlineAutocomplete.prototype.goTo = function (where) {
  3131. if (!this.completions || !this.completions.filtered) {
  3132. return;
  3133. }
  3134. var completionLength = this.completions.filtered.length;
  3135. switch (where.toLowerCase()) {
  3136. case "prev":
  3137. this.setIndex((this.$index - 1 + completionLength) % completionLength);
  3138. break;
  3139. case "next":
  3140. this.setIndex((this.$index + 1 + completionLength) % completionLength);
  3141. break;
  3142. case "first":
  3143. this.setIndex(0);
  3144. break;
  3145. case "last":
  3146. this.setIndex(this.completions.filtered.length - 1);
  3147. break;
  3148. }
  3149. };
  3150. InlineAutocomplete.prototype.getLength = function () {
  3151. if (!this.completions || !this.completions.filtered) {
  3152. return 0;
  3153. }
  3154. return this.completions.filtered.length;
  3155. };
  3156. InlineAutocomplete.prototype.getData = function (index) {
  3157. if (index == undefined || index === null) {
  3158. return this.completions.filtered[this.$index];
  3159. }
  3160. else {
  3161. return this.completions.filtered[index];
  3162. }
  3163. };
  3164. InlineAutocomplete.prototype.getIndex = function () {
  3165. return this.$index;
  3166. };
  3167. InlineAutocomplete.prototype.isOpen = function () {
  3168. return this.$index >= 0;
  3169. };
  3170. InlineAutocomplete.prototype.setIndex = function (value) {
  3171. if (!this.completions || !this.completions.filtered) {
  3172. return;
  3173. }
  3174. var newIndex = Math.max(-1, Math.min(this.completions.filtered.length - 1, value));
  3175. if (newIndex !== this.$index) {
  3176. this.$index = newIndex;
  3177. this.$showCompletion();
  3178. }
  3179. };
  3180. InlineAutocomplete.prototype.getCompletionProvider = function (initialPosition) {
  3181. if (!this.completionProvider)
  3182. this.completionProvider = new CompletionProvider(initialPosition);
  3183. return this.completionProvider;
  3184. };
  3185. InlineAutocomplete.prototype.$showCompletion = function () {
  3186. if (!this.getInlineRenderer().show(this.editor, this.completions.filtered[this.$index], this.completions.filterText)) {
  3187. this.getInlineRenderer().hide();
  3188. }
  3189. if (this.inlineTooltip && this.inlineTooltip.isShown()) {
  3190. this.inlineTooltip.update();
  3191. }
  3192. };
  3193. InlineAutocomplete.prototype.$updatePrefix = function () {
  3194. var pos = this.editor.getCursorPosition();
  3195. var prefix = this.editor.session.getTextRange({ start: this.base, end: pos });
  3196. this.completions.setFilter(prefix);
  3197. if (!this.completions.filtered.length)
  3198. return this.detach();
  3199. if (this.completions.filtered.length == 1
  3200. && this.completions.filtered[0].value == prefix
  3201. && !this.completions.filtered[0].snippet)
  3202. return this.detach();
  3203. this.$open(this.editor, prefix);
  3204. return prefix;
  3205. };
  3206. InlineAutocomplete.prototype.updateCompletions = function (options) {
  3207. var prefix = "";
  3208. if (options && options.matches) {
  3209. var pos = this.editor.getSelectionRange().start;
  3210. this.base = this.editor.session.doc.createAnchor(pos.row, pos.column);
  3211. this.base.$insertRight = true;
  3212. this.completions = new FilteredList(options.matches);
  3213. return this.$open(this.editor, "");
  3214. }
  3215. if (this.base && this.completions) {
  3216. prefix = this.$updatePrefix();
  3217. }
  3218. var session = this.editor.getSession();
  3219. var pos = this.editor.getCursorPosition();
  3220. var prefix = util.getCompletionPrefix(this.editor);
  3221. this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
  3222. this.base.$insertRight = true;
  3223. var options = {
  3224. exactMatch: true,
  3225. ignoreCaption: true
  3226. };
  3227. this.getCompletionProvider({
  3228. prefix: prefix,
  3229. base: this.base,
  3230. pos: pos
  3231. }).provideCompletions(this.editor, options,
  3232. function (err, completions, finished) {
  3233. var filtered = completions.filtered;
  3234. var prefix = util.getCompletionPrefix(this.editor);
  3235. if (finished) {
  3236. if (!filtered.length)
  3237. return this.detach();
  3238. if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
  3239. return this.detach();
  3240. }
  3241. this.completions = completions;
  3242. this.$open(this.editor, prefix);
  3243. }.bind(this));
  3244. };
  3245. InlineAutocomplete.prototype.detach = function () {
  3246. if (this.editor) {
  3247. this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
  3248. this.editor.off("changeSelection", this.changeListener);
  3249. this.editor.off("blur", this.blurListener);
  3250. }
  3251. this.changeTimer.cancel();
  3252. if (this.inlineTooltip) {
  3253. this.inlineTooltip.detach();
  3254. }
  3255. this.setIndex(-1);
  3256. if (this.completionProvider) {
  3257. this.completionProvider.detach();
  3258. }
  3259. if (this.inlineRenderer && this.inlineRenderer.isOpen()) {
  3260. this.inlineRenderer.hide();
  3261. }
  3262. if (this.base)
  3263. this.base.detach();
  3264. this.activated = false;
  3265. this.completionProvider = this.completions = this.base = null;
  3266. };
  3267. InlineAutocomplete.prototype.destroy = function () {
  3268. this.detach();
  3269. if (this.inlineRenderer)
  3270. this.inlineRenderer.destroy();
  3271. if (this.inlineTooltip)
  3272. this.inlineTooltip.destroy();
  3273. if (this.editor && this.editor.completer == this) {
  3274. this.editor.off("destroy", destroyCompleter);
  3275. this.editor.completer = null;
  3276. }
  3277. this.inlineTooltip = this.editor = this.inlineRenderer = null;
  3278. };
  3279. InlineAutocomplete.prototype.updateDocTooltip = function () {
  3280. };
  3281. return InlineAutocomplete;
  3282. }());
  3283. InlineAutocomplete.prototype.commands = {
  3284. "Previous": {
  3285. bindKey: "Alt-[",
  3286. name: "Previous",
  3287. exec: function (editor) {
  3288. editor.completer.goTo("prev");
  3289. }
  3290. },
  3291. "Next": {
  3292. bindKey: "Alt-]",
  3293. name: "Next",
  3294. exec: function (editor) {
  3295. editor.completer.goTo("next");
  3296. }
  3297. },
  3298. "Accept": {
  3299. bindKey: { win: "Tab|Ctrl-Right", mac: "Tab|Cmd-Right" },
  3300. name: "Accept",
  3301. exec: function (editor) {
  3302. return /**@type{InlineAutocomplete}*/ (editor.completer).insertMatch();
  3303. }
  3304. },
  3305. "Close": {
  3306. bindKey: "Esc",
  3307. name: "Close",
  3308. exec: function (editor) {
  3309. editor.completer.detach();
  3310. }
  3311. }
  3312. };
  3313. InlineAutocomplete.for = function (editor) {
  3314. if (editor.completer instanceof InlineAutocomplete) {
  3315. return editor.completer;
  3316. }
  3317. if (editor.completer) {
  3318. editor.completer.destroy();
  3319. editor.completer = null;
  3320. }
  3321. editor.completer = new InlineAutocomplete(editor);
  3322. editor.once("destroy", destroyCompleter);
  3323. return editor.completer;
  3324. };
  3325. InlineAutocomplete.startCommand = {
  3326. name: "startInlineAutocomplete",
  3327. exec: function (editor, options) {
  3328. var completer = InlineAutocomplete.for(editor);
  3329. completer.show(options);
  3330. },
  3331. bindKey: { win: "Alt-C", mac: "Option-C" }
  3332. };
  3333. var completers = [snippetCompleter, textCompleter, keyWordCompleter];
  3334. require("../config").defineOptions(Editor.prototype, "editor", {
  3335. enableInlineAutocompletion: {
  3336. set: function (val) {
  3337. if (val) {
  3338. if (!this.completers)
  3339. this.completers = Array.isArray(val) ? val : completers;
  3340. this.commands.addCommand(InlineAutocomplete.startCommand);
  3341. }
  3342. else {
  3343. this.commands.removeCommand(InlineAutocomplete.startCommand);
  3344. }
  3345. },
  3346. value: false
  3347. }
  3348. });
  3349. InlineAutocomplete.createInlineTooltip = function (parentEl) {
  3350. var inlineTooltip = new CommandBarTooltip(parentEl);
  3351. inlineTooltip.registerCommand("Previous",
  3352. Object.assign({}, InlineAutocomplete.prototype.commands["Previous"], {
  3353. enabled: true,
  3354. type: "button",
  3355. iconCssClass: "ace_arrow_rotated"
  3356. }));
  3357. inlineTooltip.registerCommand("Position", {
  3358. enabled: false,
  3359. getValue: function (editor) {
  3360. return editor ? [
  3361. (editor.completer).getIndex() + 1, /**@type{InlineAutocomplete}*/ (editor.completer).getLength()
  3362. ].join("/") : "";
  3363. },
  3364. type: "text",
  3365. cssClass: "completion_position"
  3366. });
  3367. inlineTooltip.registerCommand("Next",
  3368. Object.assign({}, InlineAutocomplete.prototype.commands["Next"], {
  3369. enabled: true,
  3370. type: "button",
  3371. iconCssClass: "ace_arrow"
  3372. }));
  3373. inlineTooltip.registerCommand("Accept",
  3374. Object.assign({}, InlineAutocomplete.prototype.commands["Accept"], {
  3375. enabled: function (editor) {
  3376. return !!editor && editor.completer.getIndex() >= 0;
  3377. },
  3378. type: "button"
  3379. }));
  3380. inlineTooltip.registerCommand("ShowTooltip", {
  3381. name: "Always Show Tooltip",
  3382. exec: function () {
  3383. inlineTooltip.setAlwaysShow(!inlineTooltip.getAlwaysShow());
  3384. },
  3385. enabled: true,
  3386. getValue: function () {
  3387. return inlineTooltip.getAlwaysShow();
  3388. },
  3389. type: "checkbox"
  3390. });
  3391. return inlineTooltip;
  3392. };
  3393. dom.importCssString("\n\n.ace_icon_svg.ace_arrow,\n.ace_icon_svg.ace_arrow_rotated {\n -webkit-mask-image: url(\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTUuODM3MDEgMTVMNC41ODc1MSAxMy43MTU1TDEwLjE0NjggOEw0LjU4NzUxIDIuMjg0NDZMNS44MzcwMSAxTDEyLjY0NjUgOEw1LjgzNzAxIDE1WiIgZmlsbD0iYmxhY2siLz48L3N2Zz4=\");\n}\n\n.ace_icon_svg.ace_arrow_rotated {\n transform: rotate(180deg);\n}\n\ndiv.".concat(BUTTON_CLASS_NAME, ".completion_position {\n padding: 0;\n}\n"), "inlineautocomplete.css", false);
  3394. exports.InlineAutocomplete = InlineAutocomplete;
  3395. }); (function() {
  3396. ace.require(["ace/ext/inline_autocomplete"], function(m) {
  3397. if (typeof module == "object" && typeof exports == "object" && module) {
  3398. module.exports = m;
  3399. }
  3400. });
  3401. })();