PageRenderTime 148ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 2ms

/libs/ace.js

https://github.com/creesch/reddit-moderator-toolbox
JavaScript | 14302 lines | 13731 code | 539 blank | 32 comment | 885 complexity | 5358d8a162b6b7345464f1b1414f3364 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. (function() {
  31. var ACE_NAMESPACE = "ace";
  32. var global = (function() {
  33. return this;
  34. })();
  35. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  36. return;
  37. var _define = function(module, deps, payload) {
  38. if (typeof module !== 'string') {
  39. if (_define.original)
  40. _define.original.apply(window, arguments);
  41. else {
  42. console.error('dropping module because define wasn\'t a string.');
  43. console.trace();
  44. }
  45. return;
  46. }
  47. if (arguments.length == 2)
  48. payload = deps;
  49. if (!_define.modules) {
  50. _define.modules = {};
  51. _define.payloads = {};
  52. }
  53. _define.payloads[module] = payload;
  54. _define.modules[module] = null;
  55. };
  56. var _require = function(parentId, module, callback) {
  57. if (Object.prototype.toString.call(module) === "[object Array]") {
  58. var params = [];
  59. for (var i = 0, l = module.length; i < l; ++i) {
  60. var dep = lookup(parentId, module[i]);
  61. if (!dep && _require.original)
  62. return _require.original.apply(window, arguments);
  63. params.push(dep);
  64. }
  65. if (callback) {
  66. callback.apply(null, params);
  67. }
  68. }
  69. else if (typeof module === 'string') {
  70. var payload = lookup(parentId, module);
  71. if (!payload && _require.original)
  72. return _require.original.apply(window, arguments);
  73. if (callback) {
  74. callback();
  75. }
  76. return payload;
  77. }
  78. else {
  79. if (_require.original)
  80. return _require.original.apply(window, arguments);
  81. }
  82. };
  83. var normalizeModule = function(parentId, moduleName) {
  84. if (moduleName.indexOf("!") !== -1) {
  85. var chunks = moduleName.split("!");
  86. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  87. }
  88. if (moduleName.charAt(0) == ".") {
  89. var base = parentId.split("/").slice(0, -1).join("/");
  90. moduleName = base + "/" + moduleName;
  91. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  92. var previous = moduleName;
  93. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  94. }
  95. }
  96. return moduleName;
  97. };
  98. var lookup = function(parentId, moduleName) {
  99. moduleName = normalizeModule(parentId, moduleName);
  100. var module = _define.modules[moduleName];
  101. if (!module) {
  102. module = _define.payloads[moduleName];
  103. if (typeof module === 'function') {
  104. var exports = {};
  105. var mod = {
  106. id: moduleName,
  107. uri: '',
  108. exports: exports,
  109. packaged: true
  110. };
  111. var req = function(module, callback) {
  112. return _require(moduleName, module, callback);
  113. };
  114. var returnValue = module(req, exports, mod);
  115. exports = returnValue || mod.exports;
  116. _define.modules[moduleName] = exports;
  117. delete _define.payloads[moduleName];
  118. }
  119. module = _define.modules[moduleName] = exports || module;
  120. }
  121. return module;
  122. };
  123. function exportAce(ns) {
  124. var require = function(module, callback) {
  125. return _require("", module, callback);
  126. };
  127. var root = global;
  128. if (ns) {
  129. if (!global[ns])
  130. global[ns] = {};
  131. root = global[ns];
  132. }
  133. if (!root.define || !root.define.packaged) {
  134. _define.original = root.define;
  135. root.define = _define;
  136. root.define.packaged = true;
  137. }
  138. if (!root.require || !root.require.packaged) {
  139. _require.original = root.require;
  140. root.require = require;
  141. root.require.packaged = true;
  142. }
  143. }
  144. exportAce(ACE_NAMESPACE);
  145. })();
  146. ace.define('ace/ace', ['require', 'exports', 'module' , 'ace/lib/fixoldbrowsers', 'ace/lib/dom', 'ace/lib/event', 'ace/editor', 'ace/edit_session', 'ace/undomanager', 'ace/virtual_renderer', 'ace/worker/worker_client', 'ace/keyboard/hash_handler', 'ace/placeholder', 'ace/multi_select', 'ace/mode/folding/fold_mode', 'ace/theme/textmate', 'ace/ext/error_marker', 'ace/config'], function(require, exports, module) {
  147. require("./lib/fixoldbrowsers");
  148. var dom = require("./lib/dom");
  149. var event = require("./lib/event");
  150. var Editor = require("./editor").Editor;
  151. var EditSession = require("./edit_session").EditSession;
  152. var UndoManager = require("./undomanager").UndoManager;
  153. var Renderer = require("./virtual_renderer").VirtualRenderer;
  154. require("./worker/worker_client");
  155. require("./keyboard/hash_handler");
  156. require("./placeholder");
  157. require("./multi_select");
  158. require("./mode/folding/fold_mode");
  159. require("./theme/textmate");
  160. require("./ext/error_marker");
  161. exports.config = require("./config");
  162. exports.require = require;
  163. exports.edit = function(el) {
  164. if (typeof(el) == "string") {
  165. var _id = el;
  166. el = document.getElementById(_id);
  167. if (!el)
  168. throw new Error("ace.edit can't find div #" + _id);
  169. }
  170. if (el.env && el.env.editor instanceof Editor)
  171. return el.env.editor;
  172. var doc = exports.createEditSession(dom.getInnerText(el));
  173. el.innerHTML = '';
  174. var editor = new Editor(new Renderer(el));
  175. editor.setSession(doc);
  176. var env = {
  177. document: doc,
  178. editor: editor,
  179. onResize: editor.resize.bind(editor, null)
  180. };
  181. event.addListener(window, "resize", env.onResize);
  182. editor.on("destroy", function() {
  183. event.removeListener(window, "resize", env.onResize);
  184. });
  185. el.env = editor.env = env;
  186. return editor;
  187. };
  188. exports.createEditSession = function(text, mode) {
  189. var doc = new EditSession(text, mode);
  190. doc.setUndoManager(new UndoManager());
  191. return doc;
  192. }
  193. exports.EditSession = EditSession;
  194. exports.UndoManager = UndoManager;
  195. });
  196. ace.define('ace/mode/behaviour', ['require', 'exports', 'module' ], function(require, exports, module) {
  197. var Behaviour = function() {
  198. this.$behaviours = {};
  199. };
  200. (function () {
  201. this.add = function (name, action, callback) {
  202. switch (undefined) {
  203. case this.$behaviours:
  204. this.$behaviours = {};
  205. case this.$behaviours[name]:
  206. this.$behaviours[name] = {};
  207. }
  208. this.$behaviours[name][action] = callback;
  209. }
  210. this.addBehaviours = function (behaviours) {
  211. for (var key in behaviours) {
  212. for (var action in behaviours[key]) {
  213. this.add(key, action, behaviours[key][action]);
  214. }
  215. }
  216. }
  217. this.remove = function (name) {
  218. if (this.$behaviours && this.$behaviours[name]) {
  219. delete this.$behaviours[name];
  220. }
  221. }
  222. this.inherit = function (mode, filter) {
  223. if (typeof mode === "function") {
  224. var behaviours = new mode().getBehaviours(filter);
  225. } else {
  226. var behaviours = mode.getBehaviours(filter);
  227. }
  228. this.addBehaviours(behaviours);
  229. }
  230. this.getBehaviours = function (filter) {
  231. if (!filter) {
  232. return this.$behaviours;
  233. } else {
  234. var ret = {}
  235. for (var i = 0; i < filter.length; i++) {
  236. if (this.$behaviours[filter[i]]) {
  237. ret[filter[i]] = this.$behaviours[filter[i]];
  238. }
  239. }
  240. return ret;
  241. }
  242. }
  243. }).call(Behaviour.prototype);
  244. exports.Behaviour = Behaviour;
  245. });
  246. ace.define('ace/unicode', ['require', 'exports', 'module' ], function(require, exports, module) {
  247. exports.packages = {};
  248. addUnicodePackage({
  249. L: "0041-005A0061-007A00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D03860388-038A038C038E-03A103A3-03F503F7-0481048A-05250531-055605590561-058705D0-05EA05F0-05F20621-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280904-0939093D09500958-0961097109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510D0-10FA10FC1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209421022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2D00-2D252D30-2D652D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A65FA662-A66EA67F-A697A6A0-A6E5A717-A71FA722-A788A78BA78CA7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  250. Ll: "0061-007A00AA00B500BA00DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F0521052305250561-05871D00-1D2B1D62-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7C2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2D00-2D25A641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CFB00-FB06FB13-FB17FF41-FF5A",
  251. Lu: "0041-005A00C0-00D600D8-00DE01000102010401060108010A010C010E01100112011401160118011A011C011E01200122012401260128012A012C012E01300132013401360139013B013D013F0141014301450147014A014C014E01500152015401560158015A015C015E01600162016401660168016A016C016E017001720174017601780179017B017D018101820184018601870189-018B018E-0191019301940196-0198019C019D019F01A001A201A401A601A701A901AC01AE01AF01B1-01B301B501B701B801BC01C401C701CA01CD01CF01D101D301D501D701D901DB01DE01E001E201E401E601E801EA01EC01EE01F101F401F6-01F801FA01FC01FE02000202020402060208020A020C020E02100212021402160218021A021C021E02200222022402260228022A022C022E02300232023A023B023D023E02410243-02460248024A024C024E03700372037603860388-038A038C038E038F0391-03A103A3-03AB03CF03D2-03D403D803DA03DC03DE03E003E203E403E603E803EA03EC03EE03F403F703F903FA03FD-042F04600462046404660468046A046C046E04700472047404760478047A047C047E0480048A048C048E04900492049404960498049A049C049E04A004A204A404A604A804AA04AC04AE04B004B204B404B604B804BA04BC04BE04C004C104C304C504C704C904CB04CD04D004D204D404D604D804DA04DC04DE04E004E204E404E604E804EA04EC04EE04F004F204F404F604F804FA04FC04FE05000502050405060508050A050C050E05100512051405160518051A051C051E0520052205240531-055610A0-10C51E001E021E041E061E081E0A1E0C1E0E1E101E121E141E161E181E1A1E1C1E1E1E201E221E241E261E281E2A1E2C1E2E1E301E321E341E361E381E3A1E3C1E3E1E401E421E441E461E481E4A1E4C1E4E1E501E521E541E561E581E5A1E5C1E5E1E601E621E641E661E681E6A1E6C1E6E1E701E721E741E761E781E7A1E7C1E7E1E801E821E841E861E881E8A1E8C1E8E1E901E921E941E9E1EA01EA21EA41EA61EA81EAA1EAC1EAE1EB01EB21EB41EB61EB81EBA1EBC1EBE1EC01EC21EC41EC61EC81ECA1ECC1ECE1ED01ED21ED41ED61ED81EDA1EDC1EDE1EE01EE21EE41EE61EE81EEA1EEC1EEE1EF01EF21EF41EF61EF81EFA1EFC1EFE1F08-1F0F1F18-1F1D1F28-1F2F1F38-1F3F1F48-1F4D1F591F5B1F5D1F5F1F68-1F6F1FB8-1FBB1FC8-1FCB1FD8-1FDB1FE8-1FEC1FF8-1FFB21022107210B-210D2110-211221152119-211D212421262128212A-212D2130-2133213E213F214521832C00-2C2E2C602C62-2C642C672C692C6B2C6D-2C702C722C752C7E-2C802C822C842C862C882C8A2C8C2C8E2C902C922C942C962C982C9A2C9C2C9E2CA02CA22CA42CA62CA82CAA2CAC2CAE2CB02CB22CB42CB62CB82CBA2CBC2CBE2CC02CC22CC42CC62CC82CCA2CCC2CCE2CD02CD22CD42CD62CD82CDA2CDC2CDE2CE02CE22CEB2CEDA640A642A644A646A648A64AA64CA64EA650A652A654A656A658A65AA65CA65EA662A664A666A668A66AA66CA680A682A684A686A688A68AA68CA68EA690A692A694A696A722A724A726A728A72AA72CA72EA732A734A736A738A73AA73CA73EA740A742A744A746A748A74AA74CA74EA750A752A754A756A758A75AA75CA75EA760A762A764A766A768A76AA76CA76EA779A77BA77DA77EA780A782A784A786A78BFF21-FF3A",
  252. Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
  253. Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
  254. Lo: "01BB01C0-01C3029405D0-05EA05F0-05F20621-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150904-0939093D09500958-096109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF12135-21382D30-2D652D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  255. M: "0300-036F0483-04890591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DE-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0903093C093E-094E0951-0955096209630981-098309BC09BE-09C409C709C809CB-09CD09D709E209E30A01-0A030A3C0A3E-0A420A470A480A4B-0A4D0A510A700A710A750A81-0A830ABC0ABE-0AC50AC7-0AC90ACB-0ACD0AE20AE30B01-0B030B3C0B3E-0B440B470B480B4B-0B4D0B560B570B620B630B820BBE-0BC20BC6-0BC80BCA-0BCD0BD70C01-0C030C3E-0C440C46-0C480C4A-0C4D0C550C560C620C630C820C830CBC0CBE-0CC40CC6-0CC80CCA-0CCD0CD50CD60CE20CE30D020D030D3E-0D440D46-0D480D4A-0D4D0D570D620D630D820D830DCA0DCF-0DD40DD60DD8-0DDF0DF20DF30E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F3E0F3F0F71-0F840F860F870F90-0F970F99-0FBC0FC6102B-103E1056-1059105E-10601062-10641067-106D1071-10741082-108D108F109A-109D135F1712-17141732-1734175217531772177317B6-17D317DD180B-180D18A91920-192B1930-193B19B0-19C019C819C91A17-1A1B1A55-1A5E1A60-1A7C1A7F1B00-1B041B34-1B441B6B-1B731B80-1B821BA1-1BAA1C24-1C371CD0-1CD21CD4-1CE81CED1CF21DC0-1DE61DFD-1DFF20D0-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66F-A672A67CA67DA6F0A6F1A802A806A80BA823-A827A880A881A8B4-A8C4A8E0-A8F1A926-A92DA947-A953A980-A983A9B3-A9C0AA29-AA36AA43AA4CAA4DAA7BAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE3-ABEAABECABEDFB1EFE00-FE0FFE20-FE26",
  256. Mn: "0300-036F0483-04870591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DF-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0902093C0941-0948094D0951-095509620963098109BC09C1-09C409CD09E209E30A010A020A3C0A410A420A470A480A4B-0A4D0A510A700A710A750A810A820ABC0AC1-0AC50AC70AC80ACD0AE20AE30B010B3C0B3F0B41-0B440B4D0B560B620B630B820BC00BCD0C3E-0C400C46-0C480C4A-0C4D0C550C560C620C630CBC0CBF0CC60CCC0CCD0CE20CE30D41-0D440D4D0D620D630DCA0DD2-0DD40DD60E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F71-0F7E0F80-0F840F860F870F90-0F970F99-0FBC0FC6102D-10301032-10371039103A103D103E10581059105E-10601071-1074108210851086108D109D135F1712-17141732-1734175217531772177317B7-17BD17C617C9-17D317DD180B-180D18A91920-19221927192819321939-193B1A171A181A561A58-1A5E1A601A621A65-1A6C1A73-1A7C1A7F1B00-1B031B341B36-1B3A1B3C1B421B6B-1B731B801B811BA2-1BA51BA81BA91C2C-1C331C361C371CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF20D0-20DC20E120E5-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66FA67CA67DA6F0A6F1A802A806A80BA825A826A8C4A8E0-A8F1A926-A92DA947-A951A980-A982A9B3A9B6-A9B9A9BCAA29-AA2EAA31AA32AA35AA36AA43AA4CAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE5ABE8ABEDFB1EFE00-FE0FFE20-FE26",
  257. Mc: "0903093E-09400949-094C094E0982098309BE-09C009C709C809CB09CC09D70A030A3E-0A400A830ABE-0AC00AC90ACB0ACC0B020B030B3E0B400B470B480B4B0B4C0B570BBE0BBF0BC10BC20BC6-0BC80BCA-0BCC0BD70C01-0C030C41-0C440C820C830CBE0CC0-0CC40CC70CC80CCA0CCB0CD50CD60D020D030D3E-0D400D46-0D480D4A-0D4C0D570D820D830DCF-0DD10DD8-0DDF0DF20DF30F3E0F3F0F7F102B102C10311038103B103C105610571062-10641067-106D108310841087-108C108F109A-109C17B617BE-17C517C717C81923-19261929-192B193019311933-193819B0-19C019C819C91A19-1A1B1A551A571A611A631A641A6D-1A721B041B351B3B1B3D-1B411B431B441B821BA11BA61BA71BAA1C24-1C2B1C341C351CE11CF2A823A824A827A880A881A8B4-A8C3A952A953A983A9B4A9B5A9BAA9BBA9BD-A9C0AA2FAA30AA33AA34AA4DAA7BABE3ABE4ABE6ABE7ABE9ABEAABEC",
  258. Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
  259. N: "0030-003900B200B300B900BC-00BE0660-066906F0-06F907C0-07C90966-096F09E6-09EF09F4-09F90A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BF20C66-0C6F0C78-0C7E0CE6-0CEF0D66-0D750E50-0E590ED0-0ED90F20-0F331040-10491090-10991369-137C16EE-16F017E0-17E917F0-17F91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C5920702074-20792080-20892150-21822185-21892460-249B24EA-24FF2776-27932CFD30073021-30293038-303A3192-31953220-32293251-325F3280-328932B1-32BFA620-A629A6E6-A6EFA830-A835A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  260. Nd: "0030-00390660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  261. Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
  262. No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
  263. P: "0021-00230025-002A002C-002F003A003B003F0040005B-005D005F007B007D00A100AB00B700BB00BF037E0387055A-055F0589058A05BE05C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F3A-0F3D0F850FD0-0FD4104A-104F10FB1361-13681400166D166E169B169C16EB-16ED1735173617D4-17D617D8-17DA1800-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD32010-20272030-20432045-20512053-205E207D207E208D208E2329232A2768-277527C527C627E6-27EF2983-299829D8-29DB29FC29FD2CF9-2CFC2CFE2CFF2E00-2E2E2E302E313001-30033008-30113014-301F3030303D30A030FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFD3EFD3FFE10-FE19FE30-FE52FE54-FE61FE63FE68FE6AFE6BFF01-FF03FF05-FF0AFF0C-FF0FFF1AFF1BFF1FFF20FF3B-FF3DFF3FFF5BFF5DFF5F-FF65",
  264. Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
  265. Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
  266. Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
  267. Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
  268. Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
  269. Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
  270. Po: "0021-00230025-0027002A002C002E002F003A003B003F0040005C00A100B700BF037E0387055A-055F058905C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F850FD0-0FD4104A-104F10FB1361-1368166D166E16EB-16ED1735173617D4-17D617D8-17DA1800-18051807-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD3201620172020-20272030-2038203B-203E2041-20432047-205120532055-205E2CF9-2CFC2CFE2CFF2E002E012E06-2E082E0B2E0E-2E162E182E192E1B2E1E2E1F2E2A-2E2E2E302E313001-3003303D30FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFE10-FE16FE19FE30FE45FE46FE49-FE4CFE50-FE52FE54-FE57FE5F-FE61FE68FE6AFE6BFF01-FF03FF05-FF07FF0AFF0CFF0EFF0FFF1AFF1BFF1FFF20FF3CFF61FF64FF65",
  271. S: "0024002B003C-003E005E0060007C007E00A2-00A900AC00AE-00B100B400B600B800D700F702C2-02C502D2-02DF02E5-02EB02ED02EF-02FF03750384038503F604820606-0608060B060E060F06E906FD06FE07F609F209F309FA09FB0AF10B700BF3-0BFA0C7F0CF10CF20D790E3F0F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-139917DB194019E0-19FF1B61-1B6A1B74-1B7C1FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE20442052207A-207C208A-208C20A0-20B8210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B2140-2144214A-214D214F2190-2328232B-23E82400-24262440-244A249C-24E92500-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE27C0-27C427C7-27CA27CC27D0-27E527F0-29822999-29D729DC-29FB29FE-2B4C2B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F309B309C319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A700-A716A720A721A789A78AA828-A82BA836-A839AA77-AA79FB29FDFCFDFDFE62FE64-FE66FE69FF04FF0BFF1C-FF1EFF3EFF40FF5CFF5EFFE0-FFE6FFE8-FFEEFFFCFFFD",
  272. Sm: "002B003C-003E007C007E00AC00B100D700F703F60606-060820442052207A-207C208A-208C2140-2144214B2190-2194219A219B21A021A321A621AE21CE21CF21D221D421F4-22FF2308-230B23202321237C239B-23B323DC-23E125B725C125F8-25FF266F27C0-27C427C7-27CA27CC27D0-27E527F0-27FF2900-29822999-29D729DC-29FB29FE-2AFF2B30-2B442B47-2B4CFB29FE62FE64-FE66FF0BFF1C-FF1EFF5CFF5EFFE2FFE9-FFEC",
  273. Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
  274. Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
  275. So: "00A600A700A900AE00B000B60482060E060F06E906FD06FE07F609FA0B700BF3-0BF80BFA0C7F0CF10CF20D790F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-1399194019E0-19FF1B61-1B6A1B74-1B7C210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B214A214C214D214F2195-2199219C-219F21A121A221A421A521A7-21AD21AF-21CD21D021D121D321D5-21F32300-2307230C-231F2322-2328232B-237B237D-239A23B4-23DB23E2-23E82400-24262440-244A249C-24E92500-25B625B8-25C025C2-25F72600-266E2670-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE2800-28FF2B00-2B2F2B452B462B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A828-A82BA836A837A839AA77-AA79FDFDFFE4FFE8FFEDFFEEFFFCFFFD",
  276. Z: "002000A01680180E2000-200A20282029202F205F3000",
  277. Zs: "002000A01680180E2000-200A202F205F3000",
  278. Zl: "2028",
  279. Zp: "2029",
  280. C: "0000-001F007F-009F00AD03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-0605061C061D0620065F06DD070E070F074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17B417B517DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF200B-200F202A-202E2060-206F20722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-F8FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFD-FF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFFBFFFEFFFF",
  281. Cc: "0000-001F007F-009F",
  282. Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
  283. Co: "E000-F8FF",
  284. Cs: "D800-DFFF",
  285. Cn: "03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-05FF06040605061C061D0620065F070E074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF2065-206920722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-D7FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFDFEFEFF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFF8FFFEFFFF"
  286. });
  287. function addUnicodePackage (pack) {
  288. var codePoint = /\w{4}/g;
  289. for (var name in pack)
  290. exports.packages[name] = pack[name].replace(codePoint, "\\u$&");
  291. };
  292. });
  293. ace.define('ace/token_iterator', ['require', 'exports', 'module' ], function(require, exports, module) {
  294. var TokenIterator = function(session, initialRow, initialColumn) {
  295. this.$session = session;
  296. this.$row = initialRow;
  297. this.$rowTokens = session.getTokens(initialRow);
  298. var token = session.getTokenAt(initialRow, initialColumn);
  299. this.$tokenIndex = token ? token.index : -1;
  300. };
  301. (function() {
  302. this.stepBackward = function() {
  303. this.$tokenIndex -= 1;
  304. while (this.$tokenIndex < 0) {
  305. this.$row -= 1;
  306. if (this.$row < 0) {
  307. this.$row = 0;
  308. return null;
  309. }
  310. this.$rowTokens = this.$session.getTokens(this.$row);
  311. this.$tokenIndex = this.$rowTokens.length - 1;
  312. }
  313. return this.$rowTokens[this.$tokenIndex];
  314. };
  315. this.stepForward = function() {
  316. this.$tokenIndex += 1;
  317. var rowCount;
  318. while (this.$tokenIndex >= this.$rowTokens.length) {
  319. this.$row += 1;
  320. if (!rowCount)
  321. rowCount = this.$session.getLength();
  322. if (this.$row >= rowCount) {
  323. this.$row = rowCount - 1;
  324. return null;
  325. }
  326. this.$rowTokens = this.$session.getTokens(this.$row);
  327. this.$tokenIndex = 0;
  328. }
  329. return this.$rowTokens[this.$tokenIndex];
  330. };
  331. this.getCurrentToken = function () {
  332. return this.$rowTokens[this.$tokenIndex];
  333. };
  334. this.getCurrentTokenRow = function () {
  335. return this.$row;
  336. };
  337. this.getCurrentTokenColumn = function() {
  338. var rowTokens = this.$rowTokens;
  339. var tokenIndex = this.$tokenIndex;
  340. var column = rowTokens[tokenIndex].start;
  341. if (column !== undefined)
  342. return column;
  343. column = 0;
  344. while (tokenIndex > 0) {
  345. tokenIndex -= 1;
  346. column += rowTokens[tokenIndex].value.length;
  347. }
  348. return column;
  349. };
  350. }).call(TokenIterator.prototype);
  351. exports.TokenIterator = TokenIterator;
  352. });
  353. ace.define('ace/mode/text_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/lang'], function(require, exports, module) {
  354. var lang = require("../lib/lang");
  355. var TextHighlightRules = function() {
  356. this.$rules = {
  357. "start" : [{
  358. token : "empty_line",
  359. regex : '^$'
  360. }, {
  361. defaultToken : "text"
  362. }]
  363. };
  364. };
  365. (function() {
  366. this.addRules = function(rules, prefix) {
  367. if (!prefix) {
  368. for (var key in rules)
  369. this.$rules[key] = rules[key];
  370. return;
  371. }
  372. for (var key in rules) {
  373. var state = rules[key];
  374. for (var i = 0; i < state.length; i++) {
  375. var rule = state[i];
  376. if (rule.next) {
  377. if (typeof rule.next != "string") {
  378. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  379. rule.nextState = prefix + rule.nextState;
  380. } else {
  381. if (rule.next.indexOf(prefix) !== 0)
  382. rule.next = prefix + rule.next;
  383. }
  384. }
  385. }
  386. this.$rules[prefix + key] = state;
  387. }
  388. };
  389. this.getRules = function() {
  390. return this.$rules;
  391. };
  392. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  393. var embedRules = typeof HighlightRules == "function"
  394. ? new HighlightRules().getRules()
  395. : HighlightRules;
  396. if (states) {
  397. for (var i = 0; i < states.length; i++)
  398. states[i] = prefix + states[i];
  399. } else {
  400. states = [];
  401. for (var key in embedRules)
  402. states.push(prefix + key);
  403. }
  404. this.addRules(embedRules, prefix);
  405. if (escapeRules) {
  406. var addRules = Array.prototype[append ? "push" : "unshift"];
  407. for (var i = 0; i < states.length; i++)
  408. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  409. }
  410. if (!this.$embeds)
  411. this.$embeds = [];
  412. this.$embeds.push(prefix);
  413. };
  414. this.getEmbeds = function() {
  415. return this.$embeds;
  416. };
  417. var pushState = function(currentState, stack) {
  418. if (currentState != "start" || stack.length)
  419. stack.unshift(this.nextState, currentState);
  420. return this.nextState;
  421. };
  422. var popState = function(currentState, stack) {
  423. stack.shift();
  424. return stack.shift() || "start";
  425. };
  426. this.normalizeRules = function() {
  427. var id = 0;
  428. var rules = this.$rules;
  429. function processState(key) {
  430. var state = rules[key];
  431. state.processed = true;
  432. for (var i = 0; i < state.length; i++) {
  433. var rule = state[i];
  434. if (!rule.regex && rule.start) {
  435. rule.regex = rule.start;
  436. if (!rule.next)
  437. rule.next = [];
  438. rule.next.push({
  439. defaultToken: rule.token
  440. }, {
  441. token: rule.token + ".end",
  442. regex: rule.end || rule.start,
  443. next: "pop"
  444. });
  445. rule.token = rule.token + ".start";
  446. rule.push = true;
  447. }
  448. var next = rule.next || rule.push;
  449. if (next && Array.isArray(next)) {
  450. var stateName = rule.stateName;
  451. if (!stateName) {
  452. stateName = rule.token;
  453. if (typeof stateName != "string")
  454. stateName = stateName[0] || "";
  455. if (rules[stateName])
  456. stateName += id++;
  457. }
  458. rules[stateName] = next;
  459. rule.next = stateName;
  460. processState(stateName);
  461. } else if (next == "pop") {
  462. rule.next = popState;
  463. }
  464. if (rule.push) {
  465. rule.nextState = rule.next || rule.push;
  466. rule.next = pushState;
  467. delete rule.push;
  468. }
  469. if (rule.rules) {
  470. for (var r in rule.rules) {
  471. if (rules[r]) {
  472. if (rules[r].push)
  473. rules[r].push.apply(rules[r], rule.rules[r]);
  474. } else {
  475. rules[r] = rule.rules[r];
  476. }
  477. }
  478. }
  479. if (rule.include || typeof rule == "string") {
  480. var includeName = rule.include || rule;
  481. var toInsert = rules[includeName];
  482. } else if (Array.isArray(rule))
  483. toInsert = rule;
  484. if (toInsert) {
  485. var args = [i, 1].concat(toInsert);
  486. if (rule.noEscape)
  487. args = args.filter(function(x) {return !x.next;});
  488. state.splice.apply(state, args);
  489. i--;
  490. toInsert = null;
  491. }
  492. if (rule.keywordMap) {
  493. rule.token = this.createKeywordMapper(
  494. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  495. );
  496. delete rule.defaultToken;
  497. }
  498. }
  499. }
  500. Object.keys(rules).forEach(processState, this);
  501. };
  502. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  503. var keywords = Object.create(null);
  504. Object.keys(map).forEach(function(className) {
  505. var a = map[className];
  506. if (ignoreCase)
  507. a = a.toLowerCase();
  508. var list = a.split(splitChar || "|");
  509. for (var i = list.length; i--; )
  510. keywords[list[i]] = className;
  511. });
  512. if (Object.getPrototypeOf(keywords)) {
  513. keywords.__proto__ = null;
  514. }
  515. this.$keywordList = Object.keys(keywords);
  516. map = null;
  517. return ignoreCase
  518. ? function(value) {return keywords[value.toLowerCase()] || defaultToken }
  519. : function(value) {return keywords[value] || defaultToken };
  520. };
  521. this.getKeywords = function() {
  522. return this.$keywords;
  523. };
  524. }).call(TextHighlightRules.prototype);
  525. exports.TextHighlightRules = TextHighlightRules;
  526. });
  527. ace.define('ace/anchor', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
  528. var oop = require("./lib/oop");
  529. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  530. var Anchor = exports.Anchor = function(doc, row, column) {
  531. this.$onChange = this.onChange.bind(this);
  532. this.attach(doc);
  533. if (typeof column == "undefined")
  534. this.setPosition(row.row, row.column);
  535. else
  536. this.setPosition(row, column);
  537. };
  538. (function() {
  539. oop.implement(this, EventEmitter);
  540. this.getPosition = function() {
  541. return this.$clipPositionToDocument(this.row, this.column);
  542. };
  543. this.getDocument = function() {
  544. return this.document;
  545. };
  546. this.$insertRight = false;
  547. this.onChange = function(e) {
  548. var delta = e.data;
  549. var range = delta.range;
  550. if (range.start.row == range.end.row && range.start.row != this.row)
  551. return;
  552. if (range.start.row > this.row)
  553. return;
  554. if (range.start.row == this.row && range.start.column > this.column)
  555. return;
  556. var row = this.row;
  557. var column = this.column;
  558. var start = range.start;
  559. var end = range.end;
  560. if (delta.action === "insertText") {
  561. if (start.row === row && start.column <= column) {
  562. if (start.column === column && this.$insertRight) {
  563. } else if (start.row === end.row) {
  564. column += end.column - start.column;
  565. } else {
  566. column -= start.column;
  567. row += end.row - start.row;
  568. }
  569. } else if (start.row !== end.row && start.row < row) {
  570. row += end.row - start.row;
  571. }
  572. } else if (delta.action === "insertLines") {
  573. if (start.row === row && column === 0 && this.$insertRight) {
  574. }
  575. else if (start.row <= row) {
  576. row += end.row - start.row;
  577. }
  578. } else if (delta.action === "removeText") {
  579. if (start.row === row && start.column < column) {
  580. if (end.column >= column)
  581. column = start.column;
  582. else
  583. column = Math.max(0, column - (end.column - start.column));
  584. } else if (start.row !== end.row && start.row < row) {
  585. if (end.row === row)
  586. column = Math.max(0, column - end.column) + start.column;
  587. row -= (end.row - start.row);
  588. } else if (end.row === row) {
  589. row -= end.row - start.row;
  590. column = Math.max(0, column - end.column) + start.column;
  591. }
  592. } else if (delta.action == "removeLines") {
  593. if (start.row <= row) {
  594. if (end.row <= row)
  595. row -= end.row - start.row;
  596. else {
  597. row = start.row;
  598. column = 0;
  599. }
  600. }
  601. }
  602. this.setPosition(row, column, true);
  603. };
  604. this.setPosition = function(row, column, noClip) {
  605. var pos;
  606. if (noClip) {
  607. pos = {
  608. row: row,
  609. column: column
  610. };
  611. } else {
  612. pos = this.$clipPositionToDocument(row, column);
  613. }
  614. if (this.row == pos.row && this.column == pos.column)
  615. return;
  616. var old = {
  617. row: this.row,
  618. column: this.column
  619. };
  620. this.row = pos.row;
  621. this.column = pos.column;
  622. this._signal("change", {
  623. old: old,
  624. value: pos
  625. });
  626. };
  627. this.detach = function() {
  628. this.document.removeEventListener("change", this.$onChange);
  629. };
  630. this.attach = function(doc) {
  631. this.document = doc || this.document;
  632. this.document.on("change", this.$onChange);
  633. };
  634. this.$clipPositionToDocument = function(row, column) {
  635. var pos = {};
  636. if (row >= this.document.getLength()) {
  637. pos.row = Math.max(0, this.document.getLength() - 1);
  638. pos.column = this.document.getLine(pos.row).length;
  639. }
  640. else if (row < 0) {
  641. pos.row = 0;
  642. pos.column = 0;
  643. }
  644. else {
  645. pos.row = row;
  646. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  647. }
  648. if (column < 0)
  649. pos.column = 0;
  650. return pos;
  651. };
  652. }).call(Anchor.prototype);
  653. });
  654. ace.define('ace/background_tokenizer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
  655. var oop = require("./lib/oop");
  656. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  657. var BackgroundTokenizer = function(tokenizer, editor) {
  658. this.running = false;
  659. this.lines = [];
  660. this.states = [];
  661. this.currentLine = 0;
  662. this.tokenizer = tokenizer;
  663. var self = this;
  664. this.$worker = function() {
  665. if (!self.running) { return; }
  666. var workerStart = new Date();
  667. var currentLine = self.currentLine;
  668. var endLine = -1;
  669. var doc = self.doc;
  670. while (self.lines[currentLine])
  671. currentLine++;
  672. var startLine = currentLine;
  673. var len = doc.getLength();
  674. var processedLines = 0;
  675. self.running = false;
  676. while (currentLine < len) {
  677. self.$tokenizeRow(currentLine);
  678. endLine = currentLine;
  679. do {
  680. currentLine++;
  681. } while (self.lines[currentLine]);
  682. processedLines ++;
  683. if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
  684. self.running = setTimeout(self.$worker, 20);
  685. self.currentLine = currentLine;
  686. return;
  687. }
  688. }
  689. self.currentLine = currentLine;
  690. if (startLine <= endLine)
  691. self.fireUpdateEvent(startLine, endLine);
  692. };
  693. };
  694. (function(){
  695. oop.implement(this, EventEmitter);
  696. this.setTokenizer = function(tokenizer) {
  697. this.tokenizer = tokenizer;
  698. this.lines = [];
  699. this.states = [];
  700. this.start(0);
  701. };
  702. this.setDocument = function(doc) {
  703. this.doc = doc;
  704. this.lines = [];
  705. this.states = [];
  706. this.stop();
  707. };
  708. this.fireUpdateEvent = function(firstRow, lastRow) {
  709. var data = {
  710. first: firstRow,
  711. last: lastRow
  712. };
  713. this._signal("update", {data: data});
  714. };
  715. this.start = function(startRow) {
  716. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  717. this.lines.splice(this.currentLine, this.lines.length);
  718. this.states.splice(this.currentLine, this.states.length);
  719. this.stop();
  720. this.running = setTimeout(this.$worker, 700);
  721. };
  722. this.scheduleStart = function() {
  723. if (!this.running)
  724. this.running = setTimeout(this.$worker, 700);
  725. }
  726. this.$updateOnChange = function(delta) {
  727. var range = delta.range;
  728. var startRow = range.start.row;
  729. var len = range.end.row - startRow;
  730. if (len === 0) {
  731. this.lines[startRow] = null;
  732. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  733. this.lines.splice(startRow, len + 1, null);
  734. this.states.splice(startRow, len + 1, null);
  735. } else {
  736. var args = Array(len + 1);
  737. args.unshift(startRow, 1);
  738. this.lines.splice.apply(this.lines, args);
  739. this.states.splice.apply(this.states, args);
  740. }
  741. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  742. this.stop();
  743. };
  744. this.stop = function() {
  745. if (this.running)
  746. clearTimeout(this.running);
  747. this.running = false;
  748. };
  749. this.getTokens = function(row) {
  750. return this.lines[row] || this.$tokenizeRow(row);
  751. };
  752. this.getState = function(row) {
  753. if (this.currentLine == row)
  754. this.$tokenizeRow(row);
  755. return this.states[row] || "start";
  756. };
  757. this.$tokenizeRow = function(row) {
  758. var line = this.doc.getLine(row);
  759. var state = this.states[row - 1];
  760. var data = this.tokenizer.getLineTokens(line, state, row);
  761. if (this.states[row] + "" !== data.state + "") {
  762. this.states[row] = data.state;
  763. this.lines[row + 1] = null;
  764. if (this.currentLine > row + 1)
  765. this.currentLine = row + 1;
  766. } else if (this.currentLine == row) {
  767. this.currentLine = row + 1;
  768. }
  769. return this.lines[row] = data.tokens;
  770. };
  771. }).call(BackgroundTokenizer.prototype);
  772. exports.BackgroundTokenizer = BackgroundTokenizer;
  773. });
  774. ace.define('ace/search_highlight', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/lib/oop', 'ace/range'], function(require, exports, module) {
  775. var lang = require("./lib/lang");
  776. var oop = require("./lib/oop");
  777. var Range = require("./range").Range;
  778. var SearchHighlight = function(regExp, clazz, type) {
  779. this.setRegexp(regExp);
  780. this.clazz = clazz;
  781. this.type = type || "text";
  782. };
  783. (function() {
  784. this.MAX_RANGES = 500;
  785. this.setRegexp = function(regExp) {
  786. if (this.regExp+"" == regExp+"")
  787. return;
  788. this.regExp = regExp;
  789. this.cache = [];
  790. };
  791. this.update = function(html, markerLayer, session, config) {
  792. if (!this.regExp)
  793. return;
  794. var start = config.firstRow, end = config.lastRow;
  795. for (var i = start; i <= end; i++) {
  796. var ranges = this.cache[i];
  797. if (ranges == null) {
  798. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  799. if (ranges.length > this.MAX_RANGES)
  800. ranges = ranges.slice(0, this.MAX_RANGES);
  801. ranges = ranges.map(function(match) {
  802. return new Range(i, match.offset, i, match.offset + match.length);
  803. });
  804. this.cache[i] = ranges.length ? ranges : "";
  805. }
  806. for (var j = ranges.length; j --; ) {
  807. markerLayer.drawSingleLineMarker(
  808. html, ranges[j].toScreenRange(session), this.clazz, config);
  809. }
  810. }
  811. };
  812. }).call(SearchHighlight.prototype);
  813. exports.SearchHighlight = SearchHighlight;
  814. });
  815. ace.define('ace/edit_session/folding', ['require', 'exports', 'module' , 'ace/range', 'ace/edit_session/fold_line', 'ace/edit_session/fold', 'ace/token_iterator'], function(require, exports, module) {
  816. var Range = require("../range").Range;
  817. var FoldLine = require("./fold_line").FoldLine;
  818. var Fold = require("./fold").Fold;
  819. var TokenIterator = require("../token_iterator").TokenIterator;
  820. function Folding() {
  821. this.getFoldAt = function(row, column, side) {
  822. var foldLine = this.getFoldLine(row);
  823. if (!foldLine)
  824. return null;
  825. var folds = foldLine.folds;
  826. for (var i = 0; i < folds.length; i++) {
  827. var fold = folds[i];
  828. if (fold.range.contains(row, column)) {
  829. if (side == 1 && fold.range.isEnd(row, column)) {
  830. continue;
  831. } else if (side == -1 && fold.range.isStart(row, column)) {
  832. continue;
  833. }
  834. return fold;
  835. }
  836. }
  837. };
  838. this.getFoldsInRange = function(range) {
  839. var start = range.start;
  840. var end = range.end;
  841. var foldLines = this.$foldData;
  842. var foundFolds = [];
  843. start.column += 1;
  844. end.column -= 1;
  845. for (var i = 0; i < foldLines.length; i++) {
  846. var cmp = foldLines[i].range.compareRange(range);
  847. if (cmp == 2) {
  848. continue;
  849. }
  850. else if (cmp == -2) {
  851. break;
  852. }
  853. var folds = foldLines[i].folds;
  854. for (var j = 0; j < folds.length; j++) {
  855. var fold = folds[j];
  856. cmp = fold.range.compareRange(range);
  857. if (cmp == -2) {
  858. break;
  859. } else if (cmp == 2) {
  860. continue;
  861. } else
  862. if (cmp == 42) {
  863. break;
  864. }
  865. foundFolds.push(fold);
  866. }
  867. }
  868. start.column -= 1;
  869. end.column += 1;
  870. return foundFolds;
  871. };
  872. this.getFoldsInRangeList = function(ranges) {
  873. if (Array.isArray(ranges)) {
  874. var folds = [];
  875. ranges.forEach(function(range) {
  876. folds = folds.concat(this.getFoldsInRange(range));
  877. }, this);
  878. } else {
  879. var folds = this.getFoldsInRange(ranges);
  880. }
  881. return folds;
  882. }
  883. this.getAllFolds = function() {
  884. var folds = [];
  885. var foldLines = this.$foldData;
  886. for (var i = 0; i < foldLines.length; i++)
  887. for (var j = 0; j < foldLines[i].folds.length; j++)
  888. folds.push(foldLines[i].folds[j]);
  889. return folds;
  890. };
  891. this.getFoldStringAt = function(row, column, trim, foldLine) {
  892. foldLine = foldLine || this.getFoldLine(row);
  893. if (!foldLine)
  894. return null;
  895. var lastFold = {
  896. end: { column: 0 }
  897. };
  898. var str, fold;
  899. for (var i = 0; i < foldLine.folds.length; i++) {
  900. fold = foldLine.folds[i];
  901. var cmp = fold.range.compareEnd(row, column);
  902. if (cmp == -1) {
  903. str = this
  904. .getLine(fold.start.row)
  905. .substring(lastFold.end.column, fold.start.column);
  906. break;
  907. }
  908. else if (cmp === 0) {
  909. return null;
  910. }
  911. lastFold = fold;
  912. }
  913. if (!str)
  914. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  915. if (trim == -1)
  916. return str.substring(0, column - lastFold.end.column);
  917. else if (trim == 1)
  918. return str.substring(column - lastFold.end.column);
  919. else
  920. return str;
  921. };
  922. this.getFoldLine = function(docRow, startFoldLine) {
  923. var foldData = this.$foldData;
  924. var i = 0;
  925. if (startFoldLine)
  926. i = foldData.indexOf(startFoldLine);
  927. if (i == -1)
  928. i = 0;
  929. for (i; i < foldData.length; i++) {
  930. var foldLine = foldData[i];
  931. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  932. return foldLine;
  933. } else if (foldLine.end.row > docRow) {
  934. return null;
  935. }
  936. }
  937. return null;
  938. };
  939. this.getNextFoldLine = function(docRow, startFoldLine) {
  940. var foldData = this.$foldData;
  941. var i = 0;
  942. if (startFoldLine)
  943. i = foldData.indexOf(startFoldLine);
  944. if (i == -1)
  945. i = 0;
  946. for (i; i < foldData.length; i++) {
  947. var foldLine = foldData[i];
  948. if (foldLine.end.row >= docRow) {
  949. return foldLine;
  950. }
  951. }
  952. return null;
  953. };
  954. this.getFoldedRowCount = function(first, last) {
  955. var foldData = this.$foldData, rowCount = last-first+1;
  956. for (var i = 0; i < foldData.length; i++) {
  957. var foldLine = foldData[i],
  958. end = foldLine.end.row,
  959. start = foldLine.start.row;
  960. if (end >= last) {
  961. if(start < last) {
  962. if(start >= first)
  963. rowCount -= last-start;
  964. else
  965. rowCount = 0;//in one fold
  966. }
  967. break;
  968. } else if(end >= first){
  969. if (start >= first) //fold inside range
  970. rowCount -= end-start;
  971. else
  972. rowCount -= end-first+1;
  973. }
  974. }
  975. return rowCount;
  976. };
  977. this.$addFoldLine = function(foldLine) {
  978. this.$foldData.push(foldLine);
  979. this.$foldData.sort(function(a, b) {
  980. return a.start.row - b.start.row;
  981. });
  982. return foldLine;
  983. };
  984. this.addFold = function(placeholder, range) {
  985. var foldData = this.$foldData;
  986. var added = false;
  987. var fold;
  988. if (placeholder instanceof Fold)
  989. fold = placeholder;
  990. else {
  991. fold = new Fold(range, placeholder);
  992. fold.collapseChildren = range.collapseChildren;
  993. }
  994. this.$clipRangeToDocument(fold.range);
  995. var startRow = fold.start.row;
  996. var startColumn = fold.start.column;
  997. var endRow = fold.end.row;
  998. var endColumn = fold.end.column;
  999. if (!(startRow < endRow ||
  1000. startRow == endRow && startColumn <= endColumn - 2))
  1001. throw new Error("The range has to be at least 2 characters width");
  1002. var startFold = this.getFoldAt(startRow, startColumn, 1);
  1003. var endFold = this.getFoldAt(endRow, endColumn, -1);
  1004. if (startFold && endFold == startFold)
  1005. return startFold.addSubFold(fold);
  1006. if (
  1007. (startFold && !startFold.range.isStart(startRow, startColumn))
  1008. || (endFold && !endFold.range.isEnd(endRow, endColumn))
  1009. ) {
  1010. throw new Error("A fold can't intersect already existing fold" + fold.range + startFold.range);
  1011. }
  1012. var folds = this.getFoldsInRange(fold.range);
  1013. if (folds.length > 0) {
  1014. this.removeFolds(folds);
  1015. folds.forEach(function(subFold) {
  1016. fold.addSubFold(subFold);
  1017. });
  1018. }
  1019. for (var i = 0; i < foldData.length; i++) {
  1020. var foldLine = foldData[i];
  1021. if (endRow == foldLine.start.row) {
  1022. foldLine.addFold(fold);
  1023. added = true;
  1024. break;
  1025. } else if (startRow == foldLine.end.row) {
  1026. foldLine.addFold(fold);
  1027. added = true;
  1028. if (!fold.sameRow) {
  1029. var foldLineNext = foldData[i + 1];
  1030. if (foldLineNext && foldLineNext.start.row == endRow) {
  1031. foldLine.merge(foldLineNext);
  1032. break;
  1033. }
  1034. }
  1035. break;
  1036. } else if (endRow <= foldLine.start.row) {
  1037. break;
  1038. }
  1039. }
  1040. if (!added)
  1041. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  1042. if (this.$useWrapMode)
  1043. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  1044. else
  1045. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  1046. this.$modified = true;
  1047. this._emit("changeFold", { data: fold, action: "add" });
  1048. return fold;
  1049. };
  1050. this.addFolds = function(folds) {
  1051. folds.forEach(function(fold) {
  1052. this.addFold(fold);
  1053. }, this);
  1054. };
  1055. this.removeFold = function(fold) {
  1056. var foldLine = fold.foldLine;
  1057. var startRow = foldLine.start.row;
  1058. var endRow = foldLine.end.row;
  1059. var foldLines = this.$foldData;
  1060. var folds = foldLine.folds;
  1061. if (folds.length == 1) {
  1062. foldLines.splice(foldLines.indexOf(foldLine), 1);
  1063. } else
  1064. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  1065. folds.pop();
  1066. foldLine.end.row = folds[folds.length - 1].end.row;
  1067. foldLine.end.column = folds[folds.length - 1].end.column;
  1068. } else
  1069. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  1070. folds.shift();
  1071. foldLine.start.row = folds[0].start.row;
  1072. foldLine.start.column = folds[0].start.column;
  1073. } else
  1074. if (fold.sameRow) {
  1075. folds.splice(folds.indexOf(fold), 1);
  1076. } else
  1077. {
  1078. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  1079. folds = newFoldLine.folds;
  1080. folds.shift();
  1081. newFoldLine.start.row = folds[0].start.row;
  1082. newFoldLine.start.column = folds[0].start.column;
  1083. }
  1084. if (!this.$updating) {
  1085. if (this.$useWrapMode)
  1086. this.$updateWrapData(startRow, endRow);
  1087. else
  1088. this.$updateRowLengthCache(startRow, endRow);
  1089. }
  1090. this.$modified = true;
  1091. this._emit("changeFold", { data: fold, action: "remove" });
  1092. };
  1093. this.removeFolds = function(folds) {
  1094. var cloneFolds = [];
  1095. for (var i = 0; i < folds.length; i++) {
  1096. cloneFolds.push(folds[i]);
  1097. }
  1098. cloneFolds.forEach(function(fold) {
  1099. this.removeFold(fold);
  1100. }, this);
  1101. this.$modified = true;
  1102. };
  1103. this.expandFold = function(fold) {
  1104. this.removeFold(fold);
  1105. fold.subFolds.forEach(function(subFold) {
  1106. fold.restoreRange(subFold);
  1107. this.addFold(subFold);
  1108. }, this);
  1109. if (fold.collapseChildren > 0) {
  1110. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  1111. }
  1112. fold.subFolds = [];
  1113. };
  1114. this.expandFolds = function(folds) {
  1115. folds.forEach(function(fold) {
  1116. this.expandFold(fold);
  1117. }, this);
  1118. };
  1119. this.unfold = function(location, expandInner) {
  1120. var range, folds;
  1121. if (location == null) {
  1122. range = new Range(0, 0, this.getLength(), 0);
  1123. expandInner = true;
  1124. } else if (typeof location == "number")
  1125. range = new Range(location, 0, location, this.getLine(location).length);
  1126. else if ("row" in location)
  1127. range = Range.fromPoints(location, location);
  1128. else
  1129. range = location;
  1130. folds = this.getFoldsInRangeList(range);
  1131. if (expandInner) {
  1132. this.removeFolds(folds);
  1133. } else {
  1134. var subFolds = folds;
  1135. while (subFolds.length) {
  1136. this.expandFolds(subFolds);
  1137. subFolds = this.getFoldsInRangeList(range);
  1138. }
  1139. }
  1140. if (folds.length)
  1141. return folds;
  1142. };
  1143. this.isRowFolded = function(docRow, startFoldRow) {
  1144. return !!this.getFoldLine(docRow, startFoldRow);
  1145. };
  1146. this.getRowFoldEnd = function(docRow, startFoldRow) {
  1147. var foldLine = this.getFoldLine(docRow, startFoldRow);
  1148. return foldLine ? foldLine.end.row : docRow;
  1149. };
  1150. this.getRowFoldStart = function(docRow, startFoldRow) {
  1151. var foldLine = this.getFoldLine(docRow, startFoldRow);
  1152. return foldLine ? foldLine.start.row : docRow;
  1153. };
  1154. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  1155. if (startRow == null) {
  1156. startRow = foldLine.start.row;
  1157. startColumn = 0;
  1158. }
  1159. if (endRow == null) {
  1160. endRow = foldLine.end.row;
  1161. endColumn = this.getLine(endRow).length;
  1162. }
  1163. var doc = this.doc;
  1164. var textLine = "";
  1165. foldLine.walk(function(placeholder, row, column, lastColumn) {
  1166. if (row < startRow)
  1167. return;
  1168. if (row == startRow) {
  1169. if (column < startColumn)
  1170. return;
  1171. lastColumn = Math.max(startColumn, lastColumn);
  1172. }
  1173. if (placeholder != null) {
  1174. textLine += placeholder;
  1175. } else {
  1176. textLine += doc.getLine(row).substring(lastColumn, column);
  1177. }
  1178. }, endRow, endColumn);
  1179. return textLine;
  1180. };
  1181. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  1182. var foldLine = this.getFoldLine(row);
  1183. if (!foldLine) {
  1184. var line;
  1185. line = this.doc.getLine(row);
  1186. return line.substring(startColumn || 0, endColumn || line.length);
  1187. } else {
  1188. return this.getFoldDisplayLine(
  1189. foldLine, row, endColumn, startRow, startColumn);
  1190. }
  1191. };
  1192. this.$cloneFoldData = function() {
  1193. var fd = [];
  1194. fd = this.$foldData.map(function(foldLine) {
  1195. var folds = foldLine.folds.map(function(fold) {
  1196. return fold.clone();
  1197. });
  1198. return new FoldLine(fd, folds);
  1199. });
  1200. return fd;
  1201. };
  1202. this.toggleFold = function(tryToUnfold) {
  1203. var selection = this.selection;
  1204. var range = selection.getRange();
  1205. var fold;
  1206. var bracketPos;
  1207. if (range.isEmpty()) {
  1208. var cursor = range.start;
  1209. fold = this.getFoldAt(cursor.row, cursor.column);
  1210. if (fold) {
  1211. this.expandFold(fold);
  1212. return;
  1213. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  1214. if (range.comparePoint(bracketPos) == 1) {
  1215. range.end = bracketPos;
  1216. } else {
  1217. range.start = bracketPos;
  1218. range.start.column++;
  1219. range.end.column--;
  1220. }
  1221. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  1222. if (range.comparePoint(bracketPos) == 1)
  1223. range.end = bracketPos;
  1224. else
  1225. range.start = bracketPos;
  1226. range.start.column++;
  1227. } else {
  1228. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  1229. }
  1230. } else {
  1231. var folds = this.getFoldsInRange(range);
  1232. if (tryToUnfold && folds.length) {
  1233. this.expandFolds(folds);
  1234. return;
  1235. } else if (folds.length == 1 ) {
  1236. fold = folds[0];
  1237. }
  1238. }
  1239. if (!fold)
  1240. fold = this.getFoldAt(range.start.row, range.start.column);
  1241. if (fold && fold.range.toString() == range.toString()) {
  1242. this.expandFold(fold);
  1243. return;
  1244. }
  1245. var placeholder = "...";
  1246. if (!range.isMultiLine()) {
  1247. placeholder = this.getTextRange(range);
  1248. if(placeholder.length < 4)
  1249. return;
  1250. placeholder = placeholder.trim().substring(0, 2) + "..";
  1251. }
  1252. this.addFold(placeholder, range);
  1253. };
  1254. this.getCommentFoldRange = function(row, column, dir) {
  1255. var iterator = new TokenIterator(this, row, column);
  1256. var token = iterator.getCurrentToken();
  1257. if (token && /^comment|string/.test(token.type)) {
  1258. var range = new Range();
  1259. var re = new RegExp(token.type.replace(/\..*/, "\\."));
  1260. if (dir != 1) {
  1261. do {
  1262. token = iterator.stepBackward();
  1263. } while(token && re.test(token.type));
  1264. iterator.stepForward();
  1265. }
  1266. range.start.row = iterator.getCurrentTokenRow();
  1267. range.start.column = iterator.getCurrentTokenColumn() + 2;
  1268. iterator = new TokenIterator(this, row, column);
  1269. if (dir != -1) {
  1270. do {
  1271. token = iterator.stepForward();
  1272. } while(token && re.test(token.type));
  1273. token = iterator.stepBackward();
  1274. } else
  1275. token = iterator.getCurrentToken();
  1276. range.end.row = iterator.getCurrentTokenRow();
  1277. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  1278. return range;
  1279. }
  1280. };
  1281. this.foldAll = function(startRow, endRow, depth) {
  1282. if (depth == undefined)
  1283. depth = 100000; // JSON.stringify doesn't hanle Infinity
  1284. var foldWidgets = this.foldWidgets;
  1285. if (!foldWidgets)
  1286. return; // mode doesn't support folding
  1287. endRow = endRow || this.getLength();
  1288. startRow = startRow || 0;
  1289. for (var row = startRow; row < endRow; row++) {
  1290. if (foldWidgets[row] == null)
  1291. foldWidgets[row] = this.getFoldWidget(row);
  1292. if (foldWidgets[row] != "start")
  1293. continue;
  1294. var range = this.getFoldWidgetRange(row);
  1295. if (range && range.isMultiLine()
  1296. && range.end.row <= endRow
  1297. && range.start.row >= startRow
  1298. ) {
  1299. row = range.end.row;
  1300. try {
  1301. var fold = this.addFold("...", range);
  1302. if (fold)
  1303. fold.collapseChildren = depth;
  1304. } catch(e) {}
  1305. }
  1306. }
  1307. };
  1308. this.$foldStyles = {
  1309. "manual": 1,
  1310. "markbegin": 1,
  1311. "markbeginend": 1
  1312. };
  1313. this.$foldStyle = "markbegin";
  1314. this.setFoldStyle = function(style) {
  1315. if (!this.$foldStyles[style])
  1316. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  1317. if (this.$foldStyle == style)
  1318. return;
  1319. this.$foldStyle = style;
  1320. if (style == "manual")
  1321. this.unfold();
  1322. var mode = this.$foldMode;
  1323. this.$setFolding(null);
  1324. this.$setFolding(mode);
  1325. };
  1326. this.$setFolding = function(foldMode) {
  1327. if (this.$foldMode == foldMode)
  1328. return;
  1329. this.$foldMode = foldMode;
  1330. this.removeListener('change', this.$updateFoldWidgets);
  1331. this._emit("changeAnnotation");
  1332. if (!foldMode || this.$foldStyle == "manual") {
  1333. this.foldWidgets = null;
  1334. return;
  1335. }
  1336. this.foldWidgets = [];
  1337. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  1338. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  1339. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  1340. this.on('change', this.$updateFoldWidgets);
  1341. };
  1342. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  1343. var fw = this.foldWidgets;
  1344. if (!fw || (ignoreCurrent && fw[row]))
  1345. return {};
  1346. var i = row - 1, firstRange;
  1347. while (i >= 0) {
  1348. var c = fw[i];
  1349. if (c == null)
  1350. c = fw[i] = this.getFoldWidget(i);
  1351. if (c == "start") {
  1352. var range = this.getFoldWidgetRange(i);
  1353. if (!firstRange)
  1354. firstRange = range;
  1355. if (range && range.end.row >= row)
  1356. break;
  1357. }
  1358. i--;
  1359. }
  1360. return {
  1361. range: i !== -1 && range,
  1362. firstRange: firstRange
  1363. };
  1364. }
  1365. this.onFoldWidgetClick = function(row, e) {
  1366. e = e.domEvent;
  1367. var options = {
  1368. children: e.shiftKey,
  1369. all: e.ctrlKey || e.metaKey,
  1370. siblings: e.altKey
  1371. };
  1372. var range = this.$toggleFoldWidget(row, options);
  1373. if (!range) {
  1374. var el = (e.target || e.srcElement)
  1375. if (el && /ace_fold-widget/.test(el.className))
  1376. el.className += " ace_invalid";
  1377. }
  1378. };
  1379. this.$toggleFoldWidget = function(row, options) {
  1380. if (!this.getFoldWidget)
  1381. return;
  1382. var type = this.getFoldWidget(row);
  1383. var line = this.getLine(row);
  1384. var dir = type === "end" ? -1 : 1;
  1385. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  1386. if (fold) {
  1387. if (options.children || options.all)
  1388. this.removeFold(fold);
  1389. else
  1390. this.expandFold(fold);
  1391. return;
  1392. }
  1393. var range = this.getFoldWidgetRange(row, true);
  1394. if (range && !range.isMultiLine()) {
  1395. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  1396. if (fold && range.isEqual(fold.range)) {
  1397. this.removeFold(fold);
  1398. return;
  1399. }
  1400. }
  1401. if (options.siblings) {
  1402. var data = this.getParentFoldRangeData(row);
  1403. if (data.range) {
  1404. var startRow = data.range.start.row + 1;
  1405. var endRow = data.range.end.row;
  1406. }
  1407. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  1408. } else if (options.children) {
  1409. endRow = range ? range.end.row : this.getLength();
  1410. this.foldAll(row + 1, range.end.row, options.all ? 10000 : 0);
  1411. } else if (range) {
  1412. if (options.all)
  1413. range.collapseChildren = 10000;
  1414. this.addFold("...", range);
  1415. }
  1416. return range;
  1417. };
  1418. this.toggleFoldWidget = function(toggleParent) {
  1419. var row = this.selection.getCursor().row;
  1420. row = this.getRowFoldStart(row);
  1421. var range = this.$toggleFoldWidget(row, {});
  1422. if (range)
  1423. return;
  1424. var data = this.getParentFoldRangeData(row, true);
  1425. range = data.range || data.firstRange;
  1426. if (range) {
  1427. row = range.start.row;
  1428. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  1429. if (fold) {
  1430. this.removeFold(fold);
  1431. } else {
  1432. this.addFold("...", range);
  1433. }
  1434. }
  1435. };
  1436. this.updateFoldWidgets = function(e) {
  1437. var delta = e.data;
  1438. var range = delta.range;
  1439. var firstRow = range.start.row;
  1440. var len = range.end.row - firstRow;
  1441. if (len === 0) {
  1442. this.foldWidgets[firstRow] = null;
  1443. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  1444. this.foldWidgets.splice(firstRow, len + 1, null);
  1445. } else {
  1446. var args = Array(len + 1);
  1447. args.unshift(firstRow, 1);
  1448. this.foldWidgets.splice.apply(this.foldWidgets, args);
  1449. }
  1450. };
  1451. }
  1452. exports.Folding = Folding;
  1453. });
  1454. ace.define('ace/edit_session/fold_line', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  1455. var Range = require("../range").Range;
  1456. function FoldLine(foldData, folds) {
  1457. this.foldData = foldData;
  1458. if (Array.isArray(folds)) {
  1459. this.folds = folds;
  1460. } else {
  1461. folds = this.folds = [ folds ];
  1462. }
  1463. var last = folds[folds.length - 1]
  1464. this.range = new Range(folds[0].start.row, folds[0].start.column,
  1465. last.end.row, last.end.column);
  1466. this.start = this.range.start;
  1467. this.end = this.range.end;
  1468. this.folds.forEach(function(fold) {
  1469. fold.setFoldLine(this);
  1470. }, this);
  1471. }
  1472. (function() {
  1473. this.shiftRow = function(shift) {
  1474. this.start.row += shift;
  1475. this.end.row += shift;
  1476. this.folds.forEach(function(fold) {
  1477. fold.start.row += shift;
  1478. fold.end.row += shift;
  1479. });
  1480. }
  1481. this.addFold = function(fold) {
  1482. if (fold.sameRow) {
  1483. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  1484. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  1485. }
  1486. this.folds.push(fold);
  1487. this.folds.sort(function(a, b) {
  1488. return -a.range.compareEnd(b.start.row, b.start.column);
  1489. });
  1490. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  1491. this.end.row = fold.end.row;
  1492. this.end.column = fold.end.column;
  1493. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  1494. this.start.row = fold.start.row;
  1495. this.start.column = fold.start.column;
  1496. }
  1497. } else if (fold.start.row == this.end.row) {
  1498. this.folds.push(fold);
  1499. this.end.row = fold.end.row;
  1500. this.end.column = fold.end.column;
  1501. } else if (fold.end.row == this.start.row) {
  1502. this.folds.unshift(fold);
  1503. this.start.row = fold.start.row;
  1504. this.start.column = fold.start.column;
  1505. } else {
  1506. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  1507. }
  1508. fold.foldLine = this;
  1509. }
  1510. this.containsRow = function(row) {
  1511. return row >= this.start.row && row <= this.end.row;
  1512. }
  1513. this.walk = function(callback, endRow, endColumn) {
  1514. var lastEnd = 0,
  1515. folds = this.folds,
  1516. fold,
  1517. comp, stop, isNewRow = true;
  1518. if (endRow == null) {
  1519. endRow = this.end.row;
  1520. endColumn = this.end.column;
  1521. }
  1522. for (var i = 0; i < folds.length; i++) {
  1523. fold = folds[i];
  1524. comp = fold.range.compareStart(endRow, endColumn);
  1525. if (comp == -1) {
  1526. callback(null, endRow, endColumn, lastEnd, isNewRow);
  1527. return;
  1528. }
  1529. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  1530. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  1531. if (stop || comp == 0) {
  1532. return;
  1533. }
  1534. isNewRow = !fold.sameRow;
  1535. lastEnd = fold.end.column;
  1536. }
  1537. callback(null, endRow, endColumn, lastEnd, isNewRow);
  1538. }
  1539. this.getNextFoldTo = function(row, column) {
  1540. var fold, cmp;
  1541. for (var i = 0; i < this.folds.length; i++) {
  1542. fold = this.folds[i];
  1543. cmp = fold.range.compareEnd(row, column);
  1544. if (cmp == -1) {
  1545. return {
  1546. fold: fold,
  1547. kind: "after"
  1548. };
  1549. } else if (cmp == 0) {
  1550. return {
  1551. fold: fold,
  1552. kind: "inside"
  1553. }
  1554. }
  1555. }
  1556. return null;
  1557. }
  1558. this.addRemoveChars = function(row, column, len) {
  1559. var ret = this.getNextFoldTo(row, column),
  1560. fold, folds;
  1561. if (ret) {
  1562. fold = ret.fold;
  1563. if (ret.kind == "inside"
  1564. && fold.start.column != column
  1565. && fold.start.row != row)
  1566. {
  1567. window.console && window.console.log(row, column, fold);
  1568. } else if (fold.start.row == row) {
  1569. folds = this.folds;
  1570. var i = folds.indexOf(fold);
  1571. if (i == 0) {
  1572. this.start.column += len;
  1573. }
  1574. for (i; i < folds.length; i++) {
  1575. fold = folds[i];
  1576. fold.start.column += len;
  1577. if (!fold.sameRow) {
  1578. return;
  1579. }
  1580. fold.end.column += len;
  1581. }
  1582. this.end.column += len;
  1583. }
  1584. }
  1585. }
  1586. this.split = function(row, column) {
  1587. var fold = this.getNextFoldTo(row, column).fold;
  1588. var folds = this.folds;
  1589. var foldData = this.foldData;
  1590. if (!fold)
  1591. return null;
  1592. var i = folds.indexOf(fold);
  1593. var foldBefore = folds[i - 1];
  1594. this.end.row = foldBefore.end.row;
  1595. this.end.column = foldBefore.end.column;
  1596. folds = folds.splice(i, folds.length - i);
  1597. var newFoldLine = new FoldLine(foldData, folds);
  1598. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  1599. return newFoldLine;
  1600. }
  1601. this.merge = function(foldLineNext) {
  1602. var folds = foldLineNext.folds;
  1603. for (var i = 0; i < folds.length; i++) {
  1604. this.addFold(folds[i]);
  1605. }
  1606. var foldData = this.foldData;
  1607. foldData.splice(foldData.indexOf(foldLineNext), 1);
  1608. }
  1609. this.toString = function() {
  1610. var ret = [this.range.toString() + ": [" ];
  1611. this.folds.forEach(function(fold) {
  1612. ret.push(" " + fold.toString());
  1613. });
  1614. ret.push("]")
  1615. return ret.join("\n");
  1616. }
  1617. this.idxToPosition = function(idx) {
  1618. var lastFoldEndColumn = 0;
  1619. var fold;
  1620. for (var i = 0; i < this.folds.length; i++) {
  1621. var fold = this.folds[i];
  1622. idx -= fold.start.column - lastFoldEndColumn;
  1623. if (idx < 0) {
  1624. return {
  1625. row: fold.start.row,
  1626. column: fold.start.column + idx
  1627. };
  1628. }
  1629. idx -= fold.placeholder.length;
  1630. if (idx < 0) {
  1631. return fold.start;
  1632. }
  1633. lastFoldEndColumn = fold.end.column;
  1634. }
  1635. return {
  1636. row: this.end.row,
  1637. column: this.end.column + idx
  1638. };
  1639. }
  1640. }).call(FoldLine.prototype);
  1641. exports.FoldLine = FoldLine;
  1642. });
  1643. ace.define('ace/tokenizer', ['require', 'exports', 'module' ], function(require, exports, module) {
  1644. var MAX_TOKEN_COUNT = 1000;
  1645. var Tokenizer = function(rules) {
  1646. this.states = rules;
  1647. this.regExps = {};
  1648. this.matchMappings = {};
  1649. for (var key in this.states) {
  1650. var state = this.states[key];
  1651. var ruleRegExps = [];
  1652. var matchTotal = 0;
  1653. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  1654. var flag = "g";
  1655. var splitterRurles = [];
  1656. for (var i = 0; i < state.length; i++) {
  1657. var rule = state[i];
  1658. if (rule.defaultToken)
  1659. mapping.defaultToken = rule.defaultToken;
  1660. if (rule.caseInsensitive)
  1661. flag = "gi";
  1662. if (rule.regex == null)
  1663. continue;
  1664. if (rule.regex instanceof RegExp)
  1665. rule.regex = rule.regex.toString().slice(1, -1);
  1666. var adjustedregex = rule.regex;
  1667. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  1668. if (Array.isArray(rule.token)) {
  1669. if (rule.token.length == 1 || matchcount == 1) {
  1670. rule.token = rule.token[0];
  1671. } else if (matchcount - 1 != rule.token.length) {
  1672. throw new Error("number of classes and regexp groups in '" +
  1673. rule.token + "'\n'" + rule.regex + "' doesn't match\n"
  1674. + (matchcount - 1) + "!=" + rule.token.length);
  1675. } else {
  1676. rule.tokenArray = rule.token;
  1677. rule.token = null;
  1678. rule.onMatch = this.$arrayTokens;
  1679. }
  1680. } else if (typeof rule.token == "function" && !rule.onMatch) {
  1681. if (matchcount > 1)
  1682. rule.onMatch = this.$applyToken;
  1683. else
  1684. rule.onMatch = rule.token;
  1685. }
  1686. if (matchcount > 1) {
  1687. if (/\\\d/.test(rule.regex)) {
  1688. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  1689. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  1690. });
  1691. } else {
  1692. matchcount = 1;
  1693. adjustedregex = this.removeCapturingGroups(rule.regex);
  1694. }
  1695. if (!rule.splitRegex && typeof rule.token != "string")
  1696. splitterRurles.push(rule); // flag will be known only at the very end
  1697. }
  1698. mapping[matchTotal] = i;
  1699. matchTotal += matchcount;
  1700. ruleRegExps.push(adjustedregex);
  1701. if (!rule.onMatch)
  1702. rule.onMatch = null;
  1703. }
  1704. splitterRurles.forEach(function(rule) {
  1705. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  1706. }, this);
  1707. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  1708. }
  1709. };
  1710. (function() {
  1711. this.$setMaxTokenCount = function(m) {
  1712. MAX_TOKEN_COUNT = m | 0;
  1713. };
  1714. this.$applyToken = function(str) {
  1715. var values = this.splitRegex.exec(str).slice(1);
  1716. var types = this.token.apply(this, values);
  1717. if (typeof types === "string")
  1718. return [{type: types, value: str}];
  1719. var tokens = [];
  1720. for (var i = 0, l = types.length; i < l; i++) {
  1721. if (values[i])
  1722. tokens[tokens.length] = {
  1723. type: types[i],
  1724. value: values[i]
  1725. };
  1726. }
  1727. return tokens;
  1728. },
  1729. this.$arrayTokens = function(str) {
  1730. if (!str)
  1731. return [];
  1732. var values = this.splitRegex.exec(str);
  1733. if (!values)
  1734. return "text";
  1735. var tokens = [];
  1736. var types = this.tokenArray;
  1737. for (var i = 0, l = types.length; i < l; i++) {
  1738. if (values[i + 1])
  1739. tokens[tokens.length] = {
  1740. type: types[i],
  1741. value: values[i + 1]
  1742. };
  1743. }
  1744. return tokens;
  1745. };
  1746. this.removeCapturingGroups = function(src) {
  1747. var r = src.replace(
  1748. /\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g,
  1749. function(x, y) {return y ? "(?:" : x;}
  1750. );
  1751. return r;
  1752. };
  1753. this.createSplitterRegexp = function(src, flag) {
  1754. if (src.indexOf("(?=") != -1) {
  1755. var stack = 0;
  1756. var inChClass = false;
  1757. var lastCapture = {};
  1758. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  1759. m, esc, parenOpen, parenClose, square, index
  1760. ) {
  1761. if (inChClass) {
  1762. inChClass = square != "]";
  1763. } else if (square) {
  1764. inChClass = true;
  1765. } else if (parenClose) {
  1766. if (stack == lastCapture.stack) {
  1767. lastCapture.end = index+1;
  1768. lastCapture.stack = -1;
  1769. }
  1770. stack--;
  1771. } else if (parenOpen) {
  1772. stack++;
  1773. if (parenOpen.length != 1) {
  1774. lastCapture.stack = stack
  1775. lastCapture.start = index;
  1776. }
  1777. }
  1778. return m;
  1779. });
  1780. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  1781. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  1782. }
  1783. return new RegExp(src, (flag||"").replace("g", ""));
  1784. };
  1785. this.getLineTokens = function(line, startState) {
  1786. if (startState && typeof startState != "string") {
  1787. var stack = startState.slice(0);
  1788. startState = stack[0];
  1789. } else
  1790. var stack = [];
  1791. var currentState = startState || "start";
  1792. var state = this.states[currentState];
  1793. if (!state) {
  1794. currentState = "start";
  1795. state = this.states[currentState];
  1796. }
  1797. var mapping = this.matchMappings[currentState];
  1798. var re = this.regExps[currentState];
  1799. re.lastIndex = 0;
  1800. var match, tokens = [];
  1801. var lastIndex = 0;
  1802. var token = {type: null, value: ""};
  1803. while (match = re.exec(line)) {
  1804. var type = mapping.defaultToken;
  1805. var rule = null;
  1806. var value = match[0];
  1807. var index = re.lastIndex;
  1808. if (index - value.length > lastIndex) {
  1809. var skipped = line.substring(lastIndex, index - value.length);
  1810. if (token.type == type) {
  1811. token.value += skipped;
  1812. } else {
  1813. if (token.type)
  1814. tokens.push(token);
  1815. token = {type: type, value: skipped};
  1816. }
  1817. }
  1818. for (var i = 0; i < match.length-2; i++) {
  1819. if (match[i + 1] === undefined)
  1820. continue;
  1821. rule = state[mapping[i]];
  1822. if (rule.onMatch)
  1823. type = rule.onMatch(value, currentState, stack);
  1824. else
  1825. type = rule.token;
  1826. if (rule.next) {
  1827. if (typeof rule.next == "string")
  1828. currentState = rule.next;
  1829. else
  1830. currentState = rule.next(currentState, stack);
  1831. state = this.states[currentState];
  1832. if (!state) {
  1833. window.console && console.error && console.error(currentState, "doesn't exist");
  1834. currentState = "start";
  1835. state = this.states[currentState];
  1836. }
  1837. mapping = this.matchMappings[currentState];
  1838. lastIndex = index;
  1839. re = this.regExps[currentState];
  1840. re.lastIndex = index;
  1841. }
  1842. break;
  1843. }
  1844. if (value) {
  1845. if (typeof type == "string") {
  1846. if ((!rule || rule.merge !== false) && token.type === type) {
  1847. token.value += value;
  1848. } else {
  1849. if (token.type)
  1850. tokens.push(token);
  1851. token = {type: type, value: value};
  1852. }
  1853. } else if (type) {
  1854. if (token.type)
  1855. tokens.push(token);
  1856. token = {type: null, value: ""};
  1857. for (var i = 0; i < type.length; i++)
  1858. tokens.push(type[i]);
  1859. }
  1860. }
  1861. if (lastIndex == line.length)
  1862. break;
  1863. lastIndex = index;
  1864. if (tokens.length > MAX_TOKEN_COUNT) {
  1865. while (lastIndex < line.length) {
  1866. if (token.type)
  1867. tokens.push(token);
  1868. token = {
  1869. value: line.substring(lastIndex, lastIndex += 2000),
  1870. type: "overflow"
  1871. };
  1872. }
  1873. currentState = "start";
  1874. stack = [];
  1875. break;
  1876. }
  1877. }
  1878. if (token.type)
  1879. tokens.push(token);
  1880. if (stack.length > 1) {
  1881. if (stack[0] !== currentState)
  1882. stack.unshift(currentState);
  1883. }
  1884. return {
  1885. tokens : tokens,
  1886. state : stack.length ? stack : currentState
  1887. };
  1888. };
  1889. }).call(Tokenizer.prototype);
  1890. exports.Tokenizer = Tokenizer;
  1891. });
  1892. ace.define('ace/edit_session/fold', ['require', 'exports', 'module' , 'ace/range', 'ace/range_list', 'ace/lib/oop'], function(require, exports, module) {
  1893. var Range = require("../range").Range;
  1894. var RangeList = require("../range_list").RangeList;
  1895. var oop = require("../lib/oop")
  1896. var Fold = exports.Fold = function(range, placeholder) {
  1897. this.foldLine = null;
  1898. this.placeholder = placeholder;
  1899. this.range = range;
  1900. this.start = range.start;
  1901. this.end = range.end;
  1902. this.sameRow = range.start.row == range.end.row;
  1903. this.subFolds = this.ranges = [];
  1904. };
  1905. oop.inherits(Fold, RangeList);
  1906. (function() {
  1907. this.toString = function() {
  1908. return '"' + this.placeholder + '" ' + this.range.toString();
  1909. };
  1910. this.setFoldLine = function(foldLine) {
  1911. this.foldLine = foldLine;
  1912. this.subFolds.forEach(function(fold) {
  1913. fold.setFoldLine(foldLine);
  1914. });
  1915. };
  1916. this.clone = function() {
  1917. var range = this.range.clone();
  1918. var fold = new Fold(range, this.placeholder);
  1919. this.subFolds.forEach(function(subFold) {
  1920. fold.subFolds.push(subFold.clone());
  1921. });
  1922. fold.collapseChildren = this.collapseChildren;
  1923. return fold;
  1924. };
  1925. this.addSubFold = function(fold) {
  1926. if (this.range.isEqual(fold))
  1927. return;
  1928. if (!this.range.containsRange(fold))
  1929. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  1930. consumeRange(fold, this.start);
  1931. var row = fold.start.row, column = fold.start.column;
  1932. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  1933. cmp = this.subFolds[i].range.compare(row, column);
  1934. if (cmp != 1)
  1935. break;
  1936. }
  1937. var afterStart = this.subFolds[i];
  1938. if (cmp == 0)
  1939. return afterStart.addSubFold(fold);
  1940. var row = fold.range.end.row, column = fold.range.end.column;
  1941. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  1942. cmp = this.subFolds[j].range.compare(row, column);
  1943. if (cmp != 1)
  1944. break;
  1945. }
  1946. var afterEnd = this.subFolds[j];
  1947. if (cmp == 0)
  1948. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  1949. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  1950. fold.setFoldLine(this.foldLine);
  1951. return fold;
  1952. };
  1953. this.restoreRange = function(range) {
  1954. return restoreRange(range, this.start);
  1955. };
  1956. }).call(Fold.prototype);
  1957. function consumePoint(point, anchor) {
  1958. point.row -= anchor.row;
  1959. if (point.row == 0)
  1960. point.column -= anchor.column;
  1961. }
  1962. function consumeRange(range, anchor) {
  1963. consumePoint(range.start, anchor);
  1964. consumePoint(range.end, anchor);
  1965. }
  1966. function restorePoint(point, anchor) {
  1967. if (point.row == 0)
  1968. point.column += anchor.column;
  1969. point.row += anchor.row;
  1970. }
  1971. function restoreRange(range, anchor) {
  1972. restorePoint(range.start, anchor);
  1973. restorePoint(range.end, anchor);
  1974. }
  1975. });
  1976. ace.define('ace/mode/text', ['require', 'exports', 'module' , 'ace/tokenizer', 'ace/mode/text_highlight_rules', 'ace/mode/behaviour', 'ace/unicode', 'ace/lib/lang', 'ace/token_iterator', 'ace/range'], function(require, exports, module) {
  1977. var Tokenizer = require("../tokenizer").Tokenizer;
  1978. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  1979. var Behaviour = require("./behaviour").Behaviour;
  1980. var unicode = require("../unicode");
  1981. var lang = require("../lib/lang");
  1982. var TokenIterator = require("../token_iterator").TokenIterator;
  1983. var Range = require("../range").Range;
  1984. var Mode = function() {
  1985. this.HighlightRules = TextHighlightRules;
  1986. this.$behaviour = new Behaviour();
  1987. };
  1988. (function() {
  1989. this.tokenRe = new RegExp("^["
  1990. + unicode.packages.L
  1991. + unicode.packages.Mn + unicode.packages.Mc
  1992. + unicode.packages.Nd
  1993. + unicode.packages.Pc + "\\$_]+", "g"
  1994. );
  1995. this.nonTokenRe = new RegExp("^(?:[^"
  1996. + unicode.packages.L
  1997. + unicode.packages.Mn + unicode.packages.Mc
  1998. + unicode.packages.Nd
  1999. + unicode.packages.Pc + "\\$_]|\\s])+", "g"
  2000. );
  2001. this.getTokenizer = function() {
  2002. if (!this.$tokenizer) {
  2003. this.$highlightRules = new this.HighlightRules();
  2004. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  2005. }
  2006. return this.$tokenizer;
  2007. };
  2008. this.lineCommentStart = "";
  2009. this.blockComment = "";
  2010. this.toggleCommentLines = function(state, session, startRow, endRow) {
  2011. var doc = session.doc;
  2012. var ignoreBlankLines = true;
  2013. var shouldRemove = true;
  2014. var minIndent = Infinity;
  2015. var tabSize = session.getTabSize();
  2016. var insertAtTabStop = false;
  2017. if (!this.lineCommentStart) {
  2018. if (!this.blockComment)
  2019. return false;
  2020. var lineCommentStart = this.blockComment.start;
  2021. var lineCommentEnd = this.blockComment.end;
  2022. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  2023. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  2024. var comment = function(line, i) {
  2025. if (testRemove(line, i))
  2026. return;
  2027. if (!ignoreBlankLines || /\S/.test(line)) {
  2028. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  2029. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  2030. }
  2031. };
  2032. var uncomment = function(line, i) {
  2033. var m;
  2034. if (m = line.match(regexpEnd))
  2035. doc.removeInLine(i, line.length - m[0].length, line.length);
  2036. if (m = line.match(regexpStart))
  2037. doc.removeInLine(i, m[1].length, m[0].length);
  2038. };
  2039. var testRemove = function(line, row) {
  2040. if (regexpStart.test(line))
  2041. return true;
  2042. var tokens = session.getTokens(row);
  2043. for (var i = 0; i < tokens.length; i++) {
  2044. if (tokens[i].type === 'comment')
  2045. return true;
  2046. }
  2047. };
  2048. } else {
  2049. if (Array.isArray(this.lineCommentStart)) {
  2050. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  2051. var lineCommentStart = this.lineCommentStart[0];
  2052. } else {
  2053. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  2054. var lineCommentStart = this.lineCommentStart;
  2055. }
  2056. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  2057. insertAtTabStop = session.getUseSoftTabs();
  2058. var uncomment = function(line, i) {
  2059. var m = line.match(regexpStart);
  2060. if (!m) return;
  2061. var start = m[1].length, end = m[0].length;
  2062. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  2063. end--;
  2064. doc.removeInLine(i, start, end);
  2065. };
  2066. var commentWithSpace = lineCommentStart + " ";
  2067. var comment = function(line, i) {
  2068. if (!ignoreBlankLines || /\S/.test(line)) {
  2069. if (shouldInsertSpace(line, minIndent, minIndent))
  2070. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  2071. else
  2072. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  2073. }
  2074. };
  2075. var testRemove = function(line, i) {
  2076. return regexpStart.test(line);
  2077. };
  2078. var shouldInsertSpace = function(line, before, after) {
  2079. var spaces = 0;
  2080. while (before-- && line.charAt(before) == " ")
  2081. spaces++;
  2082. if (spaces % tabSize != 0)
  2083. return false;
  2084. var spaces = 0;
  2085. while (line.charAt(after++) == " ")
  2086. spaces++;
  2087. if (tabSize > 2)
  2088. return spaces % tabSize != tabSize - 1;
  2089. else
  2090. return spaces % tabSize == 0;
  2091. return true;
  2092. };
  2093. }
  2094. function iter(fun) {
  2095. for (var i = startRow; i <= endRow; i++)
  2096. fun(doc.getLine(i), i);
  2097. }
  2098. var minEmptyLength = Infinity;
  2099. iter(function(line, i) {
  2100. var indent = line.search(/\S/);
  2101. if (indent !== -1) {
  2102. if (indent < minIndent)
  2103. minIndent = indent;
  2104. if (shouldRemove && !testRemove(line, i))
  2105. shouldRemove = false;
  2106. } else if (minEmptyLength > line.length) {
  2107. minEmptyLength = line.length;
  2108. }
  2109. });
  2110. if (minIndent == Infinity) {
  2111. minIndent = minEmptyLength;
  2112. ignoreBlankLines = false;
  2113. shouldRemove = false;
  2114. }
  2115. if (insertAtTabStop && minIndent % tabSize != 0)
  2116. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  2117. iter(shouldRemove ? uncomment : comment);
  2118. };
  2119. this.toggleBlockComment = function(state, session, range, cursor) {
  2120. var comment = this.blockComment;
  2121. if (!comment)
  2122. return;
  2123. if (!comment.start && comment[0])
  2124. comment = comment[0];
  2125. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  2126. var token = iterator.getCurrentToken();
  2127. var sel = session.selection;
  2128. var initialRange = session.selection.toOrientedRange();
  2129. var startRow, colDiff;
  2130. if (token && /comment/.test(token.type)) {
  2131. var startRange, endRange;
  2132. while (token && /comment/.test(token.type)) {
  2133. var i = token.value.indexOf(comment.start);
  2134. if (i != -1) {
  2135. var row = iterator.getCurrentTokenRow();
  2136. var column = iterator.getCurrentTokenColumn() + i;
  2137. startRange = new Range(row, column, row, column + comment.start.length);
  2138. break;
  2139. }
  2140. token = iterator.stepBackward();
  2141. }
  2142. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  2143. var token = iterator.getCurrentToken();
  2144. while (token && /comment/.test(token.type)) {
  2145. var i = token.value.indexOf(comment.end);
  2146. if (i != -1) {
  2147. var row = iterator.getCurrentTokenRow();
  2148. var column = iterator.getCurrentTokenColumn() + i;
  2149. endRange = new Range(row, column, row, column + comment.end.length);
  2150. break;
  2151. }
  2152. token = iterator.stepForward();
  2153. }
  2154. if (endRange)
  2155. session.remove(endRange);
  2156. if (startRange) {
  2157. session.remove(startRange);
  2158. startRow = startRange.start.row;
  2159. colDiff = -comment.start.length;
  2160. }
  2161. } else {
  2162. colDiff = comment.start.length;
  2163. startRow = range.start.row;
  2164. session.insert(range.end, comment.end);
  2165. session.insert(range.start, comment.start);
  2166. }
  2167. if (initialRange.start.row == startRow)
  2168. initialRange.start.column += colDiff;
  2169. if (initialRange.end.row == startRow)
  2170. initialRange.end.column += colDiff;
  2171. session.selection.fromOrientedRange(initialRange);
  2172. };
  2173. this.getNextLineIndent = function(state, line, tab) {
  2174. return this.$getIndent(line);
  2175. };
  2176. this.checkOutdent = function(state, line, input) {
  2177. return false;
  2178. };
  2179. this.autoOutdent = function(state, doc, row) {
  2180. };
  2181. this.$getIndent = function(line) {
  2182. return line.match(/^\s*/)[0];
  2183. };
  2184. this.createWorker = function(session) {
  2185. return null;
  2186. };
  2187. this.createModeDelegates = function (mapping) {
  2188. this.$embeds = [];
  2189. this.$modes = {};
  2190. for (var i in mapping) {
  2191. if (mapping[i]) {
  2192. this.$embeds.push(i);
  2193. this.$modes[i] = new mapping[i]();
  2194. }
  2195. }
  2196. var delegations = ['toggleBlockComment', 'toggleCommentLines', 'getNextLineIndent',
  2197. 'checkOutdent', 'autoOutdent', 'transformAction', 'getCompletions'];
  2198. for (var i = 0; i < delegations.length; i++) {
  2199. (function(scope) {
  2200. var functionName = delegations[i];
  2201. var defaultHandler = scope[functionName];
  2202. scope[delegations[i]] = function() {
  2203. return this.$delegator(functionName, arguments, defaultHandler);
  2204. };
  2205. } (this));
  2206. }
  2207. };
  2208. this.$delegator = function(method, args, defaultHandler) {
  2209. var state = args[0];
  2210. if (typeof state != "string")
  2211. state = state[0];
  2212. for (var i = 0; i < this.$embeds.length; i++) {
  2213. if (!this.$modes[this.$embeds[i]]) continue;
  2214. var split = state.split(this.$embeds[i]);
  2215. if (!split[0] && split[1]) {
  2216. args[0] = split[1];
  2217. var mode = this.$modes[this.$embeds[i]];
  2218. return mode[method].apply(mode, args);
  2219. }
  2220. }
  2221. var ret = defaultHandler.apply(this, args);
  2222. return defaultHandler ? ret : undefined;
  2223. };
  2224. this.transformAction = function(state, action, editor, session, param) {
  2225. if (this.$behaviour) {
  2226. var behaviours = this.$behaviour.getBehaviours();
  2227. for (var key in behaviours) {
  2228. if (behaviours[key][action]) {
  2229. var ret = behaviours[key][action].apply(this, arguments);
  2230. if (ret) {
  2231. return ret;
  2232. }
  2233. }
  2234. }
  2235. }
  2236. };
  2237. this.getKeywords = function(append) {
  2238. if (!this.completionKeywords) {
  2239. var rules = this.$tokenizer.rules;
  2240. var completionKeywords = [];
  2241. for (var rule in rules) {
  2242. var ruleItr = rules[rule];
  2243. for (var r = 0, l = ruleItr.length; r < l; r++) {
  2244. if (typeof ruleItr[r].token === "string") {
  2245. if (/keyword|support|storage/.test(ruleItr[r].token))
  2246. completionKeywords.push(ruleItr[r].regex);
  2247. }
  2248. else if (typeof ruleItr[r].token === "object") {
  2249. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  2250. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  2251. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  2252. completionKeywords.push(rule.substr(1, rule.length - 2));
  2253. }
  2254. }
  2255. }
  2256. }
  2257. }
  2258. this.completionKeywords = completionKeywords;
  2259. }
  2260. if (!append)
  2261. return this.$keywordList;
  2262. return completionKeywords.concat(this.$keywordList || []);
  2263. };
  2264. this.$createKeywordList = function() {
  2265. if (!this.$highlightRules)
  2266. this.getTokenizer();
  2267. return this.$keywordList = this.$highlightRules.$keywordList || [];
  2268. };
  2269. this.getCompletions = function(state, session, pos, prefix) {
  2270. var keywords = this.$keywordList || this.$createKeywordList();
  2271. return keywords.map(function(word) {
  2272. return {
  2273. name: word,
  2274. value: word,
  2275. score: 0,
  2276. meta: "keyword"
  2277. };
  2278. });
  2279. };
  2280. this.$id = "ace/mode/text";
  2281. }).call(Mode.prototype);
  2282. exports.Mode = Mode;
  2283. });
  2284. ace.define('ace/range_list', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  2285. var Range = require("./range").Range;
  2286. var comparePoints = Range.comparePoints;
  2287. var RangeList = function() {
  2288. this.ranges = [];
  2289. };
  2290. (function() {
  2291. this.comparePoints = comparePoints;
  2292. this.pointIndex = function(pos, excludeEdges, startIndex) {
  2293. var list = this.ranges;
  2294. for (var i = startIndex || 0; i < list.length; i++) {
  2295. var range = list[i];
  2296. var cmpEnd = comparePoints(pos, range.end);
  2297. if (cmpEnd > 0)
  2298. continue;
  2299. var cmpStart = comparePoints(pos, range.start);
  2300. if (cmpEnd === 0)
  2301. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  2302. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  2303. return i;
  2304. return -i-1;
  2305. }
  2306. return -i - 1;
  2307. };
  2308. this.add = function(range) {
  2309. var excludeEdges = !range.isEmpty();
  2310. var startIndex = this.pointIndex(range.start, excludeEdges);
  2311. if (startIndex < 0)
  2312. startIndex = -startIndex - 1;
  2313. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  2314. if (endIndex < 0)
  2315. endIndex = -endIndex - 1;
  2316. else
  2317. endIndex++;
  2318. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  2319. };
  2320. this.addList = function(list) {
  2321. var removed = [];
  2322. for (var i = list.length; i--; ) {
  2323. removed.push.call(removed, this.add(list[i]));
  2324. }
  2325. return removed;
  2326. };
  2327. this.substractPoint = function(pos) {
  2328. var i = this.pointIndex(pos);
  2329. if (i >= 0)
  2330. return this.ranges.splice(i, 1);
  2331. };
  2332. this.merge = function() {
  2333. var removed = [];
  2334. var list = this.ranges;
  2335. list = list.sort(function(a, b) {
  2336. return comparePoints(a.start, b.start);
  2337. });
  2338. var next = list[0], range;
  2339. for (var i = 1; i < list.length; i++) {
  2340. range = next;
  2341. next = list[i];
  2342. var cmp = comparePoints(range.end, next.start);
  2343. if (cmp < 0)
  2344. continue;
  2345. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  2346. continue;
  2347. if (comparePoints(range.end, next.end) < 0) {
  2348. range.end.row = next.end.row;
  2349. range.end.column = next.end.column;
  2350. }
  2351. list.splice(i, 1);
  2352. removed.push(next);
  2353. next = range;
  2354. i--;
  2355. }
  2356. this.ranges = list;
  2357. return removed;
  2358. };
  2359. this.contains = function(row, column) {
  2360. return this.pointIndex({row: row, column: column}) >= 0;
  2361. };
  2362. this.containsPoint = function(pos) {
  2363. return this.pointIndex(pos) >= 0;
  2364. };
  2365. this.rangeAtPoint = function(pos) {
  2366. var i = this.pointIndex(pos);
  2367. if (i >= 0)
  2368. return this.ranges[i];
  2369. };
  2370. this.clipRows = function(startRow, endRow) {
  2371. var list = this.ranges;
  2372. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  2373. return [];
  2374. var startIndex = this.pointIndex({row: startRow, column: 0});
  2375. if (startIndex < 0)
  2376. startIndex = -startIndex - 1;
  2377. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  2378. if (endIndex < 0)
  2379. endIndex = -endIndex - 1;
  2380. var clipped = [];
  2381. for (var i = startIndex; i < endIndex; i++) {
  2382. clipped.push(list[i]);
  2383. }
  2384. return clipped;
  2385. };
  2386. this.removeAll = function() {
  2387. return this.ranges.splice(0, this.ranges.length);
  2388. };
  2389. this.attach = function(session) {
  2390. if (this.session)
  2391. this.detach();
  2392. this.session = session;
  2393. this.onChange = this.$onChange.bind(this);
  2394. this.session.on('change', this.onChange);
  2395. };
  2396. this.detach = function() {
  2397. if (!this.session)
  2398. return;
  2399. this.session.removeListener('change', this.onChange);
  2400. this.session = null;
  2401. };
  2402. this.$onChange = function(e) {
  2403. var changeRange = e.data.range;
  2404. if (e.data.action[0] == "i"){
  2405. var start = changeRange.start;
  2406. var end = changeRange.end;
  2407. } else {
  2408. var end = changeRange.start;
  2409. var start = changeRange.end;
  2410. }
  2411. var startRow = start.row;
  2412. var endRow = end.row;
  2413. var lineDif = endRow - startRow;
  2414. var colDiff = -start.column + end.column;
  2415. var ranges = this.ranges;
  2416. for (var i = 0, n = ranges.length; i < n; i++) {
  2417. var r = ranges[i];
  2418. if (r.end.row < startRow)
  2419. continue;
  2420. if (r.start.row > startRow)
  2421. break;
  2422. if (r.start.row == startRow && r.start.column >= start.column ) {
  2423. if (r.start.column == start.column && this.$insertRight) {
  2424. } else {
  2425. r.start.column += colDiff;
  2426. r.start.row += lineDif;
  2427. }
  2428. }
  2429. if (r.end.row == startRow && r.end.column >= start.column) {
  2430. if (r.end.column == start.column && this.$insertRight) {
  2431. continue;
  2432. }
  2433. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  2434. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  2435. r.end.column -= colDiff;
  2436. }
  2437. r.end.column += colDiff;
  2438. r.end.row += lineDif;
  2439. }
  2440. }
  2441. if (lineDif != 0 && i < n) {
  2442. for (; i < n; i++) {
  2443. var r = ranges[i];
  2444. r.start.row += lineDif;
  2445. r.end.row += lineDif;
  2446. }
  2447. }
  2448. };
  2449. }).call(RangeList.prototype);
  2450. exports.RangeList = RangeList;
  2451. });
  2452. ace.define('ace/range', ['require', 'exports', 'module' ], function(require, exports, module) {
  2453. var comparePoints = function(p1, p2) {
  2454. return p1.row - p2.row || p1.column - p2.column;
  2455. };
  2456. var Range = function(startRow, startColumn, endRow, endColumn) {
  2457. this.start = {
  2458. row: startRow,
  2459. column: startColumn
  2460. };
  2461. this.end = {
  2462. row: endRow,
  2463. column: endColumn
  2464. };
  2465. };
  2466. (function() {
  2467. this.isEqual = function(range) {
  2468. return this.start.row === range.start.row &&
  2469. this.end.row === range.end.row &&
  2470. this.start.column === range.start.column &&
  2471. this.end.column === range.end.column;
  2472. };
  2473. this.toString = function() {
  2474. return ("Range: [" + this.start.row + "/" + this.start.column +
  2475. "] -> [" + this.end.row + "/" + this.end.column + "]");
  2476. };
  2477. this.contains = function(row, column) {
  2478. return this.compare(row, column) == 0;
  2479. };
  2480. this.compareRange = function(range) {
  2481. var cmp,
  2482. end = range.end,
  2483. start = range.start;
  2484. cmp = this.compare(end.row, end.column);
  2485. if (cmp == 1) {
  2486. cmp = this.compare(start.row, start.column);
  2487. if (cmp == 1) {
  2488. return 2;
  2489. } else if (cmp == 0) {
  2490. return 1;
  2491. } else {
  2492. return 0;
  2493. }
  2494. } else if (cmp == -1) {
  2495. return -2;
  2496. } else {
  2497. cmp = this.compare(start.row, start.column);
  2498. if (cmp == -1) {
  2499. return -1;
  2500. } else if (cmp == 1) {
  2501. return 42;
  2502. } else {
  2503. return 0;
  2504. }
  2505. }
  2506. };
  2507. this.comparePoint = function(p) {
  2508. return this.compare(p.row, p.column);
  2509. };
  2510. this.containsRange = function(range) {
  2511. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  2512. };
  2513. this.intersects = function(range) {
  2514. var cmp = this.compareRange(range);
  2515. return (cmp == -1 || cmp == 0 || cmp == 1);
  2516. };
  2517. this.isEnd = function(row, column) {
  2518. return this.end.row == row && this.end.column == column;
  2519. };
  2520. this.isStart = function(row, column) {
  2521. return this.start.row == row && this.start.column == column;
  2522. };
  2523. this.setStart = function(row, column) {
  2524. if (typeof row == "object") {
  2525. this.start.column = row.column;
  2526. this.start.row = row.row;
  2527. } else {
  2528. this.start.row = row;
  2529. this.start.column = column;
  2530. }
  2531. };
  2532. this.setEnd = function(row, column) {
  2533. if (typeof row == "object") {
  2534. this.end.column = row.column;
  2535. this.end.row = row.row;
  2536. } else {
  2537. this.end.row = row;
  2538. this.end.column = column;
  2539. }
  2540. };
  2541. this.inside = function(row, column) {
  2542. if (this.compare(row, column) == 0) {
  2543. if (this.isEnd(row, column) || this.isStart(row, column)) {
  2544. return false;
  2545. } else {
  2546. return true;
  2547. }
  2548. }
  2549. return false;
  2550. };
  2551. this.insideStart = function(row, column) {
  2552. if (this.compare(row, column) == 0) {
  2553. if (this.isEnd(row, column)) {
  2554. return false;
  2555. } else {
  2556. return true;
  2557. }
  2558. }
  2559. return false;
  2560. };
  2561. this.insideEnd = function(row, column) {
  2562. if (this.compare(row, column) == 0) {
  2563. if (this.isStart(row, column)) {
  2564. return false;
  2565. } else {
  2566. return true;
  2567. }
  2568. }
  2569. return false;
  2570. };
  2571. this.compare = function(row, column) {
  2572. if (!this.isMultiLine()) {
  2573. if (row === this.start.row) {
  2574. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  2575. };
  2576. }
  2577. if (row < this.start.row)
  2578. return -1;
  2579. if (row > this.end.row)
  2580. return 1;
  2581. if (this.start.row === row)
  2582. return column >= this.start.column ? 0 : -1;
  2583. if (this.end.row === row)
  2584. return column <= this.end.column ? 0 : 1;
  2585. return 0;
  2586. };
  2587. this.compareStart = function(row, column) {
  2588. if (this.start.row == row && this.start.column == column) {
  2589. return -1;
  2590. } else {
  2591. return this.compare(row, column);
  2592. }
  2593. };
  2594. this.compareEnd = function(row, column) {
  2595. if (this.end.row == row && this.end.column == column) {
  2596. return 1;
  2597. } else {
  2598. return this.compare(row, column);
  2599. }
  2600. };
  2601. this.compareInside = function(row, column) {
  2602. if (this.end.row == row && this.end.column == column) {
  2603. return 1;
  2604. } else if (this.start.row == row && this.start.column == column) {
  2605. return -1;
  2606. } else {
  2607. return this.compare(row, column);
  2608. }
  2609. };
  2610. this.clipRows = function(firstRow, lastRow) {
  2611. if (this.end.row > lastRow)
  2612. var end = {row: lastRow + 1, column: 0};
  2613. else if (this.end.row < firstRow)
  2614. var end = {row: firstRow, column: 0};
  2615. if (this.start.row > lastRow)
  2616. var start = {row: lastRow + 1, column: 0};
  2617. else if (this.start.row < firstRow)
  2618. var start = {row: firstRow, column: 0};
  2619. return Range.fromPoints(start || this.start, end || this.end);
  2620. };
  2621. this.extend = function(row, column) {
  2622. var cmp = this.compare(row, column);
  2623. if (cmp == 0)
  2624. return this;
  2625. else if (cmp == -1)
  2626. var start = {row: row, column: column};
  2627. else
  2628. var end = {row: row, column: column};
  2629. return Range.fromPoints(start || this.start, end || this.end);
  2630. };
  2631. this.isEmpty = function() {
  2632. return (this.start.row === this.end.row && this.start.column === this.end.column);
  2633. };
  2634. this.isMultiLine = function() {
  2635. return (this.start.row !== this.end.row);
  2636. };
  2637. this.clone = function() {
  2638. return Range.fromPoints(this.start, this.end);
  2639. };
  2640. this.collapseRows = function() {
  2641. if (this.end.column == 0)
  2642. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  2643. else
  2644. return new Range(this.start.row, 0, this.end.row, 0)
  2645. };
  2646. this.toScreenRange = function(session) {
  2647. var screenPosStart = session.documentToScreenPosition(this.start);
  2648. var screenPosEnd = session.documentToScreenPosition(this.end);
  2649. return new Range(
  2650. screenPosStart.row, screenPosStart.column,
  2651. screenPosEnd.row, screenPosEnd.column
  2652. );
  2653. };
  2654. this.moveBy = function(row, column) {
  2655. this.start.row += row;
  2656. this.start.column += column;
  2657. this.end.row += row;
  2658. this.end.column += column;
  2659. };
  2660. }).call(Range.prototype);
  2661. Range.fromPoints = function(start, end) {
  2662. return new Range(start.row, start.column, end.row, end.column);
  2663. };
  2664. Range.comparePoints = comparePoints;
  2665. Range.comparePoints = function(p1, p2) {
  2666. return p1.row - p2.row || p1.column - p2.column;
  2667. };
  2668. exports.Range = Range;
  2669. });
  2670. ace.define('ace/edit_session/bracket_match', ['require', 'exports', 'module' , 'ace/token_iterator', 'ace/range'], function(require, exports, module) {
  2671. var TokenIterator = require("../token_iterator").TokenIterator;
  2672. var Range = require("../range").Range;
  2673. function BracketMatch() {
  2674. this.findMatchingBracket = function(position, chr) {
  2675. if (position.column == 0) return null;
  2676. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  2677. if (charBeforeCursor == "") return null;
  2678. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  2679. if (!match)
  2680. return null;
  2681. if (match[1])
  2682. return this.$findClosingBracket(match[1], position);
  2683. else
  2684. return this.$findOpeningBracket(match[2], position);
  2685. };
  2686. this.getBracketRange = function(pos) {
  2687. var line = this.getLine(pos.row);
  2688. var before = true, range;
  2689. var chr = line.charAt(pos.column-1);
  2690. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  2691. if (!match) {
  2692. chr = line.charAt(pos.column);
  2693. pos = {row: pos.row, column: pos.column + 1};
  2694. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  2695. before = false;
  2696. }
  2697. if (!match)
  2698. return null;
  2699. if (match[1]) {
  2700. var bracketPos = this.$findClosingBracket(match[1], pos);
  2701. if (!bracketPos)
  2702. return null;
  2703. range = Range.fromPoints(pos, bracketPos);
  2704. if (!before) {
  2705. range.end.column++;
  2706. range.start.column--;
  2707. }
  2708. range.cursor = range.end;
  2709. } else {
  2710. var bracketPos = this.$findOpeningBracket(match[2], pos);
  2711. if (!bracketPos)
  2712. return null;
  2713. range = Range.fromPoints(bracketPos, pos);
  2714. if (!before) {
  2715. range.start.column++;
  2716. range.end.column--;
  2717. }
  2718. range.cursor = range.start;
  2719. }
  2720. return range;
  2721. };
  2722. this.$brackets = {
  2723. ")": "(",
  2724. "(": ")",
  2725. "]": "[",
  2726. "[": "]",
  2727. "{": "}",
  2728. "}": "{"
  2729. };
  2730. this.$findOpeningBracket = function(bracket, position, typeRe) {
  2731. var openBracket = this.$brackets[bracket];
  2732. var depth = 1;
  2733. var iterator = new TokenIterator(this, position.row, position.column);
  2734. var token = iterator.getCurrentToken();
  2735. if (!token)
  2736. token = iterator.stepForward();
  2737. if (!token)
  2738. return;
  2739. if (!typeRe){
  2740. typeRe = new RegExp(
  2741. "(\\.?" +
  2742. token.type.replace(".", "\\.").replace("rparen", ".paren")
  2743. + ")+"
  2744. );
  2745. }
  2746. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  2747. var value = token.value;
  2748. while (true) {
  2749. while (valueIndex >= 0) {
  2750. var chr = value.charAt(valueIndex);
  2751. if (chr == openBracket) {
  2752. depth -= 1;
  2753. if (depth == 0) {
  2754. return {row: iterator.getCurrentTokenRow(),
  2755. column: valueIndex + iterator.getCurrentTokenColumn()};
  2756. }
  2757. }
  2758. else if (chr == bracket) {
  2759. depth += 1;
  2760. }
  2761. valueIndex -= 1;
  2762. }
  2763. do {
  2764. token = iterator.stepBackward();
  2765. } while (token && !typeRe.test(token.type));
  2766. if (token == null)
  2767. break;
  2768. value = token.value;
  2769. valueIndex = value.length - 1;
  2770. }
  2771. return null;
  2772. };
  2773. this.$findClosingBracket = function(bracket, position, typeRe) {
  2774. var closingBracket = this.$brackets[bracket];
  2775. var depth = 1;
  2776. var iterator = new TokenIterator(this, position.row, position.column);
  2777. var token = iterator.getCurrentToken();
  2778. if (!token)
  2779. token = iterator.stepForward();
  2780. if (!token)
  2781. return;
  2782. if (!typeRe){
  2783. typeRe = new RegExp(
  2784. "(\\.?" +
  2785. token.type.replace(".", "\\.").replace("lparen", ".paren")
  2786. + ")+"
  2787. );
  2788. }
  2789. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  2790. while (true) {
  2791. var value = token.value;
  2792. var valueLength = value.length;
  2793. while (valueIndex < valueLength) {
  2794. var chr = value.charAt(valueIndex);
  2795. if (chr == closingBracket) {
  2796. depth -= 1;
  2797. if (depth == 0) {
  2798. return {row: iterator.getCurrentTokenRow(),
  2799. column: valueIndex + iterator.getCurrentTokenColumn()};
  2800. }
  2801. }
  2802. else if (chr == bracket) {
  2803. depth += 1;
  2804. }
  2805. valueIndex += 1;
  2806. }
  2807. do {
  2808. token = iterator.stepForward();
  2809. } while (token && !typeRe.test(token.type));
  2810. if (token == null)
  2811. break;
  2812. valueIndex = 0;
  2813. }
  2814. return null;
  2815. };
  2816. }
  2817. exports.BracketMatch = BracketMatch;
  2818. });
  2819. ace.define('ace/selection', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/lib/event_emitter', 'ace/range'], function(require, exports, module) {
  2820. var oop = require("./lib/oop");
  2821. var lang = require("./lib/lang");
  2822. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  2823. var Range = require("./range").Range;
  2824. var Selection = function(session) {
  2825. this.session = session;
  2826. this.doc = session.getDocument();
  2827. this.clearSelection();
  2828. this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
  2829. this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
  2830. var self = this;
  2831. this.lead.on("change", function(e) {
  2832. self._emit("changeCursor");
  2833. if (!self.$isEmpty)
  2834. self._emit("changeSelection");
  2835. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  2836. self.$desiredColumn = null;
  2837. });
  2838. this.selectionAnchor.on("change", function() {
  2839. if (!self.$isEmpty)
  2840. self._emit("changeSelection");
  2841. });
  2842. };
  2843. (function() {
  2844. oop.implement(this, EventEmitter);
  2845. this.isEmpty = function() {
  2846. return (this.$isEmpty || (
  2847. this.anchor.row == this.lead.row &&
  2848. this.anchor.column == this.lead.column
  2849. ));
  2850. };
  2851. this.isMultiLine = function() {
  2852. if (this.isEmpty()) {
  2853. return false;
  2854. }
  2855. return this.getRange().isMultiLine();
  2856. };
  2857. this.getCursor = function() {
  2858. return this.lead.getPosition();
  2859. };
  2860. this.setSelectionAnchor = function(row, column) {
  2861. this.anchor.setPosition(row, column);
  2862. if (this.$isEmpty) {
  2863. this.$isEmpty = false;
  2864. this._emit("changeSelection");
  2865. }
  2866. };
  2867. this.getSelectionAnchor = function() {
  2868. if (this.$isEmpty)
  2869. return this.getSelectionLead()
  2870. else
  2871. return this.anchor.getPosition();
  2872. };
  2873. this.getSelectionLead = function() {
  2874. return this.lead.getPosition();
  2875. };
  2876. this.shiftSelection = function(columns) {
  2877. if (this.$isEmpty) {
  2878. this.moveCursorTo(this.lead.row, this.lead.column + columns);
  2879. return;
  2880. };
  2881. var anchor = this.getSelectionAnchor();
  2882. var lead = this.getSelectionLead();
  2883. var isBackwards = this.isBackwards();
  2884. if (!isBackwards || anchor.column !== 0)
  2885. this.setSelectionAnchor(anchor.row, anchor.column + columns);
  2886. if (isBackwards || lead.column !== 0) {
  2887. this.$moveSelection(function() {
  2888. this.moveCursorTo(lead.row, lead.column + columns);
  2889. });
  2890. }
  2891. };
  2892. this.isBackwards = function() {
  2893. var anchor = this.anchor;
  2894. var lead = this.lead;
  2895. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  2896. };
  2897. this.getRange = function() {
  2898. var anchor = this.anchor;
  2899. var lead = this.lead;
  2900. if (this.isEmpty())
  2901. return Range.fromPoints(lead, lead);
  2902. if (this.isBackwards()) {
  2903. return Range.fromPoints(lead, anchor);
  2904. }
  2905. else {
  2906. return Range.fromPoints(anchor, lead);
  2907. }
  2908. };
  2909. this.clearSelection = function() {
  2910. if (!this.$isEmpty) {
  2911. this.$isEmpty = true;
  2912. this._emit("changeSelection");
  2913. }
  2914. };
  2915. this.selectAll = function() {
  2916. var lastRow = this.doc.getLength() - 1;
  2917. this.setSelectionAnchor(0, 0);
  2918. this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
  2919. };
  2920. this.setRange =
  2921. this.setSelectionRange = function(range, reverse) {
  2922. if (reverse) {
  2923. this.setSelectionAnchor(range.end.row, range.end.column);
  2924. this.selectTo(range.start.row, range.start.column);
  2925. } else {
  2926. this.setSelectionAnchor(range.start.row, range.start.column);
  2927. this.selectTo(range.end.row, range.end.column);
  2928. }
  2929. if (this.getRange().isEmpty())
  2930. this.$isEmpty = true;
  2931. this.$desiredColumn = null;
  2932. };
  2933. this.$moveSelection = function(mover) {
  2934. var lead = this.lead;
  2935. if (this.$isEmpty)
  2936. this.setSelectionAnchor(lead.row, lead.column);
  2937. mover.call(this);
  2938. };
  2939. this.selectTo = function(row, column) {
  2940. this.$moveSelection(function() {
  2941. this.moveCursorTo(row, column);
  2942. });
  2943. };
  2944. this.selectToPosition = function(pos) {
  2945. this.$moveSelection(function() {
  2946. this.moveCursorToPosition(pos);
  2947. });
  2948. };
  2949. this.moveTo = function(row, column) {
  2950. this.clearSelection();
  2951. this.moveCursorTo(row, column);
  2952. };
  2953. this.moveToPosition = function(pos) {
  2954. this.clearSelection();
  2955. this.moveCursorToPosition(pos);
  2956. };
  2957. this.selectUp = function() {
  2958. this.$moveSelection(this.moveCursorUp);
  2959. };
  2960. this.selectDown = function() {
  2961. this.$moveSelection(this.moveCursorDown);
  2962. };
  2963. this.selectRight = function() {
  2964. this.$moveSelection(this.moveCursorRight);
  2965. };
  2966. this.selectLeft = function() {
  2967. this.$moveSelection(this.moveCursorLeft);
  2968. };
  2969. this.selectLineStart = function() {
  2970. this.$moveSelection(this.moveCursorLineStart);
  2971. };
  2972. this.selectLineEnd = function() {
  2973. this.$moveSelection(this.moveCursorLineEnd);
  2974. };
  2975. this.selectFileEnd = function() {
  2976. this.$moveSelection(this.moveCursorFileEnd);
  2977. };
  2978. this.selectFileStart = function() {
  2979. this.$moveSelection(this.moveCursorFileStart);
  2980. };
  2981. this.selectWordRight = function() {
  2982. this.$moveSelection(this.moveCursorWordRight);
  2983. };
  2984. this.selectWordLeft = function() {
  2985. this.$moveSelection(this.moveCursorWordLeft);
  2986. };
  2987. this.getWordRange = function(row, column) {
  2988. if (typeof column == "undefined") {
  2989. var cursor = row || this.lead;
  2990. row = cursor.row;
  2991. column = cursor.column;
  2992. }
  2993. return this.session.getWordRange(row, column);
  2994. };
  2995. this.selectWord = function() {
  2996. this.setSelectionRange(this.getWordRange());
  2997. };
  2998. this.selectAWord = function() {
  2999. var cursor = this.getCursor();
  3000. var range = this.session.getAWordRange(cursor.row, cursor.column);
  3001. this.setSelectionRange(range);
  3002. };
  3003. this.getLineRange = function(row, excludeLastChar) {
  3004. var rowStart = typeof row == "number" ? row : this.lead.row;
  3005. var rowEnd;
  3006. var foldLine = this.session.getFoldLine(rowStart);
  3007. if (foldLine) {
  3008. rowStart = foldLine.start.row;
  3009. rowEnd = foldLine.end.row;
  3010. } else {
  3011. rowEnd = rowStart;
  3012. }
  3013. if (excludeLastChar === true)
  3014. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  3015. else
  3016. return new Range(rowStart, 0, rowEnd + 1, 0);
  3017. };
  3018. this.selectLine = function() {
  3019. this.setSelectionRange(this.getLineRange());
  3020. };
  3021. this.moveCursorUp = function() {
  3022. this.moveCursorBy(-1, 0);
  3023. };
  3024. this.moveCursorDown = function() {
  3025. this.moveCursorBy(1, 0);
  3026. };
  3027. this.moveCursorLeft = function() {
  3028. var cursor = this.lead.getPosition(),
  3029. fold;
  3030. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  3031. this.moveCursorTo(fold.start.row, fold.start.column);
  3032. } else if (cursor.column == 0) {
  3033. if (cursor.row > 0) {
  3034. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  3035. }
  3036. }
  3037. else {
  3038. var tabSize = this.session.getTabSize();
  3039. if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column-tabSize, cursor.column).split(" ").length-1 == tabSize)
  3040. this.moveCursorBy(0, -tabSize);
  3041. else
  3042. this.moveCursorBy(0, -1);
  3043. }
  3044. };
  3045. this.moveCursorRight = function() {
  3046. var cursor = this.lead.getPosition(),
  3047. fold;
  3048. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  3049. this.moveCursorTo(fold.end.row, fold.end.column);
  3050. }
  3051. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  3052. if (this.lead.row < this.doc.getLength() - 1) {
  3053. this.moveCursorTo(this.lead.row + 1, 0);
  3054. }
  3055. }
  3056. else {
  3057. var tabSize = this.session.getTabSize();
  3058. var cursor = this.lead;
  3059. if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize)
  3060. this.moveCursorBy(0, tabSize);
  3061. else
  3062. this.moveCursorBy(0, 1);
  3063. }
  3064. };
  3065. this.moveCursorLineStart = function() {
  3066. var row = this.lead.row;
  3067. var column = this.lead.column;
  3068. var screenRow = this.session.documentToScreenRow(row, column);
  3069. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  3070. var beforeCursor = this.session.getDisplayLine(
  3071. row, null, firstColumnPosition.row,
  3072. firstColumnPosition.column
  3073. );
  3074. var leadingSpace = beforeCursor.match(/^\s*/);
  3075. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  3076. firstColumnPosition.column += leadingSpace[0].length;
  3077. this.moveCursorToPosition(firstColumnPosition);
  3078. };
  3079. this.moveCursorLineEnd = function() {
  3080. var lead = this.lead;
  3081. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  3082. if (this.lead.column == lineEnd.column) {
  3083. var line = this.session.getLine(lineEnd.row);
  3084. if (lineEnd.column == line.length) {
  3085. var textEnd = line.search(/\s+$/);
  3086. if (textEnd > 0)
  3087. lineEnd.column = textEnd;
  3088. }
  3089. }
  3090. this.moveCursorTo(lineEnd.row, lineEnd.column);
  3091. };
  3092. this.moveCursorFileEnd = function() {
  3093. var row = this.doc.getLength() - 1;
  3094. var column = this.doc.getLine(row).length;
  3095. this.moveCursorTo(row, column);
  3096. };
  3097. this.moveCursorFileStart = function() {
  3098. this.moveCursorTo(0, 0);
  3099. };
  3100. this.moveCursorLongWordRight = function() {
  3101. var row = this.lead.row;
  3102. var column = this.lead.column;
  3103. var line = this.doc.getLine(row);
  3104. var rightOfCursor = line.substring(column);
  3105. var match;
  3106. this.session.nonTokenRe.lastIndex = 0;
  3107. this.session.tokenRe.lastIndex = 0;
  3108. var fold = this.session.getFoldAt(row, column, 1);
  3109. if (fold) {
  3110. this.moveCursorTo(fold.end.row, fold.end.column);
  3111. return;
  3112. }
  3113. if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
  3114. column += this.session.nonTokenRe.lastIndex;
  3115. this.session.nonTokenRe.lastIndex = 0;
  3116. rightOfCursor = line.substring(column);
  3117. }
  3118. if (column >= line.length) {
  3119. this.moveCursorTo(row, line.length);
  3120. this.moveCursorRight();
  3121. if (row < this.doc.getLength() - 1)
  3122. this.moveCursorWordRight();
  3123. return;
  3124. }
  3125. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  3126. column += this.session.tokenRe.lastIndex;
  3127. this.session.tokenRe.lastIndex = 0;
  3128. }
  3129. this.moveCursorTo(row, column);
  3130. };
  3131. this.moveCursorLongWordLeft = function() {
  3132. var row = this.lead.row;
  3133. var column = this.lead.column;
  3134. var fold;
  3135. if (fold = this.session.getFoldAt(row, column, -1)) {
  3136. this.moveCursorTo(fold.start.row, fold.start.column);
  3137. return;
  3138. }
  3139. var str = this.session.getFoldStringAt(row, column, -1);
  3140. if (str == null) {
  3141. str = this.doc.getLine(row).substring(0, column)
  3142. }
  3143. var leftOfCursor = lang.stringReverse(str);
  3144. var match;
  3145. this.session.nonTokenRe.lastIndex = 0;
  3146. this.session.tokenRe.lastIndex = 0;
  3147. if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
  3148. column -= this.session.nonTokenRe.lastIndex;
  3149. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  3150. this.session.nonTokenRe.lastIndex = 0;
  3151. }
  3152. if (column <= 0) {
  3153. this.moveCursorTo(row, 0);
  3154. this.moveCursorLeft();
  3155. if (row > 0)
  3156. this.moveCursorWordLeft();
  3157. return;
  3158. }
  3159. if (match = this.session.tokenRe.exec(leftOfCursor)) {
  3160. column -= this.session.tokenRe.lastIndex;
  3161. this.session.tokenRe.lastIndex = 0;
  3162. }
  3163. this.moveCursorTo(row, column);
  3164. };
  3165. this.$shortWordEndIndex = function(rightOfCursor) {
  3166. var match, index = 0, ch;
  3167. var whitespaceRe = /\s/;
  3168. var tokenRe = this.session.tokenRe;
  3169. tokenRe.lastIndex = 0;
  3170. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  3171. index = this.session.tokenRe.lastIndex;
  3172. } else {
  3173. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  3174. index ++;
  3175. if (index < 1) {
  3176. tokenRe.lastIndex = 0;
  3177. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  3178. tokenRe.lastIndex = 0;
  3179. index ++;
  3180. if (whitespaceRe.test(ch)) {
  3181. if (index > 2) {
  3182. index--
  3183. break;
  3184. } else {
  3185. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  3186. index ++;
  3187. if (index > 2)
  3188. break
  3189. }
  3190. }
  3191. }
  3192. }
  3193. }
  3194. tokenRe.lastIndex = 0;
  3195. return index;
  3196. };
  3197. this.moveCursorShortWordRight = function() {
  3198. var row = this.lead.row;
  3199. var column = this.lead.column;
  3200. var line = this.doc.getLine(row);
  3201. var rightOfCursor = line.substring(column);
  3202. var fold = this.session.getFoldAt(row, column, 1);
  3203. if (fold)
  3204. return this.moveCursorTo(fold.end.row, fold.end.column);
  3205. if (column == line.length) {
  3206. var l = this.doc.getLength();
  3207. do {
  3208. row++;
  3209. rightOfCursor = this.doc.getLine(row)
  3210. } while (row < l && /^\s*$/.test(rightOfCursor))
  3211. if (!/^\s+/.test(rightOfCursor))
  3212. rightOfCursor = ""
  3213. column = 0;
  3214. }
  3215. var index = this.$shortWordEndIndex(rightOfCursor);
  3216. this.moveCursorTo(row, column + index);
  3217. };
  3218. this.moveCursorShortWordLeft = function() {
  3219. var row = this.lead.row;
  3220. var column = this.lead.column;
  3221. var fold;
  3222. if (fold = this.session.getFoldAt(row, column, -1))
  3223. return this.moveCursorTo(fold.start.row, fold.start.column);
  3224. var line = this.session.getLine(row).substring(0, column);
  3225. if (column == 0) {
  3226. do {
  3227. row--;
  3228. line = this.doc.getLine(row);
  3229. } while (row > 0 && /^\s*$/.test(line))
  3230. column = line.length;
  3231. if (!/\s+$/.test(line))
  3232. line = ""
  3233. }
  3234. var leftOfCursor = lang.stringReverse(line);
  3235. var index = this.$shortWordEndIndex(leftOfCursor);
  3236. return this.moveCursorTo(row, column - index);
  3237. };
  3238. this.moveCursorWordRight = function() {
  3239. if (this.session.$selectLongWords)
  3240. this.moveCursorLongWordRight();
  3241. else
  3242. this.moveCursorShortWordRight();
  3243. };
  3244. this.moveCursorWordLeft = function() {
  3245. if (this.session.$selectLongWords)
  3246. this.moveCursorLongWordLeft();
  3247. else
  3248. this.moveCursorShortWordLeft();
  3249. };
  3250. this.moveCursorBy = function(rows, chars) {
  3251. var screenPos = this.session.documentToScreenPosition(
  3252. this.lead.row,
  3253. this.lead.column
  3254. );
  3255. if (chars === 0) {
  3256. if (this.$desiredColumn)
  3257. screenPos.column = this.$desiredColumn;
  3258. else
  3259. this.$desiredColumn = screenPos.column;
  3260. }
  3261. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
  3262. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  3263. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row])
  3264. docPos.row++;
  3265. }
  3266. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  3267. };
  3268. this.moveCursorToPosition = function(position) {
  3269. this.moveCursorTo(position.row, position.column);
  3270. };
  3271. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  3272. var fold = this.session.getFoldAt(row, column, 1);
  3273. if (fold) {
  3274. row = fold.start.row;
  3275. column = fold.start.column;
  3276. }
  3277. this.$keepDesiredColumnOnChange = true;
  3278. this.lead.setPosition(row, column);
  3279. this.$keepDesiredColumnOnChange = false;
  3280. if (!keepDesiredColumn)
  3281. this.$desiredColumn = null;
  3282. };
  3283. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  3284. var pos = this.session.screenToDocumentPosition(row, column);
  3285. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  3286. };
  3287. this.detach = function() {
  3288. this.lead.detach();
  3289. this.anchor.detach();
  3290. this.session = this.doc = null;
  3291. }
  3292. this.fromOrientedRange = function(range) {
  3293. this.setSelectionRange(range, range.cursor == range.start);
  3294. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  3295. }
  3296. this.toOrientedRange = function(range) {
  3297. var r = this.getRange();
  3298. if (range) {
  3299. range.start.column = r.start.column;
  3300. range.start.row = r.start.row;
  3301. range.end.column = r.end.column;
  3302. range.end.row = r.end.row;
  3303. } else {
  3304. range = r;
  3305. }
  3306. range.cursor = this.isBackwards() ? range.start : range.end;
  3307. range.desiredColumn = this.$desiredColumn;
  3308. return range;
  3309. }
  3310. this.getRangeOfMovements = function(func) {
  3311. var start = this.getCursor();
  3312. try {
  3313. func.call(null, this);
  3314. var end = this.getCursor();
  3315. return Range.fromPoints(start,end);
  3316. } catch(e) {
  3317. return Range.fromPoints(start,start);
  3318. } finally {
  3319. this.moveCursorToPosition(start);
  3320. }
  3321. }
  3322. this.toJSON = function() {
  3323. if (this.rangeCount) {
  3324. var data = this.ranges.map(function(r) {
  3325. var r1 = r.clone();
  3326. r1.isBackwards = r.cursor == r.start;
  3327. return r1;
  3328. });
  3329. } else {
  3330. var data = this.getRange();
  3331. data.isBackwards = this.isBackwards();
  3332. }
  3333. return data;
  3334. };
  3335. this.fromJSON = function(data) {
  3336. if (data.start == undefined) {
  3337. if (this.rangeList) {
  3338. this.toSingleRange(data[0]);
  3339. for (var i = data.length; i--; ) {
  3340. var r = Range.fromPoints(data[i].start, data[i].end);
  3341. if (data.isBackwards)
  3342. r.cursor = r.start;
  3343. this.addRange(r, true);
  3344. }
  3345. return;
  3346. } else
  3347. data = data[0];
  3348. }
  3349. if (this.rangeList)
  3350. this.toSingleRange(data);
  3351. this.setSelectionRange(data, data.isBackwards);
  3352. };
  3353. this.isEqual = function(data) {
  3354. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  3355. return false;
  3356. if (!data.length || !this.ranges)
  3357. return this.getRange().isEqual(data);
  3358. for (var i = this.ranges.length; i--; ) {
  3359. if (!this.ranges[i].isEqual(data[i]))
  3360. return false
  3361. }
  3362. return true;
  3363. }
  3364. }).call(Selection.prototype);
  3365. exports.Selection = Selection;
  3366. });
  3367. ace.define('ace/search', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/lib/oop', 'ace/range'], function(require, exports, module) {
  3368. var lang = require("./lib/lang");
  3369. var oop = require("./lib/oop");
  3370. var Range = require("./range").Range;
  3371. var Search = function() {
  3372. this.$options = {};
  3373. };
  3374. (function() {
  3375. this.set = function(options) {
  3376. oop.mixin(this.$options, options);
  3377. return this;
  3378. };
  3379. this.getOptions = function() {
  3380. return lang.copyObject(this.$options);
  3381. };
  3382. this.setOptions = function(options) {
  3383. this.$options = options;
  3384. };
  3385. this.find = function(session) {
  3386. var iterator = this.$matchIterator(session, this.$options);
  3387. if (!iterator)
  3388. return false;
  3389. var firstRange = null;
  3390. iterator.forEach(function(range, row, offset) {
  3391. if (!range.start) {
  3392. var column = range.offset + (offset || 0);
  3393. firstRange = new Range(row, column, row, column+range.length);
  3394. } else
  3395. firstRange = range;
  3396. return true;
  3397. });
  3398. return firstRange;
  3399. };
  3400. this.findAll = function(session) {
  3401. var options = this.$options;
  3402. if (!options.needle)
  3403. return [];
  3404. this.$assembleRegExp(options);
  3405. var range = options.range;
  3406. var lines = range
  3407. ? session.getLines(range.start.row, range.end.row)
  3408. : session.doc.getAllLines();
  3409. var ranges = [];
  3410. var re = options.re;
  3411. if (options.$isMultiLine) {
  3412. var len = re.length;
  3413. var maxRow = lines.length - len;
  3414. var prevRange;
  3415. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  3416. for (var j = 0; j < len; j++)
  3417. if (lines[row + j].search(re[j]) == -1)
  3418. continue outer;
  3419. var startLine = lines[row];
  3420. var line = lines[row + len - 1];
  3421. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  3422. var endIndex = line.match(re[len - 1])[0].length;
  3423. if (prevRange && prevRange.end.row === row &&
  3424. prevRange.end.column > startIndex
  3425. ) {
  3426. continue;
  3427. }
  3428. ranges.push(prevRange = new Range(
  3429. row, startIndex, row + len - 1, endIndex
  3430. ));
  3431. if (len > 2)
  3432. row = row + len - 2;
  3433. }
  3434. } else {
  3435. for (var i = 0; i < lines.length; i++) {
  3436. var matches = lang.getMatchOffsets(lines[i], re);
  3437. for (var j = 0; j < matches.length; j++) {
  3438. var match = matches[j];
  3439. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  3440. }
  3441. }
  3442. }
  3443. if (range) {
  3444. var startColumn = range.start.column;
  3445. var endColumn = range.start.column;
  3446. var i = 0, j = ranges.length - 1;
  3447. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  3448. i++;
  3449. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  3450. j--;
  3451. ranges = ranges.slice(i, j + 1);
  3452. for (i = 0, j = ranges.length; i < j; i++) {
  3453. ranges[i].start.row += range.start.row;
  3454. ranges[i].end.row += range.start.row;
  3455. }
  3456. }
  3457. return ranges;
  3458. };
  3459. this.replace = function(input, replacement) {
  3460. var options = this.$options;
  3461. var re = this.$assembleRegExp(options);
  3462. if (options.$isMultiLine)
  3463. return replacement;
  3464. if (!re)
  3465. return;
  3466. var match = re.exec(input);
  3467. if (!match || match[0].length != input.length)
  3468. return null;
  3469. replacement = input.replace(re, replacement);
  3470. if (options.preserveCase) {
  3471. replacement = replacement.split("");
  3472. for (var i = Math.min(input.length, input.length); i--; ) {
  3473. var ch = input[i];
  3474. if (ch && ch.toLowerCase() != ch)
  3475. replacement[i] = replacement[i].toUpperCase();
  3476. else
  3477. replacement[i] = replacement[i].toLowerCase();
  3478. }
  3479. replacement = replacement.join("");
  3480. }
  3481. return replacement;
  3482. };
  3483. this.$matchIterator = function(session, options) {
  3484. var re = this.$assembleRegExp(options);
  3485. if (!re)
  3486. return false;
  3487. var self = this, callback, backwards = options.backwards;
  3488. if (options.$isMultiLine) {
  3489. var len = re.length;
  3490. var matchIterator = function(line, row, offset) {
  3491. var startIndex = line.search(re[0]);
  3492. if (startIndex == -1)
  3493. return;
  3494. for (var i = 1; i < len; i++) {
  3495. line = session.getLine(row + i);
  3496. if (line.search(re[i]) == -1)
  3497. return;
  3498. }
  3499. var endIndex = line.match(re[len - 1])[0].length;
  3500. var range = new Range(row, startIndex, row + len - 1, endIndex);
  3501. if (re.offset == 1) {
  3502. range.start.row--;
  3503. range.start.column = Number.MAX_VALUE;
  3504. } else if (offset)
  3505. range.start.column += offset;
  3506. if (callback(range))
  3507. return true;
  3508. };
  3509. } else if (backwards) {
  3510. var matchIterator = function(line, row, startIndex) {
  3511. var matches = lang.getMatchOffsets(line, re);
  3512. for (var i = matches.length-1; i >= 0; i--)
  3513. if (callback(matches[i], row, startIndex))
  3514. return true;
  3515. };
  3516. } else {
  3517. var matchIterator = function(line, row, startIndex) {
  3518. var matches = lang.getMatchOffsets(line, re);
  3519. for (var i = 0; i < matches.length; i++)
  3520. if (callback(matches[i], row, startIndex))
  3521. return true;
  3522. };
  3523. }
  3524. return {
  3525. forEach: function(_callback) {
  3526. callback = _callback;
  3527. self.$lineIterator(session, options).forEach(matchIterator);
  3528. }
  3529. };
  3530. };
  3531. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  3532. if (options.needle instanceof RegExp)
  3533. return options.re = options.needle;
  3534. var needle = options.needle;
  3535. if (!options.needle)
  3536. return options.re = false;
  3537. if (!options.regExp)
  3538. needle = lang.escapeRegExp(needle);
  3539. if (options.wholeWord)
  3540. needle = "\\b" + needle + "\\b";
  3541. var modifier = options.caseSensitive ? "g" : "gi";
  3542. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  3543. if (options.$isMultiLine)
  3544. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  3545. try {
  3546. var re = new RegExp(needle, modifier);
  3547. } catch(e) {
  3548. re = false;
  3549. }
  3550. return options.re = re;
  3551. };
  3552. this.$assembleMultilineRegExp = function(needle, modifier) {
  3553. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  3554. var re = [];
  3555. for (var i = 0; i < parts.length; i++) try {
  3556. re.push(new RegExp(parts[i], modifier));
  3557. } catch(e) {
  3558. return false;
  3559. }
  3560. if (parts[0] == "") {
  3561. re.shift();
  3562. re.offset = 1;
  3563. } else {
  3564. re.offset = 0;
  3565. }
  3566. return re;
  3567. };
  3568. this.$lineIterator = function(session, options) {
  3569. var backwards = options.backwards == true;
  3570. var skipCurrent = options.skipCurrent != false;
  3571. var range = options.range;
  3572. var start = options.start;
  3573. if (!start)
  3574. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  3575. if (start.start)
  3576. start = start[skipCurrent != backwards ? "end" : "start"];
  3577. var firstRow = range ? range.start.row : 0;
  3578. var lastRow = range ? range.end.row : session.getLength() - 1;
  3579. var forEach = backwards ? function(callback) {
  3580. var row = start.row;
  3581. var line = session.getLine(row).substring(0, start.column);
  3582. if (callback(line, row))
  3583. return;
  3584. for (row--; row >= firstRow; row--)
  3585. if (callback(session.getLine(row), row))
  3586. return;
  3587. if (options.wrap == false)
  3588. return;
  3589. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  3590. if (callback(session.getLine(row), row))
  3591. return;
  3592. } : function(callback) {
  3593. var row = start.row;
  3594. var line = session.getLine(row).substr(start.column);
  3595. if (callback(line, row, start.column))
  3596. return;
  3597. for (row = row+1; row <= lastRow; row++)
  3598. if (callback(session.getLine(row), row))
  3599. return;
  3600. if (options.wrap == false)
  3601. return;
  3602. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  3603. if (callback(session.getLine(row), row))
  3604. return;
  3605. };
  3606. return {forEach: forEach};
  3607. };
  3608. }).call(Search.prototype);
  3609. exports.Search = Search;
  3610. });
  3611. ace.define('ace/edit_session', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/config', 'ace/lib/event_emitter', 'ace/selection', 'ace/mode/text', 'ace/range', 'ace/document', 'ace/background_tokenizer', 'ace/search_highlight', 'ace/edit_session/folding', 'ace/edit_session/bracket_match'], function(require, exports, module) {
  3612. var oop = require("./lib/oop");
  3613. var lang = require("./lib/lang");
  3614. var config = require("./config");
  3615. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  3616. var Selection = require("./selection").Selection;
  3617. var TextMode = require("./mode/text").Mode;
  3618. var Range = require("./range").Range;
  3619. var Document = require("./document").Document;
  3620. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  3621. var SearchHighlight = require("./search_highlight").SearchHighlight;
  3622. var EditSession = function(text, mode) {
  3623. this.$breakpoints = [];
  3624. this.$decorations = [];
  3625. this.$frontMarkers = {};
  3626. this.$backMarkers = {};
  3627. this.$markerId = 1;
  3628. this.$undoSelect = true;
  3629. this.$foldData = [];
  3630. this.$foldData.toString = function() {
  3631. return this.join("\n");
  3632. }
  3633. this.on("changeFold", this.onChangeFold.bind(this));
  3634. this.$onChange = this.onChange.bind(this);
  3635. if (typeof text != "object" || !text.getLine)
  3636. text = new Document(text);
  3637. this.setDocument(text);
  3638. this.selection = new Selection(this);
  3639. config.resetOptions(this);
  3640. this.setMode(mode);
  3641. config._signal("session", this);
  3642. };
  3643. (function() {
  3644. oop.implement(this, EventEmitter);
  3645. this.setDocument = function(doc) {
  3646. if (this.doc)
  3647. this.doc.removeListener("change", this.$onChange);
  3648. this.doc = doc;
  3649. doc.on("change", this.$onChange);
  3650. if (this.bgTokenizer)
  3651. this.bgTokenizer.setDocument(this.getDocument());
  3652. this.resetCaches();
  3653. };
  3654. this.getDocument = function() {
  3655. return this.doc;
  3656. };
  3657. this.$resetRowCache = function(docRow) {
  3658. if (!docRow) {
  3659. this.$docRowCache = [];
  3660. this.$screenRowCache = [];
  3661. return;
  3662. }
  3663. var l = this.$docRowCache.length;
  3664. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  3665. if (l > i) {
  3666. this.$docRowCache.splice(i, l);
  3667. this.$screenRowCache.splice(i, l);
  3668. }
  3669. };
  3670. this.$getRowCacheIndex = function(cacheArray, val) {
  3671. var low = 0;
  3672. var hi = cacheArray.length - 1;
  3673. while (low <= hi) {
  3674. var mid = (low + hi) >> 1;
  3675. var c = cacheArray[mid];
  3676. if (val > c)
  3677. low = mid + 1;
  3678. else if (val < c)
  3679. hi = mid - 1;
  3680. else
  3681. return mid;
  3682. }
  3683. return low -1;
  3684. };
  3685. this.resetCaches = function() {
  3686. this.$modified = true;
  3687. this.$wrapData = [];
  3688. this.$rowLengthCache = [];
  3689. this.$resetRowCache(0);
  3690. if (this.bgTokenizer)
  3691. this.bgTokenizer.start(0);
  3692. };
  3693. this.onChangeFold = function(e) {
  3694. var fold = e.data;
  3695. this.$resetRowCache(fold.start.row);
  3696. };
  3697. this.onChange = function(e) {
  3698. var delta = e.data;
  3699. this.$modified = true;
  3700. this.$resetRowCache(delta.range.start.row);
  3701. var removedFolds = this.$updateInternalDataOnChange(e);
  3702. if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
  3703. this.$deltasDoc.push(delta);
  3704. if (removedFolds && removedFolds.length != 0) {
  3705. this.$deltasFold.push({
  3706. action: "removeFolds",
  3707. folds: removedFolds
  3708. });
  3709. }
  3710. this.$informUndoManager.schedule();
  3711. }
  3712. this.bgTokenizer.$updateOnChange(delta);
  3713. this._signal("change", e);
  3714. };
  3715. this.setValue = function(text) {
  3716. this.doc.setValue(text);
  3717. this.selection.moveTo(0, 0);
  3718. this.$resetRowCache(0);
  3719. this.$deltas = [];
  3720. this.$deltasDoc = [];
  3721. this.$deltasFold = [];
  3722. this.setUndoManager(this.$undoManager);
  3723. this.getUndoManager().reset();
  3724. };
  3725. this.getValue =
  3726. this.toString = function() {
  3727. return this.doc.getValue();
  3728. };
  3729. this.getSelection = function() {
  3730. return this.selection;
  3731. };
  3732. this.getState = function(row) {
  3733. return this.bgTokenizer.getState(row);
  3734. };
  3735. this.getTokens = function(row) {
  3736. return this.bgTokenizer.getTokens(row);
  3737. };
  3738. this.getTokenAt = function(row, column) {
  3739. var tokens = this.bgTokenizer.getTokens(row);
  3740. var token, c = 0;
  3741. if (column == null) {
  3742. i = tokens.length - 1;
  3743. c = this.getLine(row).length;
  3744. } else {
  3745. for (var i = 0; i < tokens.length; i++) {
  3746. c += tokens[i].value.length;
  3747. if (c >= column)
  3748. break;
  3749. }
  3750. }
  3751. token = tokens[i];
  3752. if (!token)
  3753. return null;
  3754. token.index = i;
  3755. token.start = c - token.value.length;
  3756. return token;
  3757. };
  3758. this.setUndoManager = function(undoManager) {
  3759. this.$undoManager = undoManager;
  3760. this.$deltas = [];
  3761. this.$deltasDoc = [];
  3762. this.$deltasFold = [];
  3763. if (this.$informUndoManager)
  3764. this.$informUndoManager.cancel();
  3765. if (undoManager) {
  3766. var self = this;
  3767. this.$syncInformUndoManager = function() {
  3768. self.$informUndoManager.cancel();
  3769. if (self.$deltasFold.length) {
  3770. self.$deltas.push({
  3771. group: "fold",
  3772. deltas: self.$deltasFold
  3773. });
  3774. self.$deltasFold = [];
  3775. }
  3776. if (self.$deltasDoc.length) {
  3777. self.$deltas.push({
  3778. group: "doc",
  3779. deltas: self.$deltasDoc
  3780. });
  3781. self.$deltasDoc = [];
  3782. }
  3783. if (self.$deltas.length > 0) {
  3784. undoManager.execute({
  3785. action: "aceupdate",
  3786. args: [self.$deltas, self],
  3787. merge: self.mergeUndoDeltas
  3788. });
  3789. }
  3790. self.mergeUndoDeltas = false;
  3791. self.$deltas = [];
  3792. };
  3793. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  3794. }
  3795. };
  3796. this.markUndoGroup = function() {
  3797. if (this.$syncInformUndoManager)
  3798. this.$syncInformUndoManager();
  3799. };
  3800. this.$defaultUndoManager = {
  3801. undo: function() {},
  3802. redo: function() {},
  3803. reset: function() {}
  3804. };
  3805. this.getUndoManager = function() {
  3806. return this.$undoManager || this.$defaultUndoManager;
  3807. };
  3808. this.getTabString = function() {
  3809. if (this.getUseSoftTabs()) {
  3810. return lang.stringRepeat(" ", this.getTabSize());
  3811. } else {
  3812. return "\t";
  3813. }
  3814. };
  3815. this.setUseSoftTabs = function(val) {
  3816. this.setOption("useSoftTabs", val);
  3817. };
  3818. this.getUseSoftTabs = function() {
  3819. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  3820. };
  3821. this.setTabSize = function(tabSize) {
  3822. this.setOption("tabSize", tabSize);
  3823. };
  3824. this.getTabSize = function() {
  3825. return this.$tabSize;
  3826. };
  3827. this.isTabStop = function(position) {
  3828. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  3829. };
  3830. this.$overwrite = false;
  3831. this.setOverwrite = function(overwrite) {
  3832. this.setOption("overwrite", overwrite);
  3833. };
  3834. this.getOverwrite = function() {
  3835. return this.$overwrite;
  3836. };
  3837. this.toggleOverwrite = function() {
  3838. this.setOverwrite(!this.$overwrite);
  3839. };
  3840. this.addGutterDecoration = function(row, className) {
  3841. if (!this.$decorations[row])
  3842. this.$decorations[row] = "";
  3843. this.$decorations[row] += " " + className;
  3844. this._signal("changeBreakpoint", {});
  3845. };
  3846. this.removeGutterDecoration = function(row, className) {
  3847. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  3848. this._signal("changeBreakpoint", {});
  3849. };
  3850. this.getBreakpoints = function() {
  3851. return this.$breakpoints;
  3852. };
  3853. this.setBreakpoints = function(rows) {
  3854. this.$breakpoints = [];
  3855. for (var i=0; i<rows.length; i++) {
  3856. this.$breakpoints[rows[i]] = "ace_breakpoint";
  3857. }
  3858. this._signal("changeBreakpoint", {});
  3859. };
  3860. this.clearBreakpoints = function() {
  3861. this.$breakpoints = [];
  3862. this._signal("changeBreakpoint", {});
  3863. };
  3864. this.setBreakpoint = function(row, className) {
  3865. if (className === undefined)
  3866. className = "ace_breakpoint";
  3867. if (className)
  3868. this.$breakpoints[row] = className;
  3869. else
  3870. delete this.$breakpoints[row];
  3871. this._signal("changeBreakpoint", {});
  3872. };
  3873. this.clearBreakpoint = function(row) {
  3874. delete this.$breakpoints[row];
  3875. this._signal("changeBreakpoint", {});
  3876. };
  3877. this.addMarker = function(range, clazz, type, inFront) {
  3878. var id = this.$markerId++;
  3879. var marker = {
  3880. range : range,
  3881. type : type || "line",
  3882. renderer: typeof type == "function" ? type : null,
  3883. clazz : clazz,
  3884. inFront: !!inFront,
  3885. id: id
  3886. };
  3887. if (inFront) {
  3888. this.$frontMarkers[id] = marker;
  3889. this._signal("changeFrontMarker");
  3890. } else {
  3891. this.$backMarkers[id] = marker;
  3892. this._signal("changeBackMarker");
  3893. }
  3894. return id;
  3895. };
  3896. this.addDynamicMarker = function(marker, inFront) {
  3897. if (!marker.update)
  3898. return;
  3899. var id = this.$markerId++;
  3900. marker.id = id;
  3901. marker.inFront = !!inFront;
  3902. if (inFront) {
  3903. this.$frontMarkers[id] = marker;
  3904. this._signal("changeFrontMarker");
  3905. } else {
  3906. this.$backMarkers[id] = marker;
  3907. this._signal("changeBackMarker");
  3908. }
  3909. return marker;
  3910. };
  3911. this.removeMarker = function(markerId) {
  3912. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  3913. if (!marker)
  3914. return;
  3915. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  3916. if (marker) {
  3917. delete (markers[markerId]);
  3918. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  3919. }
  3920. };
  3921. this.getMarkers = function(inFront) {
  3922. return inFront ? this.$frontMarkers : this.$backMarkers;
  3923. };
  3924. this.highlight = function(re) {
  3925. if (!this.$searchHighlight) {
  3926. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  3927. this.$searchHighlight = this.addDynamicMarker(highlight);
  3928. }
  3929. this.$searchHighlight.setRegexp(re);
  3930. };
  3931. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  3932. if (typeof endRow != "number") {
  3933. clazz = endRow;
  3934. endRow = startRow;
  3935. }
  3936. if (!clazz)
  3937. clazz = "ace_step";
  3938. var range = new Range(startRow, 0, endRow, Infinity);
  3939. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  3940. return range;
  3941. };
  3942. this.setAnnotations = function(annotations) {
  3943. this.$annotations = annotations;
  3944. this._signal("changeAnnotation", {});
  3945. };
  3946. this.getAnnotations = function() {
  3947. return this.$annotations || [];
  3948. };
  3949. this.clearAnnotations = function() {
  3950. this.setAnnotations([]);
  3951. };
  3952. this.$detectNewLine = function(text) {
  3953. var match = text.match(/^.*?(\r?\n)/m);
  3954. if (match) {
  3955. this.$autoNewLine = match[1];
  3956. } else {
  3957. this.$autoNewLine = "\n";
  3958. }
  3959. };
  3960. this.getWordRange = function(row, column) {
  3961. var line = this.getLine(row);
  3962. var inToken = false;
  3963. if (column > 0)
  3964. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  3965. if (!inToken)
  3966. inToken = !!line.charAt(column).match(this.tokenRe);
  3967. if (inToken)
  3968. var re = this.tokenRe;
  3969. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  3970. var re = /\s/;
  3971. else
  3972. var re = this.nonTokenRe;
  3973. var start = column;
  3974. if (start > 0) {
  3975. do {
  3976. start--;
  3977. }
  3978. while (start >= 0 && line.charAt(start).match(re));
  3979. start++;
  3980. }
  3981. var end = column;
  3982. while (end < line.length && line.charAt(end).match(re)) {
  3983. end++;
  3984. }
  3985. return new Range(row, start, row, end);
  3986. };
  3987. this.getAWordRange = function(row, column) {
  3988. var wordRange = this.getWordRange(row, column);
  3989. var line = this.getLine(wordRange.end.row);
  3990. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  3991. wordRange.end.column += 1;
  3992. }
  3993. return wordRange;
  3994. };
  3995. this.setNewLineMode = function(newLineMode) {
  3996. this.doc.setNewLineMode(newLineMode);
  3997. };
  3998. this.getNewLineMode = function() {
  3999. return this.doc.getNewLineMode();
  4000. };
  4001. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  4002. this.getUseWorker = function() { return this.$useWorker; };
  4003. this.onReloadTokenizer = function(e) {
  4004. var rows = e.data;
  4005. this.bgTokenizer.start(rows.first);
  4006. this._signal("tokenizerUpdate", e);
  4007. };
  4008. this.$modes = {};
  4009. this.$mode = null;
  4010. this.$modeId = null;
  4011. this.setMode = function(mode, cb) {
  4012. if (mode && typeof mode === "object") {
  4013. if (mode.getTokenizer)
  4014. return this.$onChangeMode(mode);
  4015. var options = mode;
  4016. var path = options.path;
  4017. } else {
  4018. path = mode || "ace/mode/text";
  4019. }
  4020. if (!this.$modes["ace/mode/text"])
  4021. this.$modes["ace/mode/text"] = new TextMode();
  4022. if (this.$modes[path] && !options) {
  4023. this.$onChangeMode(this.$modes[path]);
  4024. cb && cb();
  4025. return;
  4026. }
  4027. this.$modeId = path;
  4028. config.loadModule(["mode", path], function(m) {
  4029. if (this.$modeId !== path)
  4030. return cb && cb();
  4031. if (this.$modes[path] && !options)
  4032. return this.$onChangeMode(this.$modes[path]);
  4033. if (m && m.Mode) {
  4034. m = new m.Mode(options);
  4035. if (!options) {
  4036. this.$modes[path] = m;
  4037. m.$id = path;
  4038. }
  4039. this.$onChangeMode(m);
  4040. cb && cb();
  4041. }
  4042. }.bind(this));
  4043. if (!this.$mode)
  4044. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  4045. };
  4046. this.$onChangeMode = function(mode, $isPlaceholder) {
  4047. if (!$isPlaceholder)
  4048. this.$modeId = mode.$id;
  4049. if (this.$mode === mode)
  4050. return;
  4051. this.$mode = mode;
  4052. this.$stopWorker();
  4053. if (this.$useWorker)
  4054. this.$startWorker();
  4055. var tokenizer = mode.getTokenizer();
  4056. if(tokenizer.addEventListener !== undefined) {
  4057. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  4058. tokenizer.addEventListener("update", onReloadTokenizer);
  4059. }
  4060. if (!this.bgTokenizer) {
  4061. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  4062. var _self = this;
  4063. this.bgTokenizer.addEventListener("update", function(e) {
  4064. _self._signal("tokenizerUpdate", e);
  4065. });
  4066. } else {
  4067. this.bgTokenizer.setTokenizer(tokenizer);
  4068. }
  4069. this.bgTokenizer.setDocument(this.getDocument());
  4070. this.tokenRe = mode.tokenRe;
  4071. this.nonTokenRe = mode.nonTokenRe;
  4072. if (!$isPlaceholder) {
  4073. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  4074. this.$setFolding(mode.foldingRules);
  4075. this.bgTokenizer.start(0);
  4076. this._emit("changeMode");
  4077. }
  4078. };
  4079. this.$stopWorker = function() {
  4080. if (this.$worker)
  4081. this.$worker.terminate();
  4082. this.$worker = null;
  4083. };
  4084. this.$startWorker = function() {
  4085. if (typeof Worker !== "undefined" && !require.noWorker) {
  4086. try {
  4087. this.$worker = this.$mode.createWorker(this);
  4088. } catch (e) {
  4089. console.log("Could not load worker");
  4090. console.log(e);
  4091. this.$worker = null;
  4092. }
  4093. }
  4094. else
  4095. this.$worker = null;
  4096. };
  4097. this.getMode = function() {
  4098. return this.$mode;
  4099. };
  4100. this.$scrollTop = 0;
  4101. this.setScrollTop = function(scrollTop) {
  4102. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  4103. return;
  4104. this.$scrollTop = scrollTop;
  4105. this._signal("changeScrollTop", scrollTop);
  4106. };
  4107. this.getScrollTop = function() {
  4108. return this.$scrollTop;
  4109. };
  4110. this.$scrollLeft = 0;
  4111. this.setScrollLeft = function(scrollLeft) {
  4112. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  4113. return;
  4114. this.$scrollLeft = scrollLeft;
  4115. this._signal("changeScrollLeft", scrollLeft);
  4116. };
  4117. this.getScrollLeft = function() {
  4118. return this.$scrollLeft;
  4119. };
  4120. this.getScreenWidth = function() {
  4121. this.$computeWidth();
  4122. if (this.lineWidgets)
  4123. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  4124. return this.screenWidth;
  4125. };
  4126. this.getLineWidgetMaxWidth = function() {
  4127. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  4128. var width = 0;
  4129. this.lineWidgets.forEach(function(w) {
  4130. if (w && w.screenWidth > width)
  4131. width = w.screenWidth;
  4132. });
  4133. return this.lineWidgetWidth = width;
  4134. };
  4135. this.$computeWidth = function(force) {
  4136. if (this.$modified || force) {
  4137. this.$modified = false;
  4138. if (this.$useWrapMode)
  4139. return this.screenWidth = this.$wrapLimit;
  4140. var lines = this.doc.getAllLines();
  4141. var cache = this.$rowLengthCache;
  4142. var longestScreenLine = 0;
  4143. var foldIndex = 0;
  4144. var foldLine = this.$foldData[foldIndex];
  4145. var foldStart = foldLine ? foldLine.start.row : Infinity;
  4146. var len = lines.length;
  4147. for (var i = 0; i < len; i++) {
  4148. if (i > foldStart) {
  4149. i = foldLine.end.row + 1;
  4150. if (i >= len)
  4151. break;
  4152. foldLine = this.$foldData[foldIndex++];
  4153. foldStart = foldLine ? foldLine.start.row : Infinity;
  4154. }
  4155. if (cache[i] == null)
  4156. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  4157. if (cache[i] > longestScreenLine)
  4158. longestScreenLine = cache[i];
  4159. }
  4160. this.screenWidth = longestScreenLine;
  4161. }
  4162. };
  4163. this.getLine = function(row) {
  4164. return this.doc.getLine(row);
  4165. };
  4166. this.getLines = function(firstRow, lastRow) {
  4167. return this.doc.getLines(firstRow, lastRow);
  4168. };
  4169. this.getLength = function() {
  4170. return this.doc.getLength();
  4171. };
  4172. this.getTextRange = function(range) {
  4173. return this.doc.getTextRange(range || this.selection.getRange());
  4174. };
  4175. this.insert = function(position, text) {
  4176. return this.doc.insert(position, text);
  4177. };
  4178. this.remove = function(range) {
  4179. return this.doc.remove(range);
  4180. };
  4181. this.undoChanges = function(deltas, dontSelect) {
  4182. if (!deltas.length)
  4183. return;
  4184. this.$fromUndo = true;
  4185. var lastUndoRange = null;
  4186. for (var i = deltas.length - 1; i != -1; i--) {
  4187. var delta = deltas[i];
  4188. if (delta.group == "doc") {
  4189. this.doc.revertDeltas(delta.deltas);
  4190. lastUndoRange =
  4191. this.$getUndoSelection(delta.deltas, true, lastUndoRange);
  4192. } else {
  4193. delta.deltas.forEach(function(foldDelta) {
  4194. this.addFolds(foldDelta.folds);
  4195. }, this);
  4196. }
  4197. }
  4198. this.$fromUndo = false;
  4199. lastUndoRange &&
  4200. this.$undoSelect &&
  4201. !dontSelect &&
  4202. this.selection.setSelectionRange(lastUndoRange);
  4203. return lastUndoRange;
  4204. };
  4205. this.redoChanges = function(deltas, dontSelect) {
  4206. if (!deltas.length)
  4207. return;
  4208. this.$fromUndo = true;
  4209. var lastUndoRange = null;
  4210. for (var i = 0; i < deltas.length; i++) {
  4211. var delta = deltas[i];
  4212. if (delta.group == "doc") {
  4213. this.doc.applyDeltas(delta.deltas);
  4214. lastUndoRange =
  4215. this.$getUndoSelection(delta.deltas, false, lastUndoRange);
  4216. }
  4217. }
  4218. this.$fromUndo = false;
  4219. lastUndoRange &&
  4220. this.$undoSelect &&
  4221. !dontSelect &&
  4222. this.selection.setSelectionRange(lastUndoRange);
  4223. return lastUndoRange;
  4224. };
  4225. this.setUndoSelect = function(enable) {
  4226. this.$undoSelect = enable;
  4227. };
  4228. this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
  4229. function isInsert(delta) {
  4230. var insert =
  4231. delta.action === "insertText" || delta.action === "insertLines";
  4232. return isUndo ? !insert : insert;
  4233. }
  4234. var delta = deltas[0];
  4235. var range, point;
  4236. var lastDeltaIsInsert = false;
  4237. if (isInsert(delta)) {
  4238. range = Range.fromPoints(delta.range.start, delta.range.end);
  4239. lastDeltaIsInsert = true;
  4240. } else {
  4241. range = Range.fromPoints(delta.range.start, delta.range.start);
  4242. lastDeltaIsInsert = false;
  4243. }
  4244. for (var i = 1; i < deltas.length; i++) {
  4245. delta = deltas[i];
  4246. if (isInsert(delta)) {
  4247. point = delta.range.start;
  4248. if (range.compare(point.row, point.column) == -1) {
  4249. range.setStart(delta.range.start);
  4250. }
  4251. point = delta.range.end;
  4252. if (range.compare(point.row, point.column) == 1) {
  4253. range.setEnd(delta.range.end);
  4254. }
  4255. lastDeltaIsInsert = true;
  4256. } else {
  4257. point = delta.range.start;
  4258. if (range.compare(point.row, point.column) == -1) {
  4259. range =
  4260. Range.fromPoints(delta.range.start, delta.range.start);
  4261. }
  4262. lastDeltaIsInsert = false;
  4263. }
  4264. }
  4265. if (lastUndoRange != null) {
  4266. if (Range.comparePoints(lastUndoRange.start, range.start) === 0) {
  4267. lastUndoRange.start.column += range.end.column - range.start.column;
  4268. lastUndoRange.end.column += range.end.column - range.start.column;
  4269. }
  4270. var cmp = lastUndoRange.compareRange(range);
  4271. if (cmp == 1) {
  4272. range.setStart(lastUndoRange.start);
  4273. } else if (cmp == -1) {
  4274. range.setEnd(lastUndoRange.end);
  4275. }
  4276. }
  4277. return range;
  4278. };
  4279. this.replace = function(range, text) {
  4280. return this.doc.replace(range, text);
  4281. };
  4282. this.moveText = function(fromRange, toPosition, copy) {
  4283. var text = this.getTextRange(fromRange);
  4284. var folds = this.getFoldsInRange(fromRange);
  4285. var toRange = Range.fromPoints(toPosition, toPosition);
  4286. if (!copy) {
  4287. this.remove(fromRange);
  4288. var rowDiff = fromRange.start.row - fromRange.end.row;
  4289. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  4290. if (collDiff) {
  4291. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  4292. toRange.start.column += collDiff;
  4293. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  4294. toRange.end.column += collDiff;
  4295. }
  4296. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  4297. toRange.start.row += rowDiff;
  4298. toRange.end.row += rowDiff;
  4299. }
  4300. }
  4301. toRange.end = this.insert(toRange.start, text);
  4302. if (folds.length) {
  4303. var oldStart = fromRange.start;
  4304. var newStart = toRange.start;
  4305. var rowDiff = newStart.row - oldStart.row;
  4306. var collDiff = newStart.column - oldStart.column;
  4307. this.addFolds(folds.map(function(x) {
  4308. x = x.clone();
  4309. if (x.start.row == oldStart.row)
  4310. x.start.column += collDiff;
  4311. if (x.end.row == oldStart.row)
  4312. x.end.column += collDiff;
  4313. x.start.row += rowDiff;
  4314. x.end.row += rowDiff;
  4315. return x;
  4316. }));
  4317. }
  4318. return toRange;
  4319. };
  4320. this.indentRows = function(startRow, endRow, indentString) {
  4321. indentString = indentString.replace(/\t/g, this.getTabString());
  4322. for (var row=startRow; row<=endRow; row++)
  4323. this.insert({row: row, column:0}, indentString);
  4324. };
  4325. this.outdentRows = function (range) {
  4326. var rowRange = range.collapseRows();
  4327. var deleteRange = new Range(0, 0, 0, 0);
  4328. var size = this.getTabSize();
  4329. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  4330. var line = this.getLine(i);
  4331. deleteRange.start.row = i;
  4332. deleteRange.end.row = i;
  4333. for (var j = 0; j < size; ++j)
  4334. if (line.charAt(j) != ' ')
  4335. break;
  4336. if (j < size && line.charAt(j) == '\t') {
  4337. deleteRange.start.column = j;
  4338. deleteRange.end.column = j + 1;
  4339. } else {
  4340. deleteRange.start.column = 0;
  4341. deleteRange.end.column = j;
  4342. }
  4343. this.remove(deleteRange);
  4344. }
  4345. };
  4346. this.$moveLines = function(firstRow, lastRow, dir) {
  4347. firstRow = this.getRowFoldStart(firstRow);
  4348. lastRow = this.getRowFoldEnd(lastRow);
  4349. if (dir < 0) {
  4350. var row = this.getRowFoldStart(firstRow + dir);
  4351. if (row < 0) return 0;
  4352. var diff = row-firstRow;
  4353. } else if (dir > 0) {
  4354. var row = this.getRowFoldEnd(lastRow + dir);
  4355. if (row > this.doc.getLength()-1) return 0;
  4356. var diff = row-lastRow;
  4357. } else {
  4358. firstRow = this.$clipRowToDocument(firstRow);
  4359. lastRow = this.$clipRowToDocument(lastRow);
  4360. var diff = lastRow - firstRow + 1;
  4361. }
  4362. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  4363. var folds = this.getFoldsInRange(range).map(function(x){
  4364. x = x.clone();
  4365. x.start.row += diff;
  4366. x.end.row += diff;
  4367. return x;
  4368. });
  4369. var lines = dir == 0
  4370. ? this.doc.getLines(firstRow, lastRow)
  4371. : this.doc.removeLines(firstRow, lastRow);
  4372. this.doc.insertLines(firstRow+diff, lines);
  4373. folds.length && this.addFolds(folds);
  4374. return diff;
  4375. };
  4376. this.moveLinesUp = function(firstRow, lastRow) {
  4377. return this.$moveLines(firstRow, lastRow, -1);
  4378. };
  4379. this.moveLinesDown = function(firstRow, lastRow) {
  4380. return this.$moveLines(firstRow, lastRow, 1);
  4381. };
  4382. this.duplicateLines = function(firstRow, lastRow) {
  4383. return this.$moveLines(firstRow, lastRow, 0);
  4384. };
  4385. this.$clipRowToDocument = function(row) {
  4386. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  4387. };
  4388. this.$clipColumnToRow = function(row, column) {
  4389. if (column < 0)
  4390. return 0;
  4391. return Math.min(this.doc.getLine(row).length, column);
  4392. };
  4393. this.$clipPositionToDocument = function(row, column) {
  4394. column = Math.max(0, column);
  4395. if (row < 0) {
  4396. row = 0;
  4397. column = 0;
  4398. } else {
  4399. var len = this.doc.getLength();
  4400. if (row >= len) {
  4401. row = len - 1;
  4402. column = this.doc.getLine(len-1).length;
  4403. } else {
  4404. column = Math.min(this.doc.getLine(row).length, column);
  4405. }
  4406. }
  4407. return {
  4408. row: row,
  4409. column: column
  4410. };
  4411. };
  4412. this.$clipRangeToDocument = function(range) {
  4413. if (range.start.row < 0) {
  4414. range.start.row = 0;
  4415. range.start.column = 0;
  4416. } else {
  4417. range.start.column = this.$clipColumnToRow(
  4418. range.start.row,
  4419. range.start.column
  4420. );
  4421. }
  4422. var len = this.doc.getLength() - 1;
  4423. if (range.end.row > len) {
  4424. range.end.row = len;
  4425. range.end.column = this.doc.getLine(len).length;
  4426. } else {
  4427. range.end.column = this.$clipColumnToRow(
  4428. range.end.row,
  4429. range.end.column
  4430. );
  4431. }
  4432. return range;
  4433. };
  4434. this.$wrapLimit = 80;
  4435. this.$useWrapMode = false;
  4436. this.$wrapLimitRange = {
  4437. min : null,
  4438. max : null
  4439. };
  4440. this.setUseWrapMode = function(useWrapMode) {
  4441. if (useWrapMode != this.$useWrapMode) {
  4442. this.$useWrapMode = useWrapMode;
  4443. this.$modified = true;
  4444. this.$resetRowCache(0);
  4445. if (useWrapMode) {
  4446. var len = this.getLength();
  4447. this.$wrapData = Array(len);
  4448. this.$updateWrapData(0, len - 1);
  4449. }
  4450. this._signal("changeWrapMode");
  4451. }
  4452. };
  4453. this.getUseWrapMode = function() {
  4454. return this.$useWrapMode;
  4455. };
  4456. this.setWrapLimitRange = function(min, max) {
  4457. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  4458. this.$wrapLimitRange = {
  4459. min: min,
  4460. max: max
  4461. };
  4462. this.$modified = true;
  4463. this._signal("changeWrapMode");
  4464. }
  4465. };
  4466. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  4467. var limits = this.$wrapLimitRange
  4468. if (limits.max < 0)
  4469. limits = {min: $printMargin, max: $printMargin};
  4470. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  4471. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  4472. this.$wrapLimit = wrapLimit;
  4473. this.$modified = true;
  4474. if (this.$useWrapMode) {
  4475. this.$updateWrapData(0, this.getLength() - 1);
  4476. this.$resetRowCache(0);
  4477. this._signal("changeWrapLimit");
  4478. }
  4479. return true;
  4480. }
  4481. return false;
  4482. };
  4483. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  4484. if (min)
  4485. wrapLimit = Math.max(min, wrapLimit);
  4486. if (max)
  4487. wrapLimit = Math.min(max, wrapLimit);
  4488. return wrapLimit;
  4489. };
  4490. this.getWrapLimit = function() {
  4491. return this.$wrapLimit;
  4492. };
  4493. this.setWrapLimit = function (limit) {
  4494. this.setWrapLimitRange(limit, limit);
  4495. };
  4496. this.getWrapLimitRange = function() {
  4497. return {
  4498. min : this.$wrapLimitRange.min,
  4499. max : this.$wrapLimitRange.max
  4500. };
  4501. };
  4502. this.$updateInternalDataOnChange = function(e) {
  4503. var useWrapMode = this.$useWrapMode;
  4504. var len;
  4505. var action = e.data.action;
  4506. var firstRow = e.data.range.start.row;
  4507. var lastRow = e.data.range.end.row;
  4508. var start = e.data.range.start;
  4509. var end = e.data.range.end;
  4510. var removedFolds = null;
  4511. if (action.indexOf("Lines") != -1) {
  4512. if (action == "insertLines") {
  4513. lastRow = firstRow + (e.data.lines.length);
  4514. } else {
  4515. lastRow = firstRow;
  4516. }
  4517. len = e.data.lines ? e.data.lines.length : lastRow - firstRow;
  4518. } else {
  4519. len = lastRow - firstRow;
  4520. }
  4521. this.$updating = true;
  4522. if (len != 0) {
  4523. if (action.indexOf("remove") != -1) {
  4524. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  4525. var foldLines = this.$foldData;
  4526. removedFolds = this.getFoldsInRange(e.data.range);
  4527. this.removeFolds(removedFolds);
  4528. var foldLine = this.getFoldLine(end.row);
  4529. var idx = 0;
  4530. if (foldLine) {
  4531. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  4532. foldLine.shiftRow(-len);
  4533. var foldLineBefore = this.getFoldLine(firstRow);
  4534. if (foldLineBefore && foldLineBefore !== foldLine) {
  4535. foldLineBefore.merge(foldLine);
  4536. foldLine = foldLineBefore;
  4537. }
  4538. idx = foldLines.indexOf(foldLine) + 1;
  4539. }
  4540. for (idx; idx < foldLines.length; idx++) {
  4541. var foldLine = foldLines[idx];
  4542. if (foldLine.start.row >= end.row) {
  4543. foldLine.shiftRow(-len);
  4544. }
  4545. }
  4546. lastRow = firstRow;
  4547. } else {
  4548. var args = Array(len);
  4549. args.unshift(firstRow, 0);
  4550. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
  4551. arr.splice.apply(arr, args);
  4552. var foldLines = this.$foldData;
  4553. var foldLine = this.getFoldLine(firstRow);
  4554. var idx = 0;
  4555. if (foldLine) {
  4556. var cmp = foldLine.range.compareInside(start.row, start.column)
  4557. if (cmp == 0) {
  4558. foldLine = foldLine.split(start.row, start.column);
  4559. foldLine.shiftRow(len);
  4560. foldLine.addRemoveChars(
  4561. lastRow, 0, end.column - start.column);
  4562. } else
  4563. if (cmp == -1) {
  4564. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  4565. foldLine.shiftRow(len);
  4566. }
  4567. idx = foldLines.indexOf(foldLine) + 1;
  4568. }
  4569. for (idx; idx < foldLines.length; idx++) {
  4570. var foldLine = foldLines[idx];
  4571. if (foldLine.start.row >= firstRow) {
  4572. foldLine.shiftRow(len);
  4573. }
  4574. }
  4575. }
  4576. } else {
  4577. len = Math.abs(e.data.range.start.column - e.data.range.end.column);
  4578. if (action.indexOf("remove") != -1) {
  4579. removedFolds = this.getFoldsInRange(e.data.range);
  4580. this.removeFolds(removedFolds);
  4581. len = -len;
  4582. }
  4583. var foldLine = this.getFoldLine(firstRow);
  4584. if (foldLine) {
  4585. foldLine.addRemoveChars(firstRow, start.column, len);
  4586. }
  4587. }
  4588. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  4589. console.error("doc.getLength() and $wrapData.length have to be the same!");
  4590. }
  4591. this.$updating = false;
  4592. if (useWrapMode)
  4593. this.$updateWrapData(firstRow, lastRow);
  4594. else
  4595. this.$updateRowLengthCache(firstRow, lastRow);
  4596. return removedFolds;
  4597. };
  4598. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  4599. this.$rowLengthCache[firstRow] = null;
  4600. this.$rowLengthCache[lastRow] = null;
  4601. };
  4602. this.$updateWrapData = function(firstRow, lastRow) {
  4603. var lines = this.doc.getAllLines();
  4604. var tabSize = this.getTabSize();
  4605. var wrapData = this.$wrapData;
  4606. var wrapLimit = this.$wrapLimit;
  4607. var tokens;
  4608. var foldLine;
  4609. var row = firstRow;
  4610. lastRow = Math.min(lastRow, lines.length - 1);
  4611. while (row <= lastRow) {
  4612. foldLine = this.getFoldLine(row, foldLine);
  4613. if (!foldLine) {
  4614. tokens = this.$getDisplayTokens(lines[row]);
  4615. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  4616. row ++;
  4617. } else {
  4618. tokens = [];
  4619. foldLine.walk(function(placeholder, row, column, lastColumn) {
  4620. var walkTokens;
  4621. if (placeholder != null) {
  4622. walkTokens = this.$getDisplayTokens(
  4623. placeholder, tokens.length);
  4624. walkTokens[0] = PLACEHOLDER_START;
  4625. for (var i = 1; i < walkTokens.length; i++) {
  4626. walkTokens[i] = PLACEHOLDER_BODY;
  4627. }
  4628. } else {
  4629. walkTokens = this.$getDisplayTokens(
  4630. lines[row].substring(lastColumn, column),
  4631. tokens.length);
  4632. }
  4633. tokens = tokens.concat(walkTokens);
  4634. }.bind(this),
  4635. foldLine.end.row,
  4636. lines[foldLine.end.row].length + 1
  4637. );
  4638. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  4639. row = foldLine.end.row + 1;
  4640. }
  4641. }
  4642. };
  4643. var CHAR = 1,
  4644. CHAR_EXT = 2,
  4645. PLACEHOLDER_START = 3,
  4646. PLACEHOLDER_BODY = 4,
  4647. PUNCTUATION = 9,
  4648. SPACE = 10,
  4649. TAB = 11,
  4650. TAB_SPACE = 12;
  4651. this.$computeWrapSplits = function(tokens, wrapLimit) {
  4652. if (tokens.length == 0) {
  4653. return [];
  4654. }
  4655. var splits = [];
  4656. var displayLength = tokens.length;
  4657. var lastSplit = 0, lastDocSplit = 0;
  4658. var isCode = this.$wrapAsCode;
  4659. function addSplit(screenPos) {
  4660. var displayed = tokens.slice(lastSplit, screenPos);
  4661. var len = displayed.length;
  4662. displayed.join("").
  4663. replace(/12/g, function() {
  4664. len -= 1;
  4665. }).
  4666. replace(/2/g, function() {
  4667. len -= 1;
  4668. });
  4669. lastDocSplit += len;
  4670. splits.push(lastDocSplit);
  4671. lastSplit = screenPos;
  4672. }
  4673. while (displayLength - lastSplit > wrapLimit) {
  4674. var split = lastSplit + wrapLimit;
  4675. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  4676. addSplit(split);
  4677. continue;
  4678. }
  4679. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  4680. for (split; split != lastSplit - 1; split--) {
  4681. if (tokens[split] == PLACEHOLDER_START) {
  4682. break;
  4683. }
  4684. }
  4685. if (split > lastSplit) {
  4686. addSplit(split);
  4687. continue;
  4688. }
  4689. split = lastSplit + wrapLimit;
  4690. for (split; split < tokens.length; split++) {
  4691. if (tokens[split] != PLACEHOLDER_BODY) {
  4692. break;
  4693. }
  4694. }
  4695. if (split == tokens.length) {
  4696. break; // Breaks the while-loop.
  4697. }
  4698. addSplit(split);
  4699. continue;
  4700. }
  4701. var minSplit = Math.max(split - (isCode ? 10 : wrapLimit-(wrapLimit>>2)), lastSplit - 1);
  4702. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  4703. split --;
  4704. }
  4705. if (isCode) {
  4706. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  4707. split --;
  4708. }
  4709. while (split > minSplit && tokens[split] == PUNCTUATION) {
  4710. split --;
  4711. }
  4712. } else {
  4713. while (split > minSplit && tokens[split] < SPACE) {
  4714. split --;
  4715. }
  4716. }
  4717. if (split > minSplit) {
  4718. addSplit(++split);
  4719. continue;
  4720. }
  4721. split = lastSplit + wrapLimit;
  4722. addSplit(split);
  4723. }
  4724. return splits;
  4725. };
  4726. this.$getDisplayTokens = function(str, offset) {
  4727. var arr = [];
  4728. var tabSize;
  4729. offset = offset || 0;
  4730. for (var i = 0; i < str.length; i++) {
  4731. var c = str.charCodeAt(i);
  4732. if (c == 9) {
  4733. tabSize = this.getScreenTabSize(arr.length + offset);
  4734. arr.push(TAB);
  4735. for (var n = 1; n < tabSize; n++) {
  4736. arr.push(TAB_SPACE);
  4737. }
  4738. }
  4739. else if (c == 32) {
  4740. arr.push(SPACE);
  4741. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  4742. arr.push(PUNCTUATION);
  4743. }
  4744. else if (c >= 0x1100 && isFullWidth(c)) {
  4745. arr.push(CHAR, CHAR_EXT);
  4746. } else {
  4747. arr.push(CHAR);
  4748. }
  4749. }
  4750. return arr;
  4751. };
  4752. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  4753. if (maxScreenColumn == 0)
  4754. return [0, 0];
  4755. if (maxScreenColumn == null)
  4756. maxScreenColumn = Infinity;
  4757. screenColumn = screenColumn || 0;
  4758. var c, column;
  4759. for (column = 0; column < str.length; column++) {
  4760. c = str.charCodeAt(column);
  4761. if (c == 9) {
  4762. screenColumn += this.getScreenTabSize(screenColumn);
  4763. }
  4764. else if (c >= 0x1100 && isFullWidth(c)) {
  4765. screenColumn += 2;
  4766. } else {
  4767. screenColumn += 1;
  4768. }
  4769. if (screenColumn > maxScreenColumn) {
  4770. break;
  4771. }
  4772. }
  4773. return [screenColumn, column];
  4774. };
  4775. this.lineWidgets = null;
  4776. this.getRowLength = function(row) {
  4777. if (this.lineWidgets)
  4778. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  4779. else
  4780. h = 0
  4781. if (!this.$useWrapMode || !this.$wrapData[row]) {
  4782. return 1 + h;
  4783. } else {
  4784. return this.$wrapData[row].length + 1 + h;
  4785. }
  4786. };
  4787. this.getRowLineCount = function(row) {
  4788. if (!this.$useWrapMode || !this.$wrapData[row]) {
  4789. return 1;
  4790. } else {
  4791. return this.$wrapData[row].length + 1;
  4792. }
  4793. };
  4794. this.getScreenLastRowColumn = function(screenRow) {
  4795. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  4796. return this.documentToScreenColumn(pos.row, pos.column);
  4797. };
  4798. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  4799. var screenRow = this.documentToScreenRow(docRow, docColumn);
  4800. return this.getScreenLastRowColumn(screenRow);
  4801. };
  4802. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  4803. var screenRow = this.documentToScreenRow(docRow, docColumn);
  4804. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  4805. };
  4806. this.getRowSplitData = function(row) {
  4807. if (!this.$useWrapMode) {
  4808. return undefined;
  4809. } else {
  4810. return this.$wrapData[row];
  4811. }
  4812. };
  4813. this.getScreenTabSize = function(screenColumn) {
  4814. return this.$tabSize - screenColumn % this.$tabSize;
  4815. };
  4816. this.screenToDocumentRow = function(screenRow, screenColumn) {
  4817. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  4818. };
  4819. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  4820. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  4821. };
  4822. this.screenToDocumentPosition = function(screenRow, screenColumn) {
  4823. if (screenRow < 0)
  4824. return {row: 0, column: 0};
  4825. var line;
  4826. var docRow = 0;
  4827. var docColumn = 0;
  4828. var column;
  4829. var row = 0;
  4830. var rowLength = 0;
  4831. var rowCache = this.$screenRowCache;
  4832. var i = this.$getRowCacheIndex(rowCache, screenRow);
  4833. var l = rowCache.length;
  4834. if (l && i >= 0) {
  4835. var row = rowCache[i];
  4836. var docRow = this.$docRowCache[i];
  4837. var doCache = screenRow > rowCache[l - 1];
  4838. } else {
  4839. var doCache = !l;
  4840. }
  4841. var maxRow = this.getLength() - 1;
  4842. var foldLine = this.getNextFoldLine(docRow);
  4843. var foldStart = foldLine ? foldLine.start.row : Infinity;
  4844. while (row <= screenRow) {
  4845. rowLength = this.getRowLength(docRow);
  4846. if (row + rowLength > screenRow || docRow >= maxRow) {
  4847. break;
  4848. } else {
  4849. row += rowLength;
  4850. docRow++;
  4851. if (docRow > foldStart) {
  4852. docRow = foldLine.end.row+1;
  4853. foldLine = this.getNextFoldLine(docRow, foldLine);
  4854. foldStart = foldLine ? foldLine.start.row : Infinity;
  4855. }
  4856. }
  4857. if (doCache) {
  4858. this.$docRowCache.push(docRow);
  4859. this.$screenRowCache.push(row);
  4860. }
  4861. }
  4862. if (foldLine && foldLine.start.row <= docRow) {
  4863. line = this.getFoldDisplayLine(foldLine);
  4864. docRow = foldLine.start.row;
  4865. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  4866. return {
  4867. row: maxRow,
  4868. column: this.getLine(maxRow).length
  4869. }
  4870. } else {
  4871. line = this.getLine(docRow);
  4872. foldLine = null;
  4873. }
  4874. if (this.$useWrapMode) {
  4875. var splits = this.$wrapData[docRow];
  4876. if (splits) {
  4877. var splitIndex = Math.floor(screenRow - row);
  4878. column = splits[splitIndex];
  4879. if(splitIndex > 0 && splits.length) {
  4880. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  4881. line = line.substring(docColumn);
  4882. }
  4883. }
  4884. }
  4885. docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
  4886. if (this.$useWrapMode && docColumn >= column)
  4887. docColumn = column - 1;
  4888. if (foldLine)
  4889. return foldLine.idxToPosition(docColumn);
  4890. return {row: docRow, column: docColumn};
  4891. };
  4892. this.documentToScreenPosition = function(docRow, docColumn) {
  4893. if (typeof docColumn === "undefined")
  4894. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  4895. else
  4896. pos = this.$clipPositionToDocument(docRow, docColumn);
  4897. docRow = pos.row;
  4898. docColumn = pos.column;
  4899. var screenRow = 0;
  4900. var foldStartRow = null;
  4901. var fold = null;
  4902. fold = this.getFoldAt(docRow, docColumn, 1);
  4903. if (fold) {
  4904. docRow = fold.start.row;
  4905. docColumn = fold.start.column;
  4906. }
  4907. var rowEnd, row = 0;
  4908. var rowCache = this.$docRowCache;
  4909. var i = this.$getRowCacheIndex(rowCache, docRow);
  4910. var l = rowCache.length;
  4911. if (l && i >= 0) {
  4912. var row = rowCache[i];
  4913. var screenRow = this.$screenRowCache[i];
  4914. var doCache = docRow > rowCache[l - 1];
  4915. } else {
  4916. var doCache = !l;
  4917. }
  4918. var foldLine = this.getNextFoldLine(row);
  4919. var foldStart = foldLine ?foldLine.start.row :Infinity;
  4920. while (row < docRow) {
  4921. if (row >= foldStart) {
  4922. rowEnd = foldLine.end.row + 1;
  4923. if (rowEnd > docRow)
  4924. break;
  4925. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  4926. foldStart = foldLine ?foldLine.start.row :Infinity;
  4927. }
  4928. else {
  4929. rowEnd = row + 1;
  4930. }
  4931. screenRow += this.getRowLength(row);
  4932. row = rowEnd;
  4933. if (doCache) {
  4934. this.$docRowCache.push(row);
  4935. this.$screenRowCache.push(screenRow);
  4936. }
  4937. }
  4938. var textLine = "";
  4939. if (foldLine && row >= foldStart) {
  4940. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  4941. foldStartRow = foldLine.start.row;
  4942. } else {
  4943. textLine = this.getLine(docRow).substring(0, docColumn);
  4944. foldStartRow = docRow;
  4945. }
  4946. if (this.$useWrapMode) {
  4947. var wrapRow = this.$wrapData[foldStartRow];
  4948. if (wrapRow) {
  4949. var screenRowOffset = 0;
  4950. while (textLine.length >= wrapRow[screenRowOffset]) {
  4951. screenRow ++;
  4952. screenRowOffset++;
  4953. }
  4954. textLine = textLine.substring(
  4955. wrapRow[screenRowOffset - 1] || 0, textLine.length
  4956. );
  4957. }
  4958. }
  4959. return {
  4960. row: screenRow,
  4961. column: this.$getStringScreenWidth(textLine)[0]
  4962. };
  4963. };
  4964. this.documentToScreenColumn = function(row, docColumn) {
  4965. return this.documentToScreenPosition(row, docColumn).column;
  4966. };
  4967. this.documentToScreenRow = function(docRow, docColumn) {
  4968. return this.documentToScreenPosition(docRow, docColumn).row;
  4969. };
  4970. this.getScreenLength = function() {
  4971. var screenRows = 0;
  4972. var fold = null;
  4973. if (!this.$useWrapMode) {
  4974. screenRows = this.getLength();
  4975. var foldData = this.$foldData;
  4976. for (var i = 0; i < foldData.length; i++) {
  4977. fold = foldData[i];
  4978. screenRows -= fold.end.row - fold.start.row;
  4979. }
  4980. } else {
  4981. var lastRow = this.$wrapData.length;
  4982. var row = 0, i = 0;
  4983. var fold = this.$foldData[i++];
  4984. var foldStart = fold ? fold.start.row :Infinity;
  4985. while (row < lastRow) {
  4986. var splits = this.$wrapData[row];
  4987. screenRows += splits ? splits.length + 1 : 1;
  4988. row ++;
  4989. if (row > foldStart) {
  4990. row = fold.end.row+1;
  4991. fold = this.$foldData[i++];
  4992. foldStart = fold ?fold.start.row :Infinity;
  4993. }
  4994. }
  4995. }
  4996. if (this.lineWidgets)
  4997. screenRows += this.$getWidgetScreenLength();
  4998. return screenRows;
  4999. };
  5000. this.$setFontMetrics = function(fm) {
  5001. }
  5002. function isFullWidth(c) {
  5003. if (c < 0x1100)
  5004. return false;
  5005. return c >= 0x1100 && c <= 0x115F ||
  5006. c >= 0x11A3 && c <= 0x11A7 ||
  5007. c >= 0x11FA && c <= 0x11FF ||
  5008. c >= 0x2329 && c <= 0x232A ||
  5009. c >= 0x2E80 && c <= 0x2E99 ||
  5010. c >= 0x2E9B && c <= 0x2EF3 ||
  5011. c >= 0x2F00 && c <= 0x2FD5 ||
  5012. c >= 0x2FF0 && c <= 0x2FFB ||
  5013. c >= 0x3000 && c <= 0x303E ||
  5014. c >= 0x3041 && c <= 0x3096 ||
  5015. c >= 0x3099 && c <= 0x30FF ||
  5016. c >= 0x3105 && c <= 0x312D ||
  5017. c >= 0x3131 && c <= 0x318E ||
  5018. c >= 0x3190 && c <= 0x31BA ||
  5019. c >= 0x31C0 && c <= 0x31E3 ||
  5020. c >= 0x31F0 && c <= 0x321E ||
  5021. c >= 0x3220 && c <= 0x3247 ||
  5022. c >= 0x3250 && c <= 0x32FE ||
  5023. c >= 0x3300 && c <= 0x4DBF ||
  5024. c >= 0x4E00 && c <= 0xA48C ||
  5025. c >= 0xA490 && c <= 0xA4C6 ||
  5026. c >= 0xA960 && c <= 0xA97C ||
  5027. c >= 0xAC00 && c <= 0xD7A3 ||
  5028. c >= 0xD7B0 && c <= 0xD7C6 ||
  5029. c >= 0xD7CB && c <= 0xD7FB ||
  5030. c >= 0xF900 && c <= 0xFAFF ||
  5031. c >= 0xFE10 && c <= 0xFE19 ||
  5032. c >= 0xFE30 && c <= 0xFE52 ||
  5033. c >= 0xFE54 && c <= 0xFE66 ||
  5034. c >= 0xFE68 && c <= 0xFE6B ||
  5035. c >= 0xFF01 && c <= 0xFF60 ||
  5036. c >= 0xFFE0 && c <= 0xFFE6;
  5037. };
  5038. }).call(EditSession.prototype);
  5039. require("./edit_session/folding").Folding.call(EditSession.prototype);
  5040. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  5041. config.defineOptions(EditSession.prototype, "session", {
  5042. wrap: {
  5043. set: function(value) {
  5044. if (!value || value == "off")
  5045. value = false;
  5046. else if (value == "free")
  5047. value = true;
  5048. else if (value == "printMargin")
  5049. value = -1;
  5050. else if (typeof value == "string")
  5051. value = parseInt(value, 10) || false;
  5052. if (this.$wrap == value)
  5053. return;
  5054. if (!value) {
  5055. this.setUseWrapMode(false);
  5056. } else {
  5057. var col = typeof value == "number" ? value : null;
  5058. this.setWrapLimitRange(col, col);
  5059. this.setUseWrapMode(true);
  5060. }
  5061. this.$wrap = value;
  5062. },
  5063. get: function() {
  5064. if (this.getUseWrapMode()) {
  5065. if (this.$wrap == -1)
  5066. return "printMargin";
  5067. if (!this.getWrapLimitRange().min)
  5068. return "free";
  5069. return this.$wrap;
  5070. }
  5071. return "off";
  5072. },
  5073. handlesSet: true
  5074. },
  5075. wrapMethod: {
  5076. set: function(val) {
  5077. val = val == "auto"
  5078. ? this.$mode.type != "text"
  5079. : val != "text";
  5080. if (val != this.$wrapAsCode) {
  5081. this.$wrapAsCode = val;
  5082. if (this.$useWrapMode) {
  5083. this.$modified = true;
  5084. this.$resetRowCache(0);
  5085. this.$updateWrapData(0, this.getLength() - 1);
  5086. }
  5087. }
  5088. },
  5089. initialValue: "auto"
  5090. },
  5091. firstLineNumber: {
  5092. set: function() {this._signal("changeBreakpoint");},
  5093. initialValue: 1
  5094. },
  5095. useWorker: {
  5096. set: function(useWorker) {
  5097. this.$useWorker = useWorker;
  5098. this.$stopWorker();
  5099. if (useWorker)
  5100. this.$startWorker();
  5101. },
  5102. initialValue: true
  5103. },
  5104. useSoftTabs: {initialValue: true},
  5105. tabSize: {
  5106. set: function(tabSize) {
  5107. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  5108. this.$modified = true;
  5109. this.$rowLengthCache = [];
  5110. this.$tabSize = tabSize;
  5111. this._signal("changeTabSize");
  5112. },
  5113. initialValue: 4,
  5114. handlesSet: true
  5115. },
  5116. overwrite: {
  5117. set: function(val) {this._signal("changeOverwrite");},
  5118. initialValue: false
  5119. },
  5120. newLineMode: {
  5121. set: function(val) {this.doc.setNewLineMode(val)},
  5122. get: function() {return this.doc.getNewLineMode()},
  5123. handlesSet: true
  5124. },
  5125. mode: {
  5126. set: function(val) { this.setMode(val) },
  5127. get: function() { return this.$modeId }
  5128. }
  5129. });
  5130. exports.EditSession = EditSession;
  5131. });
  5132. ace.define('ace/commands/command_manager', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/keyboard/hash_handler', 'ace/lib/event_emitter'], function(require, exports, module) {
  5133. var oop = require("../lib/oop");
  5134. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  5135. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  5136. var CommandManager = function(platform, commands) {
  5137. HashHandler.call(this, commands, platform);
  5138. this.byName = this.commands;
  5139. this.setDefaultHandler("exec", function(e) {
  5140. return e.command.exec(e.editor, e.args || {});
  5141. });
  5142. };
  5143. oop.inherits(CommandManager, HashHandler);
  5144. (function() {
  5145. oop.implement(this, EventEmitter);
  5146. this.exec = function(command, editor, args) {
  5147. if (typeof command === 'string')
  5148. command = this.commands[command];
  5149. if (!command)
  5150. return false;
  5151. if (editor && editor.$readOnly && !command.readOnly)
  5152. return false;
  5153. var e = {editor: editor, command: command, args: args};
  5154. var retvalue = this._emit("exec", e);
  5155. this._signal("afterExec", e);
  5156. return retvalue === false ? false : true;
  5157. };
  5158. this.toggleRecording = function(editor) {
  5159. if (this.$inReplay)
  5160. return;
  5161. editor && editor._emit("changeStatus");
  5162. if (this.recording) {
  5163. this.macro.pop();
  5164. this.removeEventListener("exec", this.$addCommandToMacro);
  5165. if (!this.macro.length)
  5166. this.macro = this.oldMacro;
  5167. return this.recording = false;
  5168. }
  5169. if (!this.$addCommandToMacro) {
  5170. this.$addCommandToMacro = function(e) {
  5171. this.macro.push([e.command, e.args]);
  5172. }.bind(this);
  5173. }
  5174. this.oldMacro = this.macro;
  5175. this.macro = [];
  5176. this.on("exec", this.$addCommandToMacro);
  5177. return this.recording = true;
  5178. };
  5179. this.replay = function(editor) {
  5180. if (this.$inReplay || !this.macro)
  5181. return;
  5182. if (this.recording)
  5183. return this.toggleRecording(editor);
  5184. try {
  5185. this.$inReplay = true;
  5186. this.macro.forEach(function(x) {
  5187. if (typeof x == "string")
  5188. this.exec(x, editor);
  5189. else
  5190. this.exec(x[0], editor, x[1]);
  5191. }, this);
  5192. } finally {
  5193. this.$inReplay = false;
  5194. }
  5195. };
  5196. this.trimMacro = function(m) {
  5197. return m.map(function(x){
  5198. if (typeof x[0] != "string")
  5199. x[0] = x[0].name;
  5200. if (!x[1])
  5201. x = x[0];
  5202. return x;
  5203. });
  5204. };
  5205. }).call(CommandManager.prototype);
  5206. exports.CommandManager = CommandManager;
  5207. });
  5208. ace.define('ace/keyboard/keybinding', ['require', 'exports', 'module' , 'ace/lib/keys', 'ace/lib/event'], function(require, exports, module) {
  5209. var keyUtil = require("../lib/keys");
  5210. var event = require("../lib/event");
  5211. var KeyBinding = function(editor) {
  5212. this.$editor = editor;
  5213. this.$data = {editor: editor};
  5214. this.$handlers = [];
  5215. this.setDefaultHandler(editor.commands);
  5216. };
  5217. (function() {
  5218. this.setDefaultHandler = function(kb) {
  5219. this.removeKeyboardHandler(this.$defaultHandler);
  5220. this.$defaultHandler = kb;
  5221. this.addKeyboardHandler(kb, 0);
  5222. };
  5223. this.setKeyboardHandler = function(kb) {
  5224. var h = this.$handlers;
  5225. if (h[h.length - 1] == kb)
  5226. return;
  5227. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  5228. this.removeKeyboardHandler(h[h.length - 1]);
  5229. this.addKeyboardHandler(kb, 1);
  5230. };
  5231. this.addKeyboardHandler = function(kb, pos) {
  5232. if (!kb)
  5233. return;
  5234. if (typeof kb == "function" && !kb.handleKeyboard)
  5235. kb.handleKeyboard = kb;
  5236. var i = this.$handlers.indexOf(kb);
  5237. if (i != -1)
  5238. this.$handlers.splice(i, 1);
  5239. if (pos == undefined)
  5240. this.$handlers.push(kb);
  5241. else
  5242. this.$handlers.splice(pos, 0, kb);
  5243. if (i == -1 && kb.attach)
  5244. kb.attach(this.$editor);
  5245. };
  5246. this.removeKeyboardHandler = function(kb) {
  5247. var i = this.$handlers.indexOf(kb);
  5248. if (i == -1)
  5249. return false;
  5250. this.$handlers.splice(i, 1);
  5251. kb.detach && kb.detach(this.$editor);
  5252. return true;
  5253. };
  5254. this.getKeyboardHandler = function() {
  5255. return this.$handlers[this.$handlers.length - 1];
  5256. };
  5257. this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
  5258. var toExecute;
  5259. var success = false;
  5260. var commands = this.$editor.commands;
  5261. for (var i = this.$handlers.length; i--;) {
  5262. toExecute = this.$handlers[i].handleKeyboard(
  5263. this.$data, hashId, keyString, keyCode, e
  5264. );
  5265. if (!toExecute || !toExecute.command)
  5266. continue;
  5267. if (toExecute.command == "null") {
  5268. success = true;
  5269. } else {
  5270. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  5271. }
  5272. if (success && e && hashId != -1 &&
  5273. toExecute.passEvent != true && toExecute.command.passEvent != true
  5274. ) {
  5275. event.stopEvent(e);
  5276. }
  5277. if (success)
  5278. break;
  5279. }
  5280. return success;
  5281. };
  5282. this.onCommandKey = function(e, hashId, keyCode) {
  5283. var keyString = keyUtil.keyCodeToString(keyCode);
  5284. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  5285. };
  5286. this.onTextInput = function(text) {
  5287. var success = this.$callKeyboardHandlers(-1, text);
  5288. if (!success)
  5289. this.$editor.commands.exec("insertstring", this.$editor, text);
  5290. };
  5291. }).call(KeyBinding.prototype);
  5292. exports.KeyBinding = KeyBinding;
  5293. });
  5294. ace.define('ace/keyboard/hash_handler', ['require', 'exports', 'module' , 'ace/lib/keys', 'ace/lib/useragent'], function(require, exports, module) {
  5295. var keyUtil = require("../lib/keys");
  5296. var useragent = require("../lib/useragent");
  5297. function HashHandler(config, platform) {
  5298. this.platform = platform || (useragent.isMac ? "mac" : "win");
  5299. this.commands = {};
  5300. this.commandKeyBinding = {};
  5301. if (this.__defineGetter__ && this.__defineSetter__ && typeof console != "undefined" && console.error) {
  5302. var warned = false;
  5303. var warn = function() {
  5304. if (!warned) {
  5305. warned = true;
  5306. console.error("commmandKeyBinding has too many m's. use commandKeyBinding");
  5307. }
  5308. };
  5309. this.__defineGetter__("commmandKeyBinding", function() {
  5310. warn();
  5311. return this.commandKeyBinding;
  5312. });
  5313. this.__defineSetter__("commmandKeyBinding", function(val) {
  5314. warn();
  5315. return this.commandKeyBinding = val;
  5316. });
  5317. } else {
  5318. this.commmandKeyBinding = this.commandKeyBinding;
  5319. }
  5320. this.addCommands(config);
  5321. };
  5322. (function() {
  5323. this.addCommand = function(command) {
  5324. if (this.commands[command.name])
  5325. this.removeCommand(command);
  5326. this.commands[command.name] = command;
  5327. if (command.bindKey)
  5328. this._buildKeyHash(command);
  5329. };
  5330. this.removeCommand = function(command) {
  5331. var name = (typeof command === 'string' ? command : command.name);
  5332. command = this.commands[name];
  5333. delete this.commands[name];
  5334. var ckb = this.commandKeyBinding;
  5335. for (var hashId in ckb) {
  5336. for (var key in ckb[hashId]) {
  5337. if (ckb[hashId][key] == command)
  5338. delete ckb[hashId][key];
  5339. }
  5340. }
  5341. };
  5342. this.bindKey = function(key, command) {
  5343. if(!key)
  5344. return;
  5345. if (typeof command == "function") {
  5346. this.addCommand({exec: command, bindKey: key, name: command.name || key});
  5347. return;
  5348. }
  5349. var ckb = this.commandKeyBinding;
  5350. key.split("|").forEach(function(keyPart) {
  5351. var binding = this.parseKeys(keyPart, command);
  5352. var hashId = binding.hashId;
  5353. (ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
  5354. }, this);
  5355. };
  5356. this.addCommands = function(commands) {
  5357. commands && Object.keys(commands).forEach(function(name) {
  5358. var command = commands[name];
  5359. if (!command)
  5360. return;
  5361. if (typeof command === "string")
  5362. return this.bindKey(command, name);
  5363. if (typeof command === "function")
  5364. command = { exec: command };
  5365. if (typeof command !== "object")
  5366. return;
  5367. if (!command.name)
  5368. command.name = name;
  5369. this.addCommand(command);
  5370. }, this);
  5371. };
  5372. this.removeCommands = function(commands) {
  5373. Object.keys(commands).forEach(function(name) {
  5374. this.removeCommand(commands[name]);
  5375. }, this);
  5376. };
  5377. this.bindKeys = function(keyList) {
  5378. Object.keys(keyList).forEach(function(key) {
  5379. this.bindKey(key, keyList[key]);
  5380. }, this);
  5381. };
  5382. this._buildKeyHash = function(command) {
  5383. var binding = command.bindKey;
  5384. if (!binding)
  5385. return;
  5386. var key = typeof binding == "string" ? binding: binding[this.platform];
  5387. this.bindKey(key, command);
  5388. };
  5389. this.parseKeys = function(keys) {
  5390. if (keys.indexOf(" ") != -1)
  5391. keys = keys.split(/\s+/).pop();
  5392. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
  5393. var key = parts.pop();
  5394. var keyCode = keyUtil[key];
  5395. if (keyUtil.FUNCTION_KEYS[keyCode])
  5396. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  5397. else if (!parts.length)
  5398. return {key: key, hashId: -1};
  5399. else if (parts.length == 1 && parts[0] == "shift")
  5400. return {key: key.toUpperCase(), hashId: -1};
  5401. var hashId = 0;
  5402. for (var i = parts.length; i--;) {
  5403. var modifier = keyUtil.KEY_MODS[parts[i]];
  5404. if (modifier == null) {
  5405. if (typeof console != "undefined")
  5406. console.error("invalid modifier " + parts[i] + " in " + keys);
  5407. return false;
  5408. }
  5409. hashId |= modifier;
  5410. }
  5411. return {key: key, hashId: hashId};
  5412. };
  5413. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  5414. var ckbr = this.commandKeyBinding;
  5415. return ckbr[hashId] && ckbr[hashId][keyString];
  5416. };
  5417. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  5418. return {
  5419. command: this.findKeyCommand(hashId, keyString)
  5420. };
  5421. };
  5422. }).call(HashHandler.prototype)
  5423. exports.HashHandler = HashHandler;
  5424. });
  5425. ace.define('ace/mouse/fold_handler', ['require', 'exports', 'module' ], function(require, exports, module) {
  5426. function FoldHandler(editor) {
  5427. editor.on("click", function(e) {
  5428. var position = e.getDocumentPosition();
  5429. var session = editor.session;
  5430. var fold = session.getFoldAt(position.row, position.column, 1);
  5431. if (fold) {
  5432. if (e.getAccelKey())
  5433. session.removeFold(fold);
  5434. else
  5435. session.expandFold(fold);
  5436. e.stop();
  5437. }
  5438. });
  5439. editor.on("gutterclick", function(e) {
  5440. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  5441. if (gutterRegion == "foldWidgets") {
  5442. var row = e.getDocumentPosition().row;
  5443. var session = editor.session;
  5444. if (session.foldWidgets && session.foldWidgets[row])
  5445. editor.session.onFoldWidgetClick(row, e);
  5446. if (!editor.isFocused())
  5447. editor.focus();
  5448. e.stop();
  5449. }
  5450. });
  5451. editor.on("gutterdblclick", function(e) {
  5452. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  5453. if (gutterRegion == "foldWidgets") {
  5454. var row = e.getDocumentPosition().row;
  5455. var session = editor.session;
  5456. var data = session.getParentFoldRangeData(row, true);
  5457. var range = data.range || data.firstRange;
  5458. if (range) {
  5459. row = range.start.row;
  5460. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  5461. if (fold) {
  5462. session.removeFold(fold);
  5463. } else {
  5464. session.addFold("...", range);
  5465. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  5466. }
  5467. }
  5468. e.stop();
  5469. }
  5470. });
  5471. }
  5472. exports.FoldHandler = FoldHandler;
  5473. });
  5474. ace.define('ace/commands/default_commands', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/config', 'ace/range'], function(require, exports, module) {
  5475. var lang = require("../lib/lang");
  5476. var config = require("../config");
  5477. var Range = require("../range").Range;
  5478. function bindKey(win, mac) {
  5479. return {win: win, mac: mac};
  5480. }
  5481. exports.commands = [{
  5482. name: "showSettingsMenu",
  5483. bindKey: bindKey("Ctrl-,", "Command-,"),
  5484. exec: function(editor) {
  5485. config.loadModule("ace/ext/settings_menu", function(module) {
  5486. module.init(editor);
  5487. editor.showSettingsMenu();
  5488. });
  5489. },
  5490. readOnly: true
  5491. }, {
  5492. name: "goToNextError",
  5493. bindKey: bindKey("Alt-E", "Ctrl-E"),
  5494. exec: function(editor) {
  5495. config.loadModule("ace/ext/error_marker", function(module) {
  5496. module.showErrorMarker(editor, 1);
  5497. });
  5498. },
  5499. scrollIntoView: "animate",
  5500. readOnly: true
  5501. }, {
  5502. name: "goToPreviousError",
  5503. bindKey: bindKey("Alt-Shift-E", "Ctrl-Shift-E"),
  5504. exec: function(editor) {
  5505. config.loadModule("ace/ext/error_marker", function(module) {
  5506. module.showErrorMarker(editor, -1);
  5507. });
  5508. },
  5509. scrollIntoView: "animate",
  5510. readOnly: true
  5511. }, {
  5512. name: "selectall",
  5513. bindKey: bindKey("Ctrl-A", "Command-A"),
  5514. exec: function(editor) { editor.selectAll(); },
  5515. readOnly: true
  5516. }, {
  5517. name: "centerselection",
  5518. bindKey: bindKey(null, "Ctrl-L"),
  5519. exec: function(editor) { editor.centerSelection(); },
  5520. readOnly: true
  5521. }, {
  5522. name: "gotoline",
  5523. bindKey: bindKey("Ctrl-L", "Command-L"),
  5524. exec: function(editor) {
  5525. var line = parseInt(prompt("Enter line number:"), 10);
  5526. if (!isNaN(line)) {
  5527. editor.gotoLine(line);
  5528. }
  5529. },
  5530. readOnly: true
  5531. }, {
  5532. name: "fold",
  5533. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  5534. exec: function(editor) { editor.session.toggleFold(false); },
  5535. scrollIntoView: "center",
  5536. readOnly: true
  5537. }, {
  5538. name: "unfold",
  5539. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  5540. exec: function(editor) { editor.session.toggleFold(true); },
  5541. scrollIntoView: "center",
  5542. readOnly: true
  5543. }, {
  5544. name: "toggleFoldWidget",
  5545. bindKey: bindKey("F2", "F2"),
  5546. exec: function(editor) { editor.session.toggleFoldWidget(); },
  5547. scrollIntoView: "center",
  5548. readOnly: true
  5549. }, {
  5550. name: "toggleParentFoldWidget",
  5551. bindKey: bindKey("Alt-F2", "Alt-F2"),
  5552. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  5553. scrollIntoView: "center",
  5554. readOnly: true
  5555. }, {
  5556. name: "foldall",
  5557. bindKey: bindKey("Ctrl-Alt-0", "Ctrl-Command-Option-0"),
  5558. exec: function(editor) { editor.session.foldAll(); },
  5559. scrollIntoView: "center",
  5560. readOnly: true
  5561. }, {
  5562. name: "foldOther",
  5563. bindKey: bindKey("Alt-0", "Command-Option-0"),
  5564. exec: function(editor) {
  5565. editor.session.foldAll();
  5566. editor.session.unfold(editor.selection.getAllRanges());
  5567. },
  5568. scrollIntoView: "center",
  5569. readOnly: true
  5570. }, {
  5571. name: "unfoldall",
  5572. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  5573. exec: function(editor) { editor.session.unfold(); },
  5574. scrollIntoView: "center",
  5575. readOnly: true
  5576. }, {
  5577. name: "findnext",
  5578. bindKey: bindKey("Ctrl-K", "Command-G"),
  5579. exec: function(editor) { editor.findNext(); },
  5580. multiSelectAction: "forEach",
  5581. scrollIntoView: "center",
  5582. readOnly: true
  5583. }, {
  5584. name: "findprevious",
  5585. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  5586. exec: function(editor) { editor.findPrevious(); },
  5587. multiSelectAction: "forEach",
  5588. scrollIntoView: "center",
  5589. readOnly: true
  5590. }, {
  5591. name: "selectOrFindNext",
  5592. bindKey: bindKey("Alt-K", "Ctrl-G"),
  5593. exec: function(editor) {
  5594. if (editor.selection.isEmpty())
  5595. editor.selection.selectWord();
  5596. else
  5597. editor.findNext();
  5598. },
  5599. readOnly: true
  5600. }, {
  5601. name: "selectOrFindPrevious",
  5602. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  5603. exec: function(editor) {
  5604. if (editor.selection.isEmpty())
  5605. editor.selection.selectWord();
  5606. else
  5607. editor.findPrevious();
  5608. },
  5609. readOnly: true
  5610. }, {
  5611. name: "find",
  5612. bindKey: bindKey("Ctrl-F", "Command-F"),
  5613. exec: function(editor) {
  5614. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  5615. },
  5616. readOnly: true
  5617. }, {
  5618. name: "overwrite",
  5619. bindKey: "Insert",
  5620. exec: function(editor) { editor.toggleOverwrite(); },
  5621. readOnly: true
  5622. }, {
  5623. name: "selecttostart",
  5624. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
  5625. exec: function(editor) { editor.getSelection().selectFileStart(); },
  5626. multiSelectAction: "forEach",
  5627. readOnly: true,
  5628. scrollIntoView: "animate",
  5629. aceCommandGroup: "fileJump"
  5630. }, {
  5631. name: "gotostart",
  5632. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  5633. exec: function(editor) { editor.navigateFileStart(); },
  5634. multiSelectAction: "forEach",
  5635. readOnly: true,
  5636. scrollIntoView: "animate",
  5637. aceCommandGroup: "fileJump"
  5638. }, {
  5639. name: "selectup",
  5640. bindKey: bindKey("Shift-Up", "Shift-Up"),
  5641. exec: function(editor) { editor.getSelection().selectUp(); },
  5642. multiSelectAction: "forEach",
  5643. readOnly: true
  5644. }, {
  5645. name: "golineup",
  5646. bindKey: bindKey("Up", "Up|Ctrl-P"),
  5647. exec: function(editor, args) { editor.navigateUp(args.times); },
  5648. multiSelectAction: "forEach",
  5649. readOnly: true
  5650. }, {
  5651. name: "selecttoend",
  5652. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
  5653. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  5654. multiSelectAction: "forEach",
  5655. readOnly: true,
  5656. scrollIntoView: "animate",
  5657. aceCommandGroup: "fileJump"
  5658. }, {
  5659. name: "gotoend",
  5660. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  5661. exec: function(editor) { editor.navigateFileEnd(); },
  5662. multiSelectAction: "forEach",
  5663. readOnly: true,
  5664. scrollIntoView: "animate",
  5665. aceCommandGroup: "fileJump"
  5666. }, {
  5667. name: "selectdown",
  5668. bindKey: bindKey("Shift-Down", "Shift-Down"),
  5669. exec: function(editor) { editor.getSelection().selectDown(); },
  5670. multiSelectAction: "forEach",
  5671. scrollIntoView: "cursor",
  5672. readOnly: true
  5673. }, {
  5674. name: "golinedown",
  5675. bindKey: bindKey("Down", "Down|Ctrl-N"),
  5676. exec: function(editor, args) { editor.navigateDown(args.times); },
  5677. multiSelectAction: "forEach",
  5678. scrollIntoView: "cursor",
  5679. readOnly: true
  5680. }, {
  5681. name: "selectwordleft",
  5682. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  5683. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  5684. multiSelectAction: "forEach",
  5685. scrollIntoView: "cursor",
  5686. readOnly: true
  5687. }, {
  5688. name: "gotowordleft",
  5689. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  5690. exec: function(editor) { editor.navigateWordLeft(); },
  5691. multiSelectAction: "forEach",
  5692. scrollIntoView: "cursor",
  5693. readOnly: true
  5694. }, {
  5695. name: "selecttolinestart",
  5696. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
  5697. exec: function(editor) { editor.getSelection().selectLineStart(); },
  5698. multiSelectAction: "forEach",
  5699. scrollIntoView: "cursor",
  5700. readOnly: true
  5701. }, {
  5702. name: "gotolinestart",
  5703. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  5704. exec: function(editor) { editor.navigateLineStart(); },
  5705. multiSelectAction: "forEach",
  5706. scrollIntoView: "cursor",
  5707. readOnly: true
  5708. }, {
  5709. name: "selectleft",
  5710. bindKey: bindKey("Shift-Left", "Shift-Left"),
  5711. exec: function(editor) { editor.getSelection().selectLeft(); },
  5712. multiSelectAction: "forEach",
  5713. scrollIntoView: "cursor",
  5714. readOnly: true
  5715. }, {
  5716. name: "gotoleft",
  5717. bindKey: bindKey("Left", "Left|Ctrl-B"),
  5718. exec: function(editor, args) { editor.navigateLeft(args.times); },
  5719. multiSelectAction: "forEach",
  5720. scrollIntoView: "cursor",
  5721. readOnly: true
  5722. }, {
  5723. name: "selectwordright",
  5724. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  5725. exec: function(editor) { editor.getSelection().selectWordRight(); },
  5726. multiSelectAction: "forEach",
  5727. scrollIntoView: "cursor",
  5728. readOnly: true
  5729. }, {
  5730. name: "gotowordright",
  5731. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  5732. exec: function(editor) { editor.navigateWordRight(); },
  5733. multiSelectAction: "forEach",
  5734. scrollIntoView: "cursor",
  5735. readOnly: true
  5736. }, {
  5737. name: "selecttolineend",
  5738. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
  5739. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  5740. multiSelectAction: "forEach",
  5741. scrollIntoView: "cursor",
  5742. readOnly: true
  5743. }, {
  5744. name: "gotolineend",
  5745. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  5746. exec: function(editor) { editor.navigateLineEnd(); },
  5747. multiSelectAction: "forEach",
  5748. scrollIntoView: "cursor",
  5749. readOnly: true
  5750. }, {
  5751. name: "selectright",
  5752. bindKey: bindKey("Shift-Right", "Shift-Right"),
  5753. exec: function(editor) { editor.getSelection().selectRight(); },
  5754. multiSelectAction: "forEach",
  5755. scrollIntoView: "cursor",
  5756. readOnly: true
  5757. }, {
  5758. name: "gotoright",
  5759. bindKey: bindKey("Right", "Right|Ctrl-F"),
  5760. exec: function(editor, args) { editor.navigateRight(args.times); },
  5761. multiSelectAction: "forEach",
  5762. scrollIntoView: "cursor",
  5763. readOnly: true
  5764. }, {
  5765. name: "selectpagedown",
  5766. bindKey: "Shift-PageDown",
  5767. exec: function(editor) { editor.selectPageDown(); },
  5768. readOnly: true
  5769. }, {
  5770. name: "pagedown",
  5771. bindKey: bindKey(null, "Option-PageDown"),
  5772. exec: function(editor) { editor.scrollPageDown(); },
  5773. readOnly: true
  5774. }, {
  5775. name: "gotopagedown",
  5776. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  5777. exec: function(editor) { editor.gotoPageDown(); },
  5778. readOnly: true
  5779. }, {
  5780. name: "selectpageup",
  5781. bindKey: "Shift-PageUp",
  5782. exec: function(editor) { editor.selectPageUp(); },
  5783. readOnly: true
  5784. }, {
  5785. name: "pageup",
  5786. bindKey: bindKey(null, "Option-PageUp"),
  5787. exec: function(editor) { editor.scrollPageUp(); },
  5788. readOnly: true
  5789. }, {
  5790. name: "gotopageup",
  5791. bindKey: "PageUp",
  5792. exec: function(editor) { editor.gotoPageUp(); },
  5793. readOnly: true
  5794. }, {
  5795. name: "scrollup",
  5796. bindKey: bindKey("Ctrl-Up", null),
  5797. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  5798. readOnly: true
  5799. }, {
  5800. name: "scrolldown",
  5801. bindKey: bindKey("Ctrl-Down", null),
  5802. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  5803. readOnly: true
  5804. }, {
  5805. name: "selectlinestart",
  5806. bindKey: "Shift-Home",
  5807. exec: function(editor) { editor.getSelection().selectLineStart(); },
  5808. multiSelectAction: "forEach",
  5809. scrollIntoView: "cursor",
  5810. readOnly: true
  5811. }, {
  5812. name: "selectlineend",
  5813. bindKey: "Shift-End",
  5814. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  5815. multiSelectAction: "forEach",
  5816. scrollIntoView: "cursor",
  5817. readOnly: true
  5818. }, {
  5819. name: "togglerecording",
  5820. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  5821. exec: function(editor) { editor.commands.toggleRecording(editor); },
  5822. readOnly: true
  5823. }, {
  5824. name: "replaymacro",
  5825. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  5826. exec: function(editor) { editor.commands.replay(editor); },
  5827. readOnly: true
  5828. }, {
  5829. name: "jumptomatching",
  5830. bindKey: bindKey("Ctrl-P", "Ctrl-Shift-P"),
  5831. exec: function(editor) { editor.jumpToMatching(); },
  5832. multiSelectAction: "forEach",
  5833. readOnly: true
  5834. }, {
  5835. name: "selecttomatching",
  5836. bindKey: bindKey("Ctrl-Shift-P", null),
  5837. exec: function(editor) { editor.jumpToMatching(true); },
  5838. multiSelectAction: "forEach",
  5839. readOnly: true
  5840. },
  5841. {
  5842. name: "cut",
  5843. exec: function(editor) {
  5844. var range = editor.getSelectionRange();
  5845. editor._emit("cut", range);
  5846. if (!editor.selection.isEmpty()) {
  5847. editor.session.remove(range);
  5848. editor.clearSelection();
  5849. }
  5850. },
  5851. scrollIntoView: "cursor",
  5852. multiSelectAction: "forEach"
  5853. }, {
  5854. name: "removeline",
  5855. bindKey: bindKey("Ctrl-D", "Command-D"),
  5856. exec: function(editor) { editor.removeLines(); },
  5857. scrollIntoView: "cursor",
  5858. multiSelectAction: "forEachLine"
  5859. }, {
  5860. name: "duplicateSelection",
  5861. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  5862. exec: function(editor) { editor.duplicateSelection(); },
  5863. scrollIntoView: "cursor",
  5864. multiSelectAction: "forEach"
  5865. }, {
  5866. name: "sortlines",
  5867. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  5868. exec: function(editor) { editor.sortLines(); },
  5869. scrollIntoView: "selection",
  5870. multiSelectAction: "forEachLine"
  5871. }, {
  5872. name: "togglecomment",
  5873. bindKey: bindKey("Ctrl-/", "Command-/"),
  5874. exec: function(editor) { editor.toggleCommentLines(); },
  5875. multiSelectAction: "forEachLine",
  5876. scrollIntoView: "selectionPart"
  5877. }, {
  5878. name: "toggleBlockComment",
  5879. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  5880. exec: function(editor) { editor.toggleBlockComment(); },
  5881. multiSelectAction: "forEach",
  5882. scrollIntoView: "selectionPart"
  5883. }, {
  5884. name: "modifyNumberUp",
  5885. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  5886. exec: function(editor) { editor.modifyNumber(1); },
  5887. multiSelectAction: "forEach"
  5888. }, {
  5889. name: "modifyNumberDown",
  5890. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  5891. exec: function(editor) { editor.modifyNumber(-1); },
  5892. multiSelectAction: "forEach"
  5893. }, {
  5894. name: "replace",
  5895. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  5896. exec: function(editor) {
  5897. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  5898. }
  5899. }, {
  5900. name: "undo",
  5901. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  5902. exec: function(editor) { editor.undo(); }
  5903. }, {
  5904. name: "redo",
  5905. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  5906. exec: function(editor) { editor.redo(); }
  5907. }, {
  5908. name: "copylinesup",
  5909. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  5910. exec: function(editor) { editor.copyLinesUp(); },
  5911. scrollIntoView: "cursor"
  5912. }, {
  5913. name: "movelinesup",
  5914. bindKey: bindKey("Alt-Up", "Option-Up"),
  5915. exec: function(editor) { editor.moveLinesUp(); },
  5916. scrollIntoView: "cursor"
  5917. }, {
  5918. name: "copylinesdown",
  5919. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  5920. exec: function(editor) { editor.copyLinesDown(); },
  5921. scrollIntoView: "cursor"
  5922. }, {
  5923. name: "movelinesdown",
  5924. bindKey: bindKey("Alt-Down", "Option-Down"),
  5925. exec: function(editor) { editor.moveLinesDown(); },
  5926. scrollIntoView: "cursor"
  5927. }, {
  5928. name: "del",
  5929. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  5930. exec: function(editor) { editor.remove("right"); },
  5931. multiSelectAction: "forEach",
  5932. scrollIntoView: "cursor"
  5933. }, {
  5934. name: "backspace",
  5935. bindKey: bindKey(
  5936. "Shift-Backspace|Backspace",
  5937. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  5938. ),
  5939. exec: function(editor) { editor.remove("left"); },
  5940. multiSelectAction: "forEach",
  5941. scrollIntoView: "cursor"
  5942. }, {
  5943. name: "cut_or_delete",
  5944. bindKey: bindKey("Shift-Delete", null),
  5945. exec: function(editor) {
  5946. if (editor.selection.isEmpty()) {
  5947. editor.remove("left");
  5948. } else {
  5949. return false;
  5950. }
  5951. },
  5952. multiSelectAction: "forEach",
  5953. scrollIntoView: "cursor"
  5954. }, {
  5955. name: "removetolinestart",
  5956. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  5957. exec: function(editor) { editor.removeToLineStart(); },
  5958. multiSelectAction: "forEach",
  5959. scrollIntoView: "cursor"
  5960. }, {
  5961. name: "removetolineend",
  5962. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  5963. exec: function(editor) { editor.removeToLineEnd(); },
  5964. multiSelectAction: "forEach",
  5965. scrollIntoView: "cursor"
  5966. }, {
  5967. name: "removewordleft",
  5968. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  5969. exec: function(editor) { editor.removeWordLeft(); },
  5970. multiSelectAction: "forEach",
  5971. scrollIntoView: "cursor"
  5972. }, {
  5973. name: "removewordright",
  5974. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  5975. exec: function(editor) { editor.removeWordRight(); },
  5976. multiSelectAction: "forEach",
  5977. scrollIntoView: "cursor"
  5978. }, {
  5979. name: "outdent",
  5980. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  5981. exec: function(editor) { editor.blockOutdent(); },
  5982. multiSelectAction: "forEach",
  5983. scrollIntoView: "selectionPart"
  5984. }, {
  5985. name: "indent",
  5986. bindKey: bindKey("Tab", "Tab"),
  5987. exec: function(editor) { editor.indent(); },
  5988. multiSelectAction: "forEach",
  5989. scrollIntoView: "selectionPart"
  5990. }, {
  5991. name: "blockoutdent",
  5992. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  5993. exec: function(editor) { editor.blockOutdent(); },
  5994. multiSelectAction: "forEachLine",
  5995. scrollIntoView: "selectionPart"
  5996. }, {
  5997. name: "blockindent",
  5998. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  5999. exec: function(editor) { editor.blockIndent(); },
  6000. multiSelectAction: "forEachLine",
  6001. scrollIntoView: "selectionPart"
  6002. }, {
  6003. name: "insertstring",
  6004. exec: function(editor, str) { editor.insert(str); },
  6005. multiSelectAction: "forEach",
  6006. scrollIntoView: "cursor"
  6007. }, {
  6008. name: "inserttext",
  6009. exec: function(editor, args) {
  6010. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  6011. },
  6012. multiSelectAction: "forEach",
  6013. scrollIntoView: "cursor"
  6014. }, {
  6015. name: "splitline",
  6016. bindKey: bindKey(null, "Ctrl-O"),
  6017. exec: function(editor) { editor.splitLine(); },
  6018. multiSelectAction: "forEach",
  6019. scrollIntoView: "cursor"
  6020. }, {
  6021. name: "transposeletters",
  6022. bindKey: bindKey("Ctrl-T", "Ctrl-T"),
  6023. exec: function(editor) { editor.transposeLetters(); },
  6024. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  6025. scrollIntoView: "cursor"
  6026. }, {
  6027. name: "touppercase",
  6028. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  6029. exec: function(editor) { editor.toUpperCase(); },
  6030. multiSelectAction: "forEach",
  6031. scrollIntoView: "cursor"
  6032. }, {
  6033. name: "tolowercase",
  6034. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  6035. exec: function(editor) { editor.toLowerCase(); },
  6036. multiSelectAction: "forEach",
  6037. scrollIntoView: "cursor"
  6038. }, {
  6039. name: "expandtoline",
  6040. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  6041. exec: function(editor) {
  6042. var range = editor.selection.getRange();
  6043. range.start.column = range.end.column = 0;
  6044. range.end.row++;
  6045. editor.selection.setRange(range, false);
  6046. },
  6047. multiSelectAction: "forEach",
  6048. scrollIntoView: "cursor",
  6049. readOnly: true
  6050. }, {
  6051. name: "joinlines",
  6052. bindKey: bindKey(null, null),
  6053. exec: function(editor) {
  6054. var isBackwards = editor.selection.isBackwards();
  6055. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  6056. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  6057. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length
  6058. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  6059. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  6060. var insertLine = editor.session.doc.getLine(selectionStart.row);
  6061. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  6062. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  6063. if (curLine.length !== 0) {
  6064. curLine = " " + curLine;
  6065. }
  6066. insertLine += curLine;
  6067. };
  6068. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  6069. insertLine += editor.session.doc.getNewLineCharacter();
  6070. }
  6071. editor.clearSelection();
  6072. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  6073. if (selectedCount > 0) {
  6074. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  6075. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  6076. } else {
  6077. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  6078. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  6079. }
  6080. },
  6081. multiSelectAction: "forEach",
  6082. readOnly: true
  6083. }, {
  6084. name: "invertSelection",
  6085. bindKey: bindKey(null, null),
  6086. exec: function(editor) {
  6087. var endRow = editor.session.doc.getLength() - 1;
  6088. var endCol = editor.session.doc.getLine(endRow).length;
  6089. var ranges = editor.selection.rangeList.ranges;
  6090. var newRanges = [];
  6091. if (ranges.length < 1) {
  6092. ranges = [editor.selection.getRange()];
  6093. }
  6094. for (var i = 0; i < ranges.length; i++) {
  6095. if (i == (ranges.length - 1)) {
  6096. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  6097. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  6098. }
  6099. }
  6100. if (i === 0) {
  6101. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  6102. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  6103. }
  6104. } else {
  6105. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  6106. }
  6107. }
  6108. editor.exitMultiSelectMode();
  6109. editor.clearSelection();
  6110. for(var i = 0; i < newRanges.length; i++) {
  6111. editor.selection.addRange(newRanges[i], false);
  6112. }
  6113. },
  6114. readOnly: true,
  6115. scrollIntoView: "none"
  6116. }];
  6117. });
  6118. ace.define('ace/lib/event_emitter', ['require', 'exports', 'module' ], function(require, exports, module) {
  6119. var EventEmitter = {};
  6120. var stopPropagation = function() { this.propagationStopped = true; };
  6121. var preventDefault = function() { this.defaultPrevented = true; };
  6122. EventEmitter._emit =
  6123. EventEmitter._dispatchEvent = function(eventName, e) {
  6124. this._eventRegistry || (this._eventRegistry = {});
  6125. this._defaultHandlers || (this._defaultHandlers = {});
  6126. var listeners = this._eventRegistry[eventName] || [];
  6127. var defaultHandler = this._defaultHandlers[eventName];
  6128. if (!listeners.length && !defaultHandler)
  6129. return;
  6130. if (typeof e != "object" || !e)
  6131. e = {};
  6132. if (!e.type)
  6133. e.type = eventName;
  6134. if (!e.stopPropagation)
  6135. e.stopPropagation = stopPropagation;
  6136. if (!e.preventDefault)
  6137. e.preventDefault = preventDefault;
  6138. listeners = listeners.slice();
  6139. for (var i=0; i<listeners.length; i++) {
  6140. listeners[i](e, this);
  6141. if (e.propagationStopped)
  6142. break;
  6143. }
  6144. if (defaultHandler && !e.defaultPrevented)
  6145. return defaultHandler(e, this);
  6146. };
  6147. EventEmitter._signal = function(eventName, e) {
  6148. var listeners = (this._eventRegistry || {})[eventName];
  6149. if (!listeners)
  6150. return;
  6151. listeners = listeners.slice();
  6152. for (var i=0; i<listeners.length; i++)
  6153. listeners[i](e, this);
  6154. };
  6155. EventEmitter.once = function(eventName, callback) {
  6156. var _self = this;
  6157. callback && this.addEventListener(eventName, function newCallback() {
  6158. _self.removeEventListener(eventName, newCallback);
  6159. callback.apply(null, arguments);
  6160. });
  6161. };
  6162. EventEmitter.setDefaultHandler = function(eventName, callback) {
  6163. var handlers = this._defaultHandlers
  6164. if (!handlers)
  6165. handlers = this._defaultHandlers = {_disabled_: {}};
  6166. if (handlers[eventName]) {
  6167. var old = handlers[eventName];
  6168. var disabled = handlers._disabled_[eventName];
  6169. if (!disabled)
  6170. handlers._disabled_[eventName] = disabled = [];
  6171. disabled.push(old);
  6172. var i = disabled.indexOf(callback);
  6173. if (i != -1)
  6174. disabled.splice(i, 1);
  6175. }
  6176. handlers[eventName] = callback;
  6177. };
  6178. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  6179. var handlers = this._defaultHandlers
  6180. if (!handlers)
  6181. return;
  6182. var disabled = handlers._disabled_[eventName];
  6183. if (handlers[eventName] == callback) {
  6184. var old = handlers[eventName];
  6185. if (disabled)
  6186. this.setDefaultHandler(eventName, disabled.pop());
  6187. } else if (disabled) {
  6188. var i = disabled.indexOf(callback);
  6189. if (i != -1)
  6190. disabled.splice(i, 1);
  6191. }
  6192. };
  6193. EventEmitter.on =
  6194. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  6195. this._eventRegistry = this._eventRegistry || {};
  6196. var listeners = this._eventRegistry[eventName];
  6197. if (!listeners)
  6198. listeners = this._eventRegistry[eventName] = [];
  6199. if (listeners.indexOf(callback) == -1)
  6200. listeners[capturing ? "unshift" : "push"](callback);
  6201. return callback;
  6202. };
  6203. EventEmitter.off =
  6204. EventEmitter.removeListener =
  6205. EventEmitter.removeEventListener = function(eventName, callback) {
  6206. this._eventRegistry = this._eventRegistry || {};
  6207. var listeners = this._eventRegistry[eventName];
  6208. if (!listeners)
  6209. return;
  6210. var index = listeners.indexOf(callback);
  6211. if (index !== -1)
  6212. listeners.splice(index, 1);
  6213. };
  6214. EventEmitter.removeAllListeners = function(eventName) {
  6215. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  6216. };
  6217. exports.EventEmitter = EventEmitter;
  6218. });
  6219. ace.define('ace/undomanager', ['require', 'exports', 'module' ], function(require, exports, module) {
  6220. var UndoManager = function() {
  6221. this.reset();
  6222. };
  6223. (function() {
  6224. this.execute = function(options) {
  6225. var deltas = options.args[0];
  6226. this.$doc = options.args[1];
  6227. if (options.merge && this.hasUndo()){
  6228. this.dirtyCounter--;
  6229. deltas = this.$undoStack.pop().concat(deltas);
  6230. }
  6231. this.$undoStack.push(deltas);
  6232. this.$redoStack = [];
  6233. if (this.dirtyCounter < 0) {
  6234. this.dirtyCounter = NaN;
  6235. }
  6236. this.dirtyCounter++;
  6237. };
  6238. this.undo = function(dontSelect) {
  6239. var deltas = this.$undoStack.pop();
  6240. var undoSelectionRange = null;
  6241. if (deltas) {
  6242. undoSelectionRange =
  6243. this.$doc.undoChanges(deltas, dontSelect);
  6244. this.$redoStack.push(deltas);
  6245. this.dirtyCounter--;
  6246. }
  6247. return undoSelectionRange;
  6248. };
  6249. this.redo = function(dontSelect) {
  6250. var deltas = this.$redoStack.pop();
  6251. var redoSelectionRange = null;
  6252. if (deltas) {
  6253. redoSelectionRange =
  6254. this.$doc.redoChanges(deltas, dontSelect);
  6255. this.$undoStack.push(deltas);
  6256. this.dirtyCounter++;
  6257. }
  6258. return redoSelectionRange;
  6259. };
  6260. this.reset = function() {
  6261. this.$undoStack = [];
  6262. this.$redoStack = [];
  6263. this.dirtyCounter = 0;
  6264. };
  6265. this.hasUndo = function() {
  6266. return this.$undoStack.length > 0;
  6267. };
  6268. this.hasRedo = function() {
  6269. return this.$redoStack.length > 0;
  6270. };
  6271. this.markClean = function() {
  6272. this.dirtyCounter = 0;
  6273. };
  6274. this.isClean = function() {
  6275. return this.dirtyCounter === 0;
  6276. };
  6277. }).call(UndoManager.prototype);
  6278. exports.UndoManager = UndoManager;
  6279. });
  6280. ace.define('ace/lib/net', ['require', 'exports', 'module' , 'ace/lib/dom'], function(require, exports, module) {
  6281. var dom = require("./dom");
  6282. exports.get = function (url, callback) {
  6283. var xhr = new XMLHttpRequest();
  6284. xhr.open('GET', url, true);
  6285. xhr.onreadystatechange = function () {
  6286. if (xhr.readyState === 4) {
  6287. callback(xhr.responseText);
  6288. }
  6289. };
  6290. xhr.send(null);
  6291. };
  6292. exports.loadScript = function(path, callback) {
  6293. var head = dom.getDocumentHead();
  6294. var s = document.createElement('script');
  6295. s.src = path;
  6296. head.appendChild(s);
  6297. s.onload = s.onreadystatechange = function(_, isAbort) {
  6298. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  6299. s = s.onload = s.onreadystatechange = null;
  6300. if (!isAbort)
  6301. callback();
  6302. }
  6303. };
  6304. };
  6305. exports.qualifyURL = function(url) {
  6306. var a = document.createElement('a');
  6307. a.href = url;
  6308. return a.href;
  6309. }
  6310. });
  6311. ace.define('ace/virtual_renderer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/config', 'ace/lib/useragent', 'ace/layer/gutter', 'ace/layer/marker', 'ace/layer/text', 'ace/layer/cursor', 'ace/scrollbar', 'ace/renderloop', 'ace/layer/font_metrics', 'ace/lib/event_emitter'], function(require, exports, module) {
  6312. var oop = require("./lib/oop");
  6313. var dom = require("./lib/dom");
  6314. var config = require("./config");
  6315. var useragent = require("./lib/useragent");
  6316. var GutterLayer = require("./layer/gutter").Gutter;
  6317. var MarkerLayer = require("./layer/marker").Marker;
  6318. var TextLayer = require("./layer/text").Text;
  6319. var CursorLayer = require("./layer/cursor").Cursor;
  6320. var HScrollBar = require("./scrollbar").HScrollBar;
  6321. var VScrollBar = require("./scrollbar").VScrollBar;
  6322. var RenderLoop = require("./renderloop").RenderLoop;
  6323. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  6324. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6325. var editorCss = ".mod-toolbox.mod-toolbox-ace .ace_editor {\
  6326. position: relative;\
  6327. overflow: hidden;\
  6328. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace !important;\
  6329. font-size: 12px !important;\
  6330. line-height: normal;\
  6331. direction: ltr;\
  6332. }\
  6333. .ace_scroller {\
  6334. position: absolute;\
  6335. overflow: hidden;\
  6336. top: 0;\
  6337. bottom: 0;\
  6338. background-color: inherit;\
  6339. -ms-user-select: none;\
  6340. -moz-user-select: none;\
  6341. -webkit-user-select: none;\
  6342. user-select: none;\
  6343. }\
  6344. .ace_content {\
  6345. position: absolute;\
  6346. -moz-box-sizing: border-box;\
  6347. -webkit-box-sizing: border-box;\
  6348. box-sizing: border-box;\
  6349. cursor: text;\
  6350. min-width: 100%;\
  6351. }\
  6352. .ace_dragging, .ace_dragging * {\
  6353. cursor: move !important;\
  6354. }\
  6355. .ace_dragging .ace_scroller:before{\
  6356. position: absolute;\
  6357. top: 0;\
  6358. left: 0;\
  6359. right: 0;\
  6360. bottom: 0;\
  6361. content: '';\
  6362. background: rgba(250, 250, 250, 0.01);\
  6363. z-index: 1000;\
  6364. }\
  6365. .ace_dragging.ace_dark .ace_scroller:before{\
  6366. background: rgba(0, 0, 0, 0.01);\
  6367. }\
  6368. .ace_selecting, .ace_selecting * {\
  6369. cursor: text !important;\
  6370. }\
  6371. .ace_gutter {\
  6372. position: absolute;\
  6373. overflow : hidden;\
  6374. width: auto;\
  6375. top: 0;\
  6376. bottom: 0;\
  6377. left: 0;\
  6378. cursor: default;\
  6379. z-index: 4;\
  6380. -ms-user-select: none;\
  6381. -moz-user-select: none;\
  6382. -webkit-user-select: none;\
  6383. user-select: none;\
  6384. }\
  6385. .ace_gutter-active-line {\
  6386. position: absolute;\
  6387. left: 0;\
  6388. right: 0;\
  6389. }\
  6390. .ace_scroller.ace_scroll-left {\
  6391. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  6392. }\
  6393. .ace_gutter-cell {\
  6394. padding-left: 19px;\
  6395. padding-right: 6px;\
  6396. background-repeat: no-repeat;\
  6397. }\
  6398. .ace_gutter-cell.ace_error {\
  6399. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABOFBMVEX/////////QRswFAb/Ui4wFAYwFAYwFAaWGAfDRymzOSH/PxswFAb/SiUwFAYwFAbUPRvjQiDllog5HhHdRybsTi3/Tyv9Tir+Syj/UC3////XurebMBIwFAb/RSHbPx/gUzfdwL3kzMivKBAwFAbbvbnhPx66NhowFAYwFAaZJg8wFAaxKBDZurf/RB6mMxb/SCMwFAYwFAbxQB3+RB4wFAb/Qhy4Oh+4QifbNRcwFAYwFAYwFAb/QRzdNhgwFAYwFAbav7v/Uy7oaE68MBK5LxLewr/r2NXewLswFAaxJw4wFAbkPRy2PyYwFAaxKhLm1tMwFAazPiQwFAaUGAb/QBrfOx3bvrv/VC/maE4wFAbRPBq6MRO8Qynew8Dp2tjfwb0wFAbx6eju5+by6uns4uH9/f36+vr/GkHjAAAAYnRSTlMAGt+64rnWu/bo8eAA4InH3+DwoN7j4eLi4xP99Nfg4+b+/u9B/eDs1MD1mO7+4PHg2MXa347g7vDizMLN4eG+Pv7i5evs/v79yu7S3/DV7/498Yv24eH+4ufQ3Ozu/v7+y13sRqwAAADLSURBVHjaZc/XDsFgGIBhtDrshlitmk2IrbHFqL2pvXf/+78DPokj7+Fz9qpU/9UXJIlhmPaTaQ6QPaz0mm+5gwkgovcV6GZzd5JtCQwgsxoHOvJO15kleRLAnMgHFIESUEPmawB9ngmelTtipwwfASilxOLyiV5UVUyVAfbG0cCPHig+GBkzAENHS0AstVF6bacZIOzgLmxsHbt2OecNgJC83JERmePUYq8ARGkJx6XtFsdddBQgZE2nPR6CICZhawjA4Fb/chv+399kfR+MMMDGOQAAAABJRU5ErkJggg==\");\
  6400. background-repeat: no-repeat;\
  6401. background-position: 2px center;\
  6402. }\
  6403. .ace_gutter-cell.ace_warning {\
  6404. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAmVBMVEX///8AAAD///8AAAAAAABPSzb/5sAAAAB/blH/73z/ulkAAAAAAAD85pkAAAAAAAACAgP/vGz/rkDerGbGrV7/pkQICAf////e0IsAAAD/oED/qTvhrnUAAAD/yHD/njcAAADuv2r/nz//oTj/p064oGf/zHAAAAA9Nir/tFIAAAD/tlTiuWf/tkIAAACynXEAAAAAAAAtIRW7zBpBAAAAM3RSTlMAABR1m7RXO8Ln31Z36zT+neXe5OzooRDfn+TZ4p3h2hTf4t3k3ucyrN1K5+Xaks52Sfs9CXgrAAAAjklEQVR42o3PbQ+CIBQFYEwboPhSYgoYunIqqLn6/z8uYdH8Vmdnu9vz4WwXgN/xTPRD2+sgOcZjsge/whXZgUaYYvT8QnuJaUrjrHUQreGczuEafQCO/SJTufTbroWsPgsllVhq3wJEk2jUSzX3CUEDJC84707djRc5MTAQxoLgupWRwW6UB5fS++NV8AbOZgnsC7BpEAAAAABJRU5ErkJggg==\");\
  6405. background-position: 2px center;\
  6406. }\
  6407. .ace_gutter-cell.ace_info {\
  6408. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  6409. background-position: 2px center;\
  6410. }\
  6411. .ace_dark .ace_gutter-cell.ace_info {\
  6412. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  6413. }\
  6414. .ace_scrollbar {\
  6415. position: absolute;\
  6416. right: 0;\
  6417. bottom: 0;\
  6418. z-index: 6;\
  6419. }\
  6420. .ace_scrollbar-inner {\
  6421. position: absolute;\
  6422. cursor: text;\
  6423. left: 0;\
  6424. top: 0;\
  6425. }\
  6426. .ace_scrollbar-v{\
  6427. overflow-x: hidden;\
  6428. overflow-y: scroll;\
  6429. top: 0;\
  6430. }\
  6431. .ace_scrollbar-h {\
  6432. overflow-x: scroll;\
  6433. overflow-y: hidden;\
  6434. left: 0;\
  6435. }\
  6436. .ace_print-margin {\
  6437. position: absolute;\
  6438. height: 100%;\
  6439. }\
  6440. .ace_text-input {\
  6441. position: absolute;\
  6442. z-index: 0;\
  6443. width: 0.5em;\
  6444. height: 1em;\
  6445. opacity: 0;\
  6446. background: transparent;\
  6447. -moz-appearance: none;\
  6448. appearance: none;\
  6449. border: none;\
  6450. resize: none;\
  6451. outline: none;\
  6452. overflow: hidden;\
  6453. font: inherit;\
  6454. padding: 0 1px;\
  6455. margin: 0 -1px;\
  6456. text-indent: -1em;\
  6457. -ms-user-select: text;\
  6458. -moz-user-select: text;\
  6459. -webkit-user-select: text;\
  6460. user-select: text;\
  6461. }\
  6462. .ace_text-input.ace_composition {\
  6463. background: #f8f8f8;\
  6464. color: #111;\
  6465. z-index: 1000;\
  6466. opacity: 1;\
  6467. text-indent: 0;\
  6468. }\
  6469. .ace_layer {\
  6470. z-index: 1;\
  6471. position: absolute;\
  6472. overflow: hidden;\
  6473. white-space: pre;\
  6474. height: 100%;\
  6475. width: 100%;\
  6476. -moz-box-sizing: border-box;\
  6477. -webkit-box-sizing: border-box;\
  6478. box-sizing: border-box;\
  6479. /* setting pointer-events: auto; on node under the mouse, which changes\
  6480. during scroll, will break mouse wheel scrolling in Safari */\
  6481. pointer-events: none;\
  6482. }\
  6483. .ace_gutter-layer {\
  6484. position: relative;\
  6485. width: auto;\
  6486. text-align: right;\
  6487. pointer-events: auto;\
  6488. }\
  6489. .ace_text-layer {\
  6490. font: inherit !important;\
  6491. }\
  6492. .ace_cjk {\
  6493. display: inline-block;\
  6494. text-align: center;\
  6495. }\
  6496. .ace_cursor-layer {\
  6497. z-index: 4;\
  6498. }\
  6499. .ace_cursor {\
  6500. z-index: 4;\
  6501. position: absolute;\
  6502. -moz-box-sizing: border-box;\
  6503. -webkit-box-sizing: border-box;\
  6504. box-sizing: border-box;\
  6505. border-left: 2px solid\
  6506. }\
  6507. .ace_slim-cursors .ace_cursor {\
  6508. border-left-width: 1px;\
  6509. }\
  6510. .ace_overwrite-cursors .ace_cursor {\
  6511. border-left-width: 0px;\
  6512. border-bottom: 1px solid;\
  6513. }\
  6514. .ace_hidden-cursors .ace_cursor {\
  6515. opacity: 0.2;\
  6516. }\
  6517. .ace_smooth-blinking .ace_cursor {\
  6518. -moz-transition: opacity 0.18s;\
  6519. -webkit-transition: opacity 0.18s;\
  6520. -o-transition: opacity 0.18s;\
  6521. -ms-transition: opacity 0.18s;\
  6522. transition: opacity 0.18s;\
  6523. }\
  6524. .ace_editor.ace_multiselect .ace_cursor {\
  6525. border-left-width: 1px;\
  6526. }\
  6527. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  6528. position: absolute;\
  6529. z-index: 3;\
  6530. }\
  6531. .ace_marker-layer .ace_selection {\
  6532. position: absolute;\
  6533. z-index: 5;\
  6534. }\
  6535. .ace_marker-layer .ace_bracket {\
  6536. position: absolute;\
  6537. z-index: 6;\
  6538. }\
  6539. .ace_marker-layer .ace_active-line {\
  6540. position: absolute;\
  6541. z-index: 2;\
  6542. }\
  6543. .ace_marker-layer .ace_selected-word {\
  6544. position: absolute;\
  6545. z-index: 4;\
  6546. -moz-box-sizing: border-box;\
  6547. -webkit-box-sizing: border-box;\
  6548. box-sizing: border-box;\
  6549. }\
  6550. .ace_line .ace_fold {\
  6551. -moz-box-sizing: border-box;\
  6552. -webkit-box-sizing: border-box;\
  6553. box-sizing: border-box;\
  6554. display: inline-block;\
  6555. height: 11px;\
  6556. margin-top: -2px;\
  6557. vertical-align: middle;\
  6558. background-image:\
  6559. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  6560. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  6561. background-repeat: no-repeat, repeat-x;\
  6562. background-position: center center, top left;\
  6563. color: transparent;\
  6564. border: 1px solid black;\
  6565. -moz-border-radius: 2px;\
  6566. -webkit-border-radius: 2px;\
  6567. border-radius: 2px;\
  6568. cursor: pointer;\
  6569. pointer-events: auto;\
  6570. }\
  6571. .ace_dark .ace_fold {\
  6572. }\
  6573. .ace_fold:hover{\
  6574. background-image:\
  6575. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  6576. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  6577. }\
  6578. .ace_tooltip {\
  6579. background-color: #FFF;\
  6580. background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));\
  6581. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  6582. border: 1px solid gray;\
  6583. border-radius: 1px;\
  6584. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  6585. color: black;\
  6586. display: block;\
  6587. max-width: 100%;\
  6588. padding: 3px 4px;\
  6589. position: fixed;\
  6590. z-index: 999999;\
  6591. -moz-box-sizing: border-box;\
  6592. -webkit-box-sizing: border-box;\
  6593. box-sizing: border-box;\
  6594. cursor: default;\
  6595. white-space: pre;\
  6596. word-wrap: break-word;\
  6597. line-height: normal;\
  6598. font-style: normal;\
  6599. font-weight: normal;\
  6600. letter-spacing: normal;\
  6601. pointer-events: none;\
  6602. }\
  6603. .ace_folding-enabled > .ace_gutter-cell {\
  6604. padding-right: 13px;\
  6605. }\
  6606. .ace_fold-widget {\
  6607. -moz-box-sizing: border-box;\
  6608. -webkit-box-sizing: border-box;\
  6609. box-sizing: border-box;\
  6610. margin: 0 -12px 0 1px;\
  6611. display: none;\
  6612. width: 11px;\
  6613. vertical-align: top;\
  6614. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  6615. background-repeat: no-repeat;\
  6616. background-position: center;\
  6617. border-radius: 3px;\
  6618. border: 1px solid transparent;\
  6619. cursor: pointer;\
  6620. }\
  6621. .ace_folding-enabled .ace_fold-widget {\
  6622. display: inline-block; \
  6623. }\
  6624. .ace_fold-widget.ace_end {\
  6625. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  6626. }\
  6627. .ace_fold-widget.ace_closed {\
  6628. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  6629. }\
  6630. .ace_fold-widget:hover {\
  6631. border: 1px solid rgba(0, 0, 0, 0.3);\
  6632. background-color: rgba(255, 255, 255, 0.2);\
  6633. -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  6634. -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  6635. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  6636. }\
  6637. .ace_fold-widget:active {\
  6638. border: 1px solid rgba(0, 0, 0, 0.4);\
  6639. background-color: rgba(0, 0, 0, 0.05);\
  6640. -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  6641. -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  6642. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  6643. }\
  6644. /**\
  6645. * Dark version for fold widgets\
  6646. */\
  6647. .ace_dark .ace_fold-widget {\
  6648. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  6649. }\
  6650. .ace_dark .ace_fold-widget.ace_end {\
  6651. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  6652. }\
  6653. .ace_dark .ace_fold-widget.ace_closed {\
  6654. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  6655. }\
  6656. .ace_dark .ace_fold-widget:hover {\
  6657. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  6658. background-color: rgba(255, 255, 255, 0.1);\
  6659. }\
  6660. .ace_dark .ace_fold-widget:active {\
  6661. -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  6662. -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  6663. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  6664. }\
  6665. .ace_fold-widget.ace_invalid {\
  6666. background-color: #FFB4B4;\
  6667. border-color: #DE5555;\
  6668. }\
  6669. .ace_fade-fold-widgets .ace_fold-widget {\
  6670. -moz-transition: opacity 0.4s ease 0.05s;\
  6671. -webkit-transition: opacity 0.4s ease 0.05s;\
  6672. -o-transition: opacity 0.4s ease 0.05s;\
  6673. -ms-transition: opacity 0.4s ease 0.05s;\
  6674. transition: opacity 0.4s ease 0.05s;\
  6675. opacity: 0;\
  6676. }\
  6677. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  6678. -moz-transition: opacity 0.05s ease 0.05s;\
  6679. -webkit-transition: opacity 0.05s ease 0.05s;\
  6680. -o-transition: opacity 0.05s ease 0.05s;\
  6681. -ms-transition: opacity 0.05s ease 0.05s;\
  6682. transition: opacity 0.05s ease 0.05s;\
  6683. opacity:1;\
  6684. }\
  6685. .ace_underline {\
  6686. text-decoration: underline;\
  6687. }\
  6688. .ace_bold {\
  6689. font-weight: bold;\
  6690. }\
  6691. .ace_nobold .ace_bold {\
  6692. font-weight: normal;\
  6693. }\
  6694. .ace_italic {\
  6695. font-style: italic;\
  6696. }\
  6697. .ace_error-marker {\
  6698. background-color: rgba(255, 0, 0,0.2);\
  6699. position: absolute;\
  6700. z-index: 9;\
  6701. }\
  6702. .ace_highlight-marker {\
  6703. background-color: rgba(255, 255, 0,0.2);\
  6704. position: absolute;\
  6705. z-index: 8;\
  6706. }\
  6707. ";
  6708. dom.importCssString(editorCss, "ace_editor");
  6709. var VirtualRenderer = function(container, theme) {
  6710. var _self = this;
  6711. this.container = container || dom.createElement("div");
  6712. this.$keepTextAreaAtCursor = !useragent.isOldIE;
  6713. dom.addCssClass(this.container, "ace_editor");
  6714. this.setTheme(theme);
  6715. this.$gutter = dom.createElement("div");
  6716. this.$gutter.className = "ace_gutter";
  6717. this.container.appendChild(this.$gutter);
  6718. this.scroller = dom.createElement("div");
  6719. this.scroller.className = "ace_scroller";
  6720. this.container.appendChild(this.scroller);
  6721. this.content = dom.createElement("div");
  6722. this.content.className = "ace_content";
  6723. this.scroller.appendChild(this.content);
  6724. this.$gutterLayer = new GutterLayer(this.$gutter);
  6725. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  6726. this.$markerBack = new MarkerLayer(this.content);
  6727. var textLayer = this.$textLayer = new TextLayer(this.content);
  6728. this.canvas = textLayer.element;
  6729. this.$markerFront = new MarkerLayer(this.content);
  6730. this.$cursorLayer = new CursorLayer(this.content);
  6731. this.$horizScroll = false;
  6732. this.$vScroll = false;
  6733. this.scrollBar =
  6734. this.scrollBarV = new VScrollBar(this.container, this);
  6735. this.scrollBarH = new HScrollBar(this.container, this);
  6736. this.scrollBarV.addEventListener("scroll", function(e) {
  6737. if (!_self.$scrollAnimation)
  6738. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  6739. });
  6740. this.scrollBarH.addEventListener("scroll", function(e) {
  6741. if (!_self.$scrollAnimation)
  6742. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  6743. });
  6744. this.scrollTop = 0;
  6745. this.scrollLeft = 0;
  6746. this.cursorPos = {
  6747. row : 0,
  6748. column : 0
  6749. };
  6750. this.$fontMetrics = new FontMetrics(this.container, 500);
  6751. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  6752. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  6753. _self.updateCharacterSize();
  6754. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  6755. _self._signal("changeCharacterSize", e);
  6756. });
  6757. this.$size = {
  6758. width: 0,
  6759. height: 0,
  6760. scrollerHeight: 0,
  6761. scrollerWidth: 0,
  6762. $dirty: true
  6763. };
  6764. this.layerConfig = {
  6765. width : 1,
  6766. padding : 0,
  6767. firstRow : 0,
  6768. firstRowScreen: 0,
  6769. lastRow : 0,
  6770. lineHeight : 0,
  6771. characterWidth : 0,
  6772. minHeight : 1,
  6773. maxHeight : 1,
  6774. offset : 0,
  6775. height : 1,
  6776. gutterOffset: 1
  6777. };
  6778. this.scrollMargin = {
  6779. left: 0,
  6780. right: 0,
  6781. top: 0,
  6782. bottom: 0,
  6783. v: 0,
  6784. h: 0
  6785. };
  6786. this.$loop = new RenderLoop(
  6787. this.$renderChanges.bind(this),
  6788. this.container.ownerDocument.defaultView
  6789. );
  6790. this.$loop.schedule(this.CHANGE_FULL);
  6791. this.updateCharacterSize();
  6792. this.setPadding(4);
  6793. config.resetOptions(this);
  6794. config._emit("renderer", this);
  6795. };
  6796. (function() {
  6797. this.CHANGE_CURSOR = 1;
  6798. this.CHANGE_MARKER = 2;
  6799. this.CHANGE_GUTTER = 4;
  6800. this.CHANGE_SCROLL = 8;
  6801. this.CHANGE_LINES = 16;
  6802. this.CHANGE_TEXT = 32;
  6803. this.CHANGE_SIZE = 64;
  6804. this.CHANGE_MARKER_BACK = 128;
  6805. this.CHANGE_MARKER_FRONT = 256;
  6806. this.CHANGE_FULL = 512;
  6807. this.CHANGE_H_SCROLL = 1024;
  6808. oop.implement(this, EventEmitter);
  6809. this.updateCharacterSize = function() {
  6810. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  6811. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  6812. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  6813. }
  6814. this.layerConfig.characterWidth =
  6815. this.characterWidth = this.$textLayer.getCharacterWidth();
  6816. this.layerConfig.lineHeight =
  6817. this.lineHeight = this.$textLayer.getLineHeight();
  6818. this.$updatePrintMargin();
  6819. };
  6820. this.setSession = function(session) {
  6821. if (this.session)
  6822. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  6823. this.session = session;
  6824. if (!session)
  6825. return;
  6826. if (this.scrollMargin.top && session.getScrollTop() <= 0)
  6827. session.setScrollTop(-this.scrollMargin.top);
  6828. this.$cursorLayer.setSession(session);
  6829. this.$markerBack.setSession(session);
  6830. this.$markerFront.setSession(session);
  6831. this.$gutterLayer.setSession(session);
  6832. this.$textLayer.setSession(session);
  6833. this.$loop.schedule(this.CHANGE_FULL);
  6834. this.session.$setFontMetrics(this.$fontMetrics);
  6835. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  6836. this.onChangeNewLineMode()
  6837. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  6838. };
  6839. this.updateLines = function(firstRow, lastRow) {
  6840. if (lastRow === undefined)
  6841. lastRow = Infinity;
  6842. if (!this.$changedLines) {
  6843. this.$changedLines = {
  6844. firstRow: firstRow,
  6845. lastRow: lastRow
  6846. };
  6847. }
  6848. else {
  6849. if (this.$changedLines.firstRow > firstRow)
  6850. this.$changedLines.firstRow = firstRow;
  6851. if (this.$changedLines.lastRow < lastRow)
  6852. this.$changedLines.lastRow = lastRow;
  6853. }
  6854. if (this.$changedLines.firstRow > this.layerConfig.lastRow ||
  6855. this.$changedLines.lastRow < this.layerConfig.firstRow)
  6856. return;
  6857. this.$loop.schedule(this.CHANGE_LINES);
  6858. };
  6859. this.onChangeNewLineMode = function() {
  6860. this.$loop.schedule(this.CHANGE_TEXT);
  6861. this.$textLayer.$updateEolChar();
  6862. };
  6863. this.onChangeTabSize = function() {
  6864. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  6865. this.$textLayer.onChangeTabSize();
  6866. };
  6867. this.updateText = function() {
  6868. this.$loop.schedule(this.CHANGE_TEXT);
  6869. };
  6870. this.updateFull = function(force) {
  6871. if (force)
  6872. this.$renderChanges(this.CHANGE_FULL, true);
  6873. else
  6874. this.$loop.schedule(this.CHANGE_FULL);
  6875. };
  6876. this.updateFontSize = function() {
  6877. this.$textLayer.checkForSizeChanges();
  6878. };
  6879. this.$changes = 0;
  6880. this.$updateSizeAsync = function() {
  6881. if (this.$loop.pending)
  6882. this.$size.$dirty = true;
  6883. else
  6884. this.onResize();
  6885. };
  6886. this.onResize = function(force, gutterWidth, width, height) {
  6887. if (this.resizing > 2)
  6888. return;
  6889. else if (this.resizing > 0)
  6890. this.resizing++;
  6891. else
  6892. this.resizing = force ? 1 : 0;
  6893. var el = this.container;
  6894. if (!height)
  6895. height = el.clientHeight || el.scrollHeight;
  6896. if (!width)
  6897. width = el.clientWidth || el.scrollWidth;
  6898. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  6899. if (!this.$size.scrollerHeight || (!width && !height))
  6900. return this.resizing = 0;
  6901. if (force)
  6902. this.$gutterLayer.$padding = null;
  6903. if (force)
  6904. this.$renderChanges(changes | this.$changes, true);
  6905. else
  6906. this.$loop.schedule(changes | this.$changes);
  6907. if (this.resizing)
  6908. this.resizing = 0;
  6909. };
  6910. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  6911. height -= (this.$extraHeight || 0);
  6912. var changes = 0;
  6913. var size = this.$size;
  6914. var oldSize = {
  6915. width: size.width,
  6916. height: size.height,
  6917. scrollerHeight: size.scrollerHeight,
  6918. scrollerWidth: size.scrollerWidth
  6919. };
  6920. if (height && (force || size.height != height)) {
  6921. size.height = height;
  6922. changes |= this.CHANGE_SIZE;
  6923. size.scrollerHeight = size.height;
  6924. if (this.$horizScroll)
  6925. size.scrollerHeight -= this.scrollBarH.getHeight();
  6926. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  6927. changes = changes | this.CHANGE_SCROLL;
  6928. }
  6929. if (width && (force || size.width != width)) {
  6930. changes |= this.CHANGE_SIZE;
  6931. size.width = width;
  6932. if (gutterWidth == null)
  6933. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  6934. this.gutterWidth = gutterWidth;
  6935. this.scrollBarH.element.style.left =
  6936. this.scroller.style.left = gutterWidth + "px";
  6937. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
  6938. this.scrollBarH.element.style.right =
  6939. this.scroller.style.right = this.scrollBarV.getWidth() + "px";
  6940. this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
  6941. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
  6942. changes |= this.CHANGE_FULL;
  6943. }
  6944. size.$dirty = !width || !height;
  6945. if (changes)
  6946. this._signal("resize", oldSize);
  6947. return changes;
  6948. };
  6949. this.onGutterResize = function() {
  6950. var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  6951. if (gutterWidth != this.gutterWidth)
  6952. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  6953. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  6954. this.$loop.schedule(this.CHANGE_FULL);
  6955. } else if (this.$size.$dirty) {
  6956. this.$loop.schedule(this.CHANGE_FULL);
  6957. } else {
  6958. this.$computeLayerConfig();
  6959. this.$loop.schedule(this.CHANGE_MARKER);
  6960. }
  6961. };
  6962. this.adjustWrapLimit = function() {
  6963. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  6964. var limit = Math.floor(availableWidth / this.characterWidth);
  6965. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  6966. };
  6967. this.setAnimatedScroll = function(shouldAnimate){
  6968. this.setOption("animatedScroll", shouldAnimate);
  6969. };
  6970. this.getAnimatedScroll = function() {
  6971. return this.$animatedScroll;
  6972. };
  6973. this.setShowInvisibles = function(showInvisibles) {
  6974. this.setOption("showInvisibles", showInvisibles);
  6975. };
  6976. this.getShowInvisibles = function() {
  6977. return this.getOption("showInvisibles");
  6978. };
  6979. this.getDisplayIndentGuides = function() {
  6980. return this.getOption("displayIndentGuides");
  6981. };
  6982. this.setDisplayIndentGuides = function(display) {
  6983. this.setOption("displayIndentGuides", display);
  6984. };
  6985. this.setShowPrintMargin = function(showPrintMargin) {
  6986. this.setOption("showPrintMargin", showPrintMargin);
  6987. };
  6988. this.getShowPrintMargin = function() {
  6989. return this.getOption("showPrintMargin");
  6990. };
  6991. this.setPrintMarginColumn = function(showPrintMargin) {
  6992. this.setOption("printMarginColumn", showPrintMargin);
  6993. };
  6994. this.getPrintMarginColumn = function() {
  6995. return this.getOption("printMarginColumn");
  6996. };
  6997. this.getShowGutter = function(){
  6998. return this.getOption("showGutter");
  6999. };
  7000. this.setShowGutter = function(show){
  7001. return this.setOption("showGutter", show);
  7002. };
  7003. this.getFadeFoldWidgets = function(){
  7004. return this.getOption("fadeFoldWidgets")
  7005. };
  7006. this.setFadeFoldWidgets = function(show) {
  7007. this.setOption("fadeFoldWidgets", show);
  7008. };
  7009. this.setHighlightGutterLine = function(shouldHighlight) {
  7010. this.setOption("highlightGutterLine", shouldHighlight);
  7011. };
  7012. this.getHighlightGutterLine = function() {
  7013. return this.getOption("highlightGutterLine");
  7014. };
  7015. this.$updateGutterLineHighlight = function() {
  7016. var pos = this.$cursorLayer.$pixelPos;
  7017. var height = this.layerConfig.lineHeight;
  7018. if (this.session.getUseWrapMode()) {
  7019. var cursor = this.session.selection.getCursor();
  7020. cursor.column = 0;
  7021. pos = this.$cursorLayer.getPixelPosition(cursor, true);
  7022. height *= this.session.getRowLength(cursor.row);
  7023. }
  7024. this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px";
  7025. this.$gutterLineHighlight.style.height = height + "px";
  7026. };
  7027. this.$updatePrintMargin = function() {
  7028. if (!this.$showPrintMargin && !this.$printMarginEl)
  7029. return;
  7030. if (!this.$printMarginEl) {
  7031. var containerEl = dom.createElement("div");
  7032. containerEl.className = "ace_layer ace_print-margin-layer";
  7033. this.$printMarginEl = dom.createElement("div");
  7034. this.$printMarginEl.className = "ace_print-margin";
  7035. containerEl.appendChild(this.$printMarginEl);
  7036. this.content.insertBefore(containerEl, this.content.firstChild);
  7037. }
  7038. var style = this.$printMarginEl.style;
  7039. style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
  7040. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  7041. if (this.session && this.session.$wrap == -1)
  7042. this.adjustWrapLimit();
  7043. };
  7044. this.getContainerElement = function() {
  7045. return this.container;
  7046. };
  7047. this.getMouseEventTarget = function() {
  7048. return this.content;
  7049. };
  7050. this.getTextAreaContainer = function() {
  7051. return this.container;
  7052. };
  7053. this.$moveTextAreaToCursor = function() {
  7054. if (!this.$keepTextAreaAtCursor)
  7055. return;
  7056. var config = this.layerConfig;
  7057. var posTop = this.$cursorLayer.$pixelPos.top;
  7058. var posLeft = this.$cursorLayer.$pixelPos.left;
  7059. posTop -= config.offset;
  7060. var h = this.lineHeight;
  7061. if (posTop < 0 || posTop > config.height - h)
  7062. return;
  7063. var w = this.characterWidth;
  7064. if (this.$composition) {
  7065. var val = this.textarea.value.replace(/^\x01+/, "");
  7066. w *= (this.session.$getStringScreenWidth(val)[0]+2);
  7067. h += 2;
  7068. posTop -= 1;
  7069. }
  7070. posLeft -= this.scrollLeft;
  7071. if (posLeft > this.$size.scrollerWidth - w)
  7072. posLeft = this.$size.scrollerWidth - w;
  7073. posLeft -= this.scrollBar.width;
  7074. this.textarea.style.height = h + "px";
  7075. this.textarea.style.width = w + "px";
  7076. this.textarea.style.right = Math.max(0, this.$size.scrollerWidth - posLeft - w) + "px";
  7077. this.textarea.style.bottom = Math.max(0, this.$size.height - posTop - h) + "px";
  7078. };
  7079. this.getFirstVisibleRow = function() {
  7080. return this.layerConfig.firstRow;
  7081. };
  7082. this.getFirstFullyVisibleRow = function() {
  7083. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  7084. };
  7085. this.getLastFullyVisibleRow = function() {
  7086. var flint = Math.floor((this.layerConfig.height + this.layerConfig.offset) / this.layerConfig.lineHeight);
  7087. return this.layerConfig.firstRow - 1 + flint;
  7088. };
  7089. this.getLastVisibleRow = function() {
  7090. return this.layerConfig.lastRow;
  7091. };
  7092. this.$padding = null;
  7093. this.setPadding = function(padding) {
  7094. this.$padding = padding;
  7095. this.$textLayer.setPadding(padding);
  7096. this.$cursorLayer.setPadding(padding);
  7097. this.$markerFront.setPadding(padding);
  7098. this.$markerBack.setPadding(padding);
  7099. this.$loop.schedule(this.CHANGE_FULL);
  7100. this.$updatePrintMargin();
  7101. };
  7102. this.setScrollMargin = function(top, bottom, left, right) {
  7103. var sm = this.scrollMargin;
  7104. sm.top = top|0;
  7105. sm.bottom = bottom|0;
  7106. sm.right = right|0;
  7107. sm.left = left|0;
  7108. sm.v = sm.top + sm.bottom;
  7109. sm.h = sm.left + sm.right;
  7110. if (sm.top && this.scrollTop <= 0 && this.session)
  7111. this.session.setScrollTop(-sm.top);
  7112. this.updateFull();
  7113. };
  7114. this.getHScrollBarAlwaysVisible = function() {
  7115. return this.$hScrollBarAlwaysVisible;
  7116. };
  7117. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  7118. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  7119. };
  7120. this.getVScrollBarAlwaysVisible = function() {
  7121. return this.$hScrollBarAlwaysVisible;
  7122. };
  7123. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  7124. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  7125. };
  7126. this.$updateScrollBarV = function() {
  7127. var scrollHeight = this.layerConfig.maxHeight;
  7128. var scrollerHeight = this.$size.scrollerHeight;
  7129. if (!this.$maxLines && this.$scrollPastEnd) {
  7130. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  7131. if (this.scrollTop > scrollHeight - scrollerHeight) {
  7132. scrollHeight = this.scrollTop + scrollerHeight;
  7133. this.scrollBarV.scrollTop = null;
  7134. }
  7135. }
  7136. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  7137. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  7138. };
  7139. this.$updateScrollBarH = function() {
  7140. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  7141. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  7142. };
  7143. this.$frozen = false;
  7144. this.freeze = function() {
  7145. this.$frozen = true;
  7146. };
  7147. this.unfreeze = function() {
  7148. this.$frozen = false;
  7149. };
  7150. this.$renderChanges = function(changes, force) {
  7151. if (this.$changes) {
  7152. changes |= this.$changes;
  7153. this.$changes = 0;
  7154. }
  7155. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  7156. this.$changes |= changes;
  7157. return;
  7158. }
  7159. if (this.$size.$dirty) {
  7160. this.$changes |= changes;
  7161. return this.onResize(true);
  7162. }
  7163. if (!this.lineHeight) {
  7164. this.$textLayer.checkForSizeChanges();
  7165. }
  7166. this._signal("beforeRender");
  7167. var config = this.layerConfig;
  7168. if (changes & this.CHANGE_FULL ||
  7169. changes & this.CHANGE_SIZE ||
  7170. changes & this.CHANGE_TEXT ||
  7171. changes & this.CHANGE_LINES ||
  7172. changes & this.CHANGE_SCROLL ||
  7173. changes & this.CHANGE_H_SCROLL
  7174. ) {
  7175. changes |= this.$computeLayerConfig();
  7176. config = this.layerConfig;
  7177. this.$updateScrollBarV();
  7178. if (changes & this.CHANGE_H_SCROLL)
  7179. this.$updateScrollBarH();
  7180. this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
  7181. this.content.style.marginTop = (-config.offset) + "px";
  7182. this.content.style.width = config.width + 2 * this.$padding + "px";
  7183. this.content.style.height = config.minHeight + "px";
  7184. }
  7185. if (changes & this.CHANGE_H_SCROLL) {
  7186. this.content.style.marginLeft = -this.scrollLeft + "px";
  7187. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  7188. }
  7189. if (changes & this.CHANGE_FULL) {
  7190. this.$textLayer.update(config);
  7191. if (this.$showGutter)
  7192. this.$gutterLayer.update(config);
  7193. this.$markerBack.update(config);
  7194. this.$markerFront.update(config);
  7195. this.$cursorLayer.update(config);
  7196. this.$moveTextAreaToCursor();
  7197. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  7198. this._signal("afterRender");
  7199. return;
  7200. }
  7201. if (changes & this.CHANGE_SCROLL) {
  7202. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  7203. this.$textLayer.update(config);
  7204. else
  7205. this.$textLayer.scrollLines(config);
  7206. if (this.$showGutter)
  7207. this.$gutterLayer.update(config);
  7208. this.$markerBack.update(config);
  7209. this.$markerFront.update(config);
  7210. this.$cursorLayer.update(config);
  7211. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  7212. this.$moveTextAreaToCursor();
  7213. this._signal("afterRender");
  7214. return;
  7215. }
  7216. if (changes & this.CHANGE_TEXT) {
  7217. this.$textLayer.update(config);
  7218. if (this.$showGutter)
  7219. this.$gutterLayer.update(config);
  7220. }
  7221. else if (changes & this.CHANGE_LINES) {
  7222. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  7223. this.$gutterLayer.update(config);
  7224. }
  7225. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  7226. if (this.$showGutter)
  7227. this.$gutterLayer.update(config);
  7228. }
  7229. if (changes & this.CHANGE_CURSOR) {
  7230. this.$cursorLayer.update(config);
  7231. this.$moveTextAreaToCursor();
  7232. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  7233. }
  7234. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  7235. this.$markerFront.update(config);
  7236. }
  7237. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  7238. this.$markerBack.update(config);
  7239. }
  7240. this._signal("afterRender");
  7241. };
  7242. this.$autosize = function() {
  7243. var height = this.session.getScreenLength() * this.lineHeight;
  7244. var maxHeight = this.$maxLines * this.lineHeight;
  7245. var desiredHeight = Math.max(
  7246. (this.$minLines||1) * this.lineHeight,
  7247. Math.min(maxHeight, height)
  7248. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  7249. var vScroll = height > maxHeight;
  7250. if (desiredHeight != this.desiredHeight ||
  7251. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  7252. if (vScroll != this.$vScroll) {
  7253. this.$vScroll = vScroll;
  7254. this.scrollBarV.setVisible(vScroll);
  7255. }
  7256. var w = this.container.clientWidth;
  7257. this.container.style.height = desiredHeight + "px";
  7258. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  7259. this.desiredHeight = desiredHeight;
  7260. }
  7261. };
  7262. this.$computeLayerConfig = function() {
  7263. if (this.$maxLines && this.lineHeight > 1)
  7264. this.$autosize();
  7265. var session = this.session;
  7266. var size = this.$size;
  7267. var hideScrollbars = size.height <= 2 * this.lineHeight;
  7268. var screenLines = this.session.getScreenLength();
  7269. var maxHeight = screenLines * this.lineHeight;
  7270. var offset = this.scrollTop % this.lineHeight;
  7271. var minHeight = size.scrollerHeight + this.lineHeight;
  7272. var longestLine = this.$getLongestLine();
  7273. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  7274. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  7275. var hScrollChanged = this.$horizScroll !== horizScroll;
  7276. if (hScrollChanged) {
  7277. this.$horizScroll = horizScroll;
  7278. this.scrollBarH.setVisible(horizScroll);
  7279. }
  7280. if (!this.$maxLines && this.$scrollPastEnd) {
  7281. maxHeight += (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  7282. }
  7283. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  7284. size.scrollerHeight - maxHeight < 0);
  7285. var vScrollChanged = this.$vScroll !== vScroll;
  7286. if (vScrollChanged) {
  7287. this.$vScroll = vScroll;
  7288. this.scrollBarV.setVisible(vScroll);
  7289. }
  7290. this.session.setScrollTop(Math.max(-this.scrollMargin.top,
  7291. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + this.scrollMargin.bottom)));
  7292. this.session.setScrollLeft(Math.max(-this.scrollMargin.left, Math.min(this.scrollLeft,
  7293. longestLine + 2 * this.$padding - size.scrollerWidth + this.scrollMargin.right)));
  7294. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  7295. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  7296. var lastRow = firstRow + lineCount;
  7297. var firstRowScreen, firstRowHeight;
  7298. var lineHeight = this.lineHeight;
  7299. firstRow = session.screenToDocumentRow(firstRow, 0);
  7300. var foldLine = session.getFoldLine(firstRow);
  7301. if (foldLine) {
  7302. firstRow = foldLine.start.row;
  7303. }
  7304. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  7305. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  7306. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  7307. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  7308. firstRowHeight;
  7309. offset = this.scrollTop - firstRowScreen * lineHeight;
  7310. var changes = 0;
  7311. if (this.layerConfig.width != longestLine)
  7312. changes = this.CHANGE_H_SCROLL;
  7313. if (hScrollChanged || vScrollChanged) {
  7314. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  7315. this._signal("scrollbarVisibilityChanged");
  7316. if (vScrollChanged)
  7317. longestLine = this.$getLongestLine();
  7318. }
  7319. this.layerConfig = {
  7320. width : longestLine,
  7321. padding : this.$padding,
  7322. firstRow : firstRow,
  7323. firstRowScreen: firstRowScreen,
  7324. lastRow : lastRow,
  7325. lineHeight : lineHeight,
  7326. characterWidth : this.characterWidth,
  7327. minHeight : minHeight,
  7328. maxHeight : maxHeight,
  7329. offset : offset,
  7330. gutterOffset : Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)),
  7331. height : this.$size.scrollerHeight
  7332. };
  7333. return changes;
  7334. };
  7335. this.$updateLines = function() {
  7336. var firstRow = this.$changedLines.firstRow;
  7337. var lastRow = this.$changedLines.lastRow;
  7338. this.$changedLines = null;
  7339. var layerConfig = this.layerConfig;
  7340. if (firstRow > layerConfig.lastRow + 1) { return; }
  7341. if (lastRow < layerConfig.firstRow) { return; }
  7342. if (lastRow === Infinity) {
  7343. if (this.$showGutter)
  7344. this.$gutterLayer.update(layerConfig);
  7345. this.$textLayer.update(layerConfig);
  7346. return;
  7347. }
  7348. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  7349. return true;
  7350. };
  7351. this.$getLongestLine = function() {
  7352. var charCount = this.session.getScreenWidth();
  7353. if (this.showInvisibles && !this.session.$useWrapMode)
  7354. charCount += 1;
  7355. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  7356. };
  7357. this.updateFrontMarkers = function() {
  7358. this.$markerFront.setMarkers(this.session.getMarkers(true));
  7359. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  7360. };
  7361. this.updateBackMarkers = function() {
  7362. this.$markerBack.setMarkers(this.session.getMarkers());
  7363. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  7364. };
  7365. this.addGutterDecoration = function(row, className){
  7366. this.$gutterLayer.addGutterDecoration(row, className);
  7367. };
  7368. this.removeGutterDecoration = function(row, className){
  7369. this.$gutterLayer.removeGutterDecoration(row, className);
  7370. };
  7371. this.updateBreakpoints = function(rows) {
  7372. this.$loop.schedule(this.CHANGE_GUTTER);
  7373. };
  7374. this.setAnnotations = function(annotations) {
  7375. this.$gutterLayer.setAnnotations(annotations);
  7376. this.$loop.schedule(this.CHANGE_GUTTER);
  7377. };
  7378. this.updateCursor = function() {
  7379. this.$loop.schedule(this.CHANGE_CURSOR);
  7380. };
  7381. this.hideCursor = function() {
  7382. this.$cursorLayer.hideCursor();
  7383. };
  7384. this.showCursor = function() {
  7385. this.$cursorLayer.showCursor();
  7386. };
  7387. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  7388. this.scrollCursorIntoView(anchor, offset);
  7389. this.scrollCursorIntoView(lead, offset);
  7390. };
  7391. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  7392. if (this.$size.scrollerHeight === 0)
  7393. return;
  7394. var pos = this.$cursorLayer.getPixelPosition(cursor);
  7395. var left = pos.left;
  7396. var top = pos.top;
  7397. var topMargin = $viewMargin && $viewMargin.top || 0;
  7398. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  7399. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  7400. if (scrollTop + topMargin > top) {
  7401. if (offset)
  7402. top -= offset * this.$size.scrollerHeight;
  7403. if (top === 0)
  7404. top = -this.scrollMargin.top;
  7405. this.session.setScrollTop(top);
  7406. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  7407. if (offset)
  7408. top += offset * this.$size.scrollerHeight;
  7409. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  7410. }
  7411. var scrollLeft = this.scrollLeft;
  7412. if (scrollLeft > left) {
  7413. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  7414. left = -this.scrollMargin.left;
  7415. this.session.setScrollLeft(left);
  7416. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  7417. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  7418. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  7419. this.session.setScrollLeft(0);
  7420. }
  7421. };
  7422. this.getScrollTop = function() {
  7423. return this.session.getScrollTop();
  7424. };
  7425. this.getScrollLeft = function() {
  7426. return this.session.getScrollLeft();
  7427. };
  7428. this.getScrollTopRow = function() {
  7429. return this.scrollTop / this.lineHeight;
  7430. };
  7431. this.getScrollBottomRow = function() {
  7432. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  7433. };
  7434. this.scrollToRow = function(row) {
  7435. this.session.setScrollTop(row * this.lineHeight);
  7436. };
  7437. this.alignCursor = function(cursor, alignment) {
  7438. if (typeof cursor == "number")
  7439. cursor = {row: cursor, column: 0};
  7440. var pos = this.$cursorLayer.getPixelPosition(cursor);
  7441. var h = this.$size.scrollerHeight - this.lineHeight;
  7442. var offset = pos.top - h * (alignment || 0);
  7443. this.session.setScrollTop(offset);
  7444. return offset;
  7445. };
  7446. this.STEPS = 8;
  7447. this.$calcSteps = function(fromValue, toValue){
  7448. var i = 0;
  7449. var l = this.STEPS;
  7450. var steps = [];
  7451. var func = function(t, x_min, dx) {
  7452. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  7453. };
  7454. for (i = 0; i < l; ++i)
  7455. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  7456. return steps;
  7457. };
  7458. this.scrollToLine = function(line, center, animate, callback) {
  7459. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  7460. var offset = pos.top;
  7461. if (center)
  7462. offset -= this.$size.scrollerHeight / 2;
  7463. var initialScroll = this.scrollTop;
  7464. this.session.setScrollTop(offset);
  7465. if (animate !== false)
  7466. this.animateScrolling(initialScroll, callback);
  7467. };
  7468. this.animateScrolling = function(fromValue, callback) {
  7469. var toValue = this.scrollTop;
  7470. if (!this.$animatedScroll)
  7471. return;
  7472. var _self = this;
  7473. if (fromValue == toValue)
  7474. return;
  7475. if (this.$scrollAnimation) {
  7476. var oldSteps = this.$scrollAnimation.steps;
  7477. if (oldSteps.length) {
  7478. fromValue = oldSteps[0];
  7479. if (fromValue == toValue)
  7480. return;
  7481. }
  7482. }
  7483. var steps = _self.$calcSteps(fromValue, toValue);
  7484. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  7485. clearInterval(this.$timer);
  7486. _self.session.setScrollTop(steps.shift());
  7487. _self.session.$scrollTop = toValue;
  7488. this.$timer = setInterval(function() {
  7489. if (steps.length) {
  7490. _self.session.setScrollTop(steps.shift());
  7491. _self.session.$scrollTop = toValue;
  7492. } else if (toValue != null) {
  7493. _self.session.$scrollTop = -1;
  7494. _self.session.setScrollTop(toValue);
  7495. toValue = null;
  7496. } else {
  7497. _self.$timer = clearInterval(_self.$timer);
  7498. _self.$scrollAnimation = null;
  7499. callback && callback();
  7500. }
  7501. }, 10);
  7502. };
  7503. this.scrollToY = function(scrollTop) {
  7504. if (this.scrollTop !== scrollTop) {
  7505. this.$loop.schedule(this.CHANGE_SCROLL);
  7506. this.scrollTop = scrollTop;
  7507. }
  7508. };
  7509. this.scrollToX = function(scrollLeft) {
  7510. if (this.scrollLeft !== scrollLeft)
  7511. this.scrollLeft = scrollLeft;
  7512. this.$loop.schedule(this.CHANGE_H_SCROLL);
  7513. };
  7514. this.scrollTo = function(x, y) {
  7515. this.session.setScrollTop(y);
  7516. this.session.setScrollLeft(y);
  7517. };
  7518. this.scrollBy = function(deltaX, deltaY) {
  7519. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  7520. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  7521. };
  7522. this.isScrollableBy = function(deltaX, deltaY) {
  7523. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  7524. return true;
  7525. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  7526. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  7527. return true;
  7528. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  7529. return true;
  7530. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  7531. - this.layerConfig.width < -1 + this.scrollMargin.right)
  7532. return true;
  7533. };
  7534. this.pixelToScreenCoordinates = function(x, y) {
  7535. var canvasPos = this.scroller.getBoundingClientRect();
  7536. var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth;
  7537. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  7538. var col = Math.round(offset);
  7539. return {row: row, column: col, side: offset - col > 0 ? 1 : -1};
  7540. };
  7541. this.screenToTextCoordinates = function(x, y) {
  7542. var canvasPos = this.scroller.getBoundingClientRect();
  7543. var col = Math.round(
  7544. (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
  7545. );
  7546. var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
  7547. return this.session.screenToDocumentPosition(row, Math.max(col, 0));
  7548. };
  7549. this.textToScreenCoordinates = function(row, column) {
  7550. var canvasPos = this.scroller.getBoundingClientRect();
  7551. var pos = this.session.documentToScreenPosition(row, column);
  7552. var x = this.$padding + Math.round(pos.column * this.characterWidth);
  7553. var y = pos.row * this.lineHeight;
  7554. return {
  7555. pageX: canvasPos.left + x - this.scrollLeft,
  7556. pageY: canvasPos.top + y - this.scrollTop
  7557. };
  7558. };
  7559. this.visualizeFocus = function() {
  7560. dom.addCssClass(this.container, "ace_focus");
  7561. };
  7562. this.visualizeBlur = function() {
  7563. dom.removeCssClass(this.container, "ace_focus");
  7564. };
  7565. this.showComposition = function(position) {
  7566. if (!this.$composition)
  7567. this.$composition = {
  7568. keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
  7569. cssText: this.textarea.style.cssText
  7570. };
  7571. this.$keepTextAreaAtCursor = true;
  7572. dom.addCssClass(this.textarea, "ace_composition");
  7573. this.textarea.style.cssText = "";
  7574. this.$moveTextAreaToCursor();
  7575. };
  7576. this.setCompositionText = function(text) {
  7577. this.$moveTextAreaToCursor();
  7578. };
  7579. this.hideComposition = function() {
  7580. if (!this.$composition)
  7581. return;
  7582. dom.removeCssClass(this.textarea, "ace_composition");
  7583. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  7584. this.textarea.style.cssText = this.$composition.cssText;
  7585. this.$composition = null;
  7586. };
  7587. this.setTheme = function(theme, cb) {
  7588. var _self = this;
  7589. this.$themeId = theme;
  7590. _self._dispatchEvent('themeChange',{theme:theme});
  7591. if (!theme || typeof theme == "string") {
  7592. var moduleName = theme || this.$options.theme.initialValue;
  7593. config.loadModule(["theme", moduleName], afterLoad);
  7594. } else {
  7595. afterLoad(theme);
  7596. }
  7597. function afterLoad(module) {
  7598. if (_self.$themeId != theme)
  7599. return cb && cb();
  7600. if (!module.cssClass)
  7601. return;
  7602. dom.importCssString(
  7603. module.cssText,
  7604. module.cssClass,
  7605. _self.container.ownerDocument
  7606. );
  7607. if (_self.theme)
  7608. dom.removeCssClass(_self.container, _self.theme.cssClass);
  7609. var padding = "padding" in module ? module.padding
  7610. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  7611. if (_self.$padding && padding != _self.$padding)
  7612. _self.setPadding(padding);
  7613. _self.$theme = module.cssClass;
  7614. _self.theme = module;
  7615. dom.addCssClass(_self.container, module.cssClass);
  7616. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  7617. if (_self.$size) {
  7618. _self.$size.width = 0;
  7619. _self.$updateSizeAsync();
  7620. }
  7621. _self._dispatchEvent('themeLoaded', {theme:module});
  7622. cb && cb();
  7623. }
  7624. };
  7625. this.getTheme = function() {
  7626. return this.$themeId;
  7627. };
  7628. this.setStyle = function(style, include) {
  7629. dom.setCssClass(this.container, style, include !== false);
  7630. };
  7631. this.unsetStyle = function(style) {
  7632. dom.removeCssClass(this.container, style);
  7633. };
  7634. this.setCursorStyle = function(style) {
  7635. if (this.content.style.cursor != style)
  7636. this.content.style.cursor = style;
  7637. };
  7638. this.setMouseCursor = function(cursorStyle) {
  7639. this.content.style.cursor = cursorStyle;
  7640. };
  7641. this.destroy = function() {
  7642. this.$textLayer.destroy();
  7643. this.$cursorLayer.destroy();
  7644. };
  7645. }).call(VirtualRenderer.prototype);
  7646. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  7647. animatedScroll: {initialValue: false},
  7648. showInvisibles: {
  7649. set: function(value) {
  7650. if (this.$textLayer.setShowInvisibles(value))
  7651. this.$loop.schedule(this.CHANGE_TEXT);
  7652. },
  7653. initialValue: false
  7654. },
  7655. showPrintMargin: {
  7656. set: function() { this.$updatePrintMargin(); },
  7657. initialValue: true
  7658. },
  7659. printMarginColumn: {
  7660. set: function() { this.$updatePrintMargin(); },
  7661. initialValue: 80
  7662. },
  7663. printMargin: {
  7664. set: function(val) {
  7665. if (typeof val == "number")
  7666. this.$printMarginColumn = val;
  7667. this.$showPrintMargin = !!val;
  7668. this.$updatePrintMargin();
  7669. },
  7670. get: function() {
  7671. return this.$showPrintMargin && this.$printMarginColumn;
  7672. }
  7673. },
  7674. showGutter: {
  7675. set: function(show){
  7676. this.$gutter.style.display = show ? "block" : "none";
  7677. this.$loop.schedule(this.CHANGE_FULL);
  7678. this.onGutterResize();
  7679. },
  7680. initialValue: true
  7681. },
  7682. fadeFoldWidgets: {
  7683. set: function(show) {
  7684. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  7685. },
  7686. initialValue: false
  7687. },
  7688. showFoldWidgets: {
  7689. set: function(show) {this.$gutterLayer.setShowFoldWidgets(show)},
  7690. initialValue: true
  7691. },
  7692. showLineNumbers: {
  7693. set: function(show) {
  7694. this.$gutterLayer.setShowLineNumbers(show);
  7695. this.$loop.schedule(this.CHANGE_GUTTER);
  7696. },
  7697. initialValue: true
  7698. },
  7699. displayIndentGuides: {
  7700. set: function(show) {
  7701. if (this.$textLayer.setDisplayIndentGuides(show))
  7702. this.$loop.schedule(this.CHANGE_TEXT);
  7703. },
  7704. initialValue: true
  7705. },
  7706. highlightGutterLine: {
  7707. set: function(shouldHighlight) {
  7708. if (!this.$gutterLineHighlight) {
  7709. this.$gutterLineHighlight = dom.createElement("div");
  7710. this.$gutterLineHighlight.className = "ace_gutter-active-line";
  7711. this.$gutter.appendChild(this.$gutterLineHighlight);
  7712. return;
  7713. }
  7714. this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
  7715. if (this.$cursorLayer.$pixelPos)
  7716. this.$updateGutterLineHighlight();
  7717. },
  7718. initialValue: false,
  7719. value: true
  7720. },
  7721. hScrollBarAlwaysVisible: {
  7722. set: function(val) {
  7723. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  7724. this.$loop.schedule(this.CHANGE_SCROLL);
  7725. },
  7726. initialValue: false
  7727. },
  7728. vScrollBarAlwaysVisible: {
  7729. set: function(val) {
  7730. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  7731. this.$loop.schedule(this.CHANGE_SCROLL);
  7732. },
  7733. initialValue: false
  7734. },
  7735. fontSize: {
  7736. set: function(size) {
  7737. if (typeof size == "number")
  7738. size = size + "px";
  7739. this.container.style.fontSize = size;
  7740. this.updateFontSize();
  7741. },
  7742. initialValue: 12
  7743. },
  7744. fontFamily: {
  7745. set: function(name) {
  7746. this.container.style.fontFamily = name;
  7747. this.updateFontSize();
  7748. }
  7749. },
  7750. maxLines: {
  7751. set: function(val) {
  7752. this.updateFull();
  7753. }
  7754. },
  7755. minLines: {
  7756. set: function(val) {
  7757. this.updateFull();
  7758. }
  7759. },
  7760. scrollPastEnd: {
  7761. set: function(val) {
  7762. val = +val || 0;
  7763. if (this.$scrollPastEnd == val)
  7764. return;
  7765. this.$scrollPastEnd = val;
  7766. this.$loop.schedule(this.CHANGE_SCROLL);
  7767. },
  7768. initialValue: 0,
  7769. handlesSet: true
  7770. },
  7771. fixedWidthGutter: {
  7772. set: function(val) {
  7773. this.$gutterLayer.$fixedWidth = !!val;
  7774. this.$loop.schedule(this.CHANGE_GUTTER);
  7775. }
  7776. },
  7777. theme: {
  7778. set: function(val) { this.setTheme(val) },
  7779. get: function() { return this.$themeId || this.theme; },
  7780. initialValue: "./theme/textmate",
  7781. handlesSet: true
  7782. }
  7783. });
  7784. exports.VirtualRenderer = VirtualRenderer;
  7785. });
  7786. ace.define('ace/config', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/lib/oop', 'ace/lib/net', 'ace/lib/event_emitter'], function(require, exports, module) {
  7787. "no use strict";
  7788. var lang = require("./lib/lang");
  7789. var oop = require("./lib/oop");
  7790. var net = require("./lib/net");
  7791. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  7792. var global = (function() {
  7793. return this;
  7794. })();
  7795. var options = {
  7796. packaged: false,
  7797. workerPath: null,
  7798. modePath: null,
  7799. themePath: null,
  7800. basePath: "",
  7801. suffix: ".js",
  7802. $moduleUrls: {}
  7803. };
  7804. exports.get = function(key) {
  7805. if (!options.hasOwnProperty(key))
  7806. throw new Error("Unknown config key: " + key);
  7807. return options[key];
  7808. };
  7809. exports.set = function(key, value) {
  7810. if (!options.hasOwnProperty(key))
  7811. throw new Error("Unknown config key: " + key);
  7812. options[key] = value;
  7813. };
  7814. exports.all = function() {
  7815. return lang.copyObject(options);
  7816. };
  7817. oop.implement(exports, EventEmitter);
  7818. exports.moduleUrl = function(name, component) {
  7819. if (options.$moduleUrls[name])
  7820. return options.$moduleUrls[name];
  7821. var parts = name.split("/");
  7822. component = component || parts[parts.length - 2] || "";
  7823. var sep = component == "snippets" ? "/" : "-";
  7824. var base = parts[parts.length - 1];
  7825. if (sep == "-") {
  7826. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  7827. base = base.replace(re, "");
  7828. }
  7829. if ((!base || base == component) && parts.length > 1)
  7830. base = parts[parts.length - 2];
  7831. var path = options[component + "Path"];
  7832. if (path == null) {
  7833. path = options.basePath;
  7834. } else if (sep == "/") {
  7835. component = sep = "";
  7836. }
  7837. if (path && path.slice(-1) != "/")
  7838. path += "/";
  7839. return path + component + sep + base + this.get("suffix");
  7840. };
  7841. exports.setModuleUrl = function(name, subst) {
  7842. return options.$moduleUrls[name] = subst;
  7843. };
  7844. exports.$loading = {};
  7845. exports.loadModule = function(moduleName, onLoad) {
  7846. var module, moduleType;
  7847. if (Array.isArray(moduleName)) {
  7848. moduleType = moduleName[0];
  7849. moduleName = moduleName[1];
  7850. }
  7851. try {
  7852. module = require(moduleName);
  7853. } catch (e) {}
  7854. if (module && !exports.$loading[moduleName])
  7855. return onLoad && onLoad(module);
  7856. if (!exports.$loading[moduleName])
  7857. exports.$loading[moduleName] = [];
  7858. exports.$loading[moduleName].push(onLoad);
  7859. if (exports.$loading[moduleName].length > 1)
  7860. return;
  7861. var afterLoad = function() {
  7862. require([moduleName], function(module) {
  7863. exports._emit("load.module", {name: moduleName, module: module});
  7864. var listeners = exports.$loading[moduleName];
  7865. exports.$loading[moduleName] = null;
  7866. listeners.forEach(function(onLoad) {
  7867. onLoad && onLoad(module);
  7868. });
  7869. });
  7870. };
  7871. if (!exports.get("packaged"))
  7872. return afterLoad();
  7873. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  7874. };
  7875. init(true);function init(packaged) {
  7876. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  7877. if (!global.document)
  7878. return "";
  7879. var scriptOptions = {};
  7880. var scriptUrl = "";
  7881. var scripts = document.getElementsByTagName("script");
  7882. for (var i=0; i<scripts.length; i++) {
  7883. var script = scripts[i];
  7884. var src = script.src || script.getAttribute("src");
  7885. if (!src)
  7886. continue;
  7887. var attributes = script.attributes;
  7888. for (var j=0, l=attributes.length; j < l; j++) {
  7889. var attr = attributes[j];
  7890. if (attr.name.indexOf("data-ace-") === 0) {
  7891. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  7892. }
  7893. }
  7894. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  7895. if (m)
  7896. scriptUrl = m[1];
  7897. }
  7898. if (scriptUrl) {
  7899. scriptOptions.base = scriptOptions.base || scriptUrl;
  7900. scriptOptions.packaged = true;
  7901. }
  7902. scriptOptions.basePath = scriptOptions.base;
  7903. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  7904. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  7905. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  7906. delete scriptOptions.base;
  7907. for (var key in scriptOptions)
  7908. if (typeof scriptOptions[key] !== "undefined")
  7909. exports.set(key, scriptOptions[key]);
  7910. };
  7911. exports.init = init;
  7912. function deHyphenate(str) {
  7913. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  7914. }
  7915. var optionsProvider = {
  7916. setOptions: function(optList) {
  7917. Object.keys(optList).forEach(function(key) {
  7918. this.setOption(key, optList[key]);
  7919. }, this);
  7920. },
  7921. getOptions: function(optionNames) {
  7922. var result = {};
  7923. if (!optionNames) {
  7924. optionNames = Object.keys(this.$options);
  7925. } else if (!Array.isArray(optionNames)) {
  7926. result = optionNames;
  7927. optionNames = Object.keys(result);
  7928. }
  7929. optionNames.forEach(function(key) {
  7930. result[key] = this.getOption(key);
  7931. }, this);
  7932. return result;
  7933. },
  7934. setOption: function(name, value) {
  7935. if (this["$" + name] === value)
  7936. return;
  7937. var opt = this.$options[name];
  7938. if (!opt) {
  7939. if (typeof console != "undefined" && console.warn)
  7940. console.warn('misspelled option "' + name + '"');
  7941. return undefined;
  7942. }
  7943. if (opt.forwardTo)
  7944. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  7945. if (!opt.handlesSet)
  7946. this["$" + name] = value;
  7947. if (opt && opt.set)
  7948. opt.set.call(this, value);
  7949. },
  7950. getOption: function(name) {
  7951. var opt = this.$options[name];
  7952. if (!opt) {
  7953. if (typeof console != "undefined" && console.warn)
  7954. console.warn('misspelled option "' + name + '"');
  7955. return undefined;
  7956. }
  7957. if (opt.forwardTo)
  7958. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  7959. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  7960. }
  7961. };
  7962. var defaultOptions = {};
  7963. exports.defineOptions = function(obj, path, options) {
  7964. if (!obj.$options)
  7965. defaultOptions[path] = obj.$options = {};
  7966. Object.keys(options).forEach(function(key) {
  7967. var opt = options[key];
  7968. if (typeof opt == "string")
  7969. opt = {forwardTo: opt};
  7970. opt.name || (opt.name = key);
  7971. obj.$options[opt.name] = opt;
  7972. if ("initialValue" in opt)
  7973. obj["$" + opt.name] = opt.initialValue;
  7974. });
  7975. oop.implement(obj, optionsProvider);
  7976. return this;
  7977. };
  7978. exports.resetOptions = function(obj) {
  7979. Object.keys(obj.$options).forEach(function(key) {
  7980. var opt = obj.$options[key];
  7981. if ("value" in opt)
  7982. obj.setOption(key, opt.value);
  7983. });
  7984. };
  7985. exports.setDefaultValue = function(path, name, value) {
  7986. var opts = defaultOptions[path] || (defaultOptions[path] = {});
  7987. if (opts[name]) {
  7988. if (opts.forwardTo)
  7989. exports.setDefaultValue(opts.forwardTo, name, value);
  7990. else
  7991. opts[name].value = value;
  7992. }
  7993. };
  7994. exports.setDefaultValues = function(path, optionHash) {
  7995. Object.keys(optionHash).forEach(function(key) {
  7996. exports.setDefaultValue(path, key, optionHash[key]);
  7997. });
  7998. };
  7999. });
  8000. ace.define('ace/layer/gutter', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/oop', 'ace/lib/lang', 'ace/lib/event_emitter'], function(require, exports, module) {
  8001. var dom = require("../lib/dom");
  8002. var oop = require("../lib/oop");
  8003. var lang = require("../lib/lang");
  8004. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  8005. var Gutter = function(parentEl) {
  8006. this.element = dom.createElement("div");
  8007. this.element.className = "ace_layer ace_gutter-layer";
  8008. parentEl.appendChild(this.element);
  8009. this.setShowFoldWidgets(this.$showFoldWidgets);
  8010. this.gutterWidth = 0;
  8011. this.$annotations = [];
  8012. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  8013. this.$cells = [];
  8014. };
  8015. (function() {
  8016. oop.implement(this, EventEmitter);
  8017. this.setSession = function(session) {
  8018. if (this.session)
  8019. this.session.removeEventListener("change", this.$updateAnnotations);
  8020. this.session = session;
  8021. session.on("change", this.$updateAnnotations);
  8022. };
  8023. this.addGutterDecoration = function(row, className){
  8024. if (window.console)
  8025. console.warn && console.warn("deprecated use session.addGutterDecoration");
  8026. this.session.addGutterDecoration(row, className);
  8027. };
  8028. this.removeGutterDecoration = function(row, className){
  8029. if (window.console)
  8030. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  8031. this.session.removeGutterDecoration(row, className);
  8032. };
  8033. this.setAnnotations = function(annotations) {
  8034. this.$annotations = [];
  8035. for (var i = 0; i < annotations.length; i++) {
  8036. var annotation = annotations[i];
  8037. var row = annotation.row;
  8038. var rowInfo = this.$annotations[row];
  8039. if (!rowInfo)
  8040. rowInfo = this.$annotations[row] = {text: []};
  8041. var annoText = annotation.text;
  8042. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  8043. if (rowInfo.text.indexOf(annoText) === -1)
  8044. rowInfo.text.push(annoText);
  8045. var type = annotation.type;
  8046. if (type == "error")
  8047. rowInfo.className = " ace_error";
  8048. else if (type == "warning" && rowInfo.className != " ace_error")
  8049. rowInfo.className = " ace_warning";
  8050. else if (type == "info" && (!rowInfo.className))
  8051. rowInfo.className = " ace_info";
  8052. }
  8053. };
  8054. this.$updateAnnotations = function (e) {
  8055. if (!this.$annotations.length)
  8056. return;
  8057. var delta = e.data;
  8058. var range = delta.range;
  8059. var firstRow = range.start.row;
  8060. var len = range.end.row - firstRow;
  8061. if (len === 0) {
  8062. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  8063. this.$annotations.splice(firstRow, len + 1, null);
  8064. } else {
  8065. var args = new Array(len + 1);
  8066. args.unshift(firstRow, 1);
  8067. this.$annotations.splice.apply(this.$annotations, args);
  8068. }
  8069. };
  8070. this.update = function(config) {
  8071. var session = this.session;
  8072. var firstRow = config.firstRow;
  8073. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  8074. session.getLength() - 1);
  8075. var fold = session.getNextFoldLine(firstRow);
  8076. var foldStart = fold ? fold.start.row : Infinity;
  8077. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  8078. var breakpoints = session.$breakpoints;
  8079. var decorations = session.$decorations;
  8080. var firstLineNumber = session.$firstLineNumber;
  8081. var lastLineNumber = 0;
  8082. var gutterRenderer = session.gutterRenderer || this.$renderer;
  8083. var cell = null;
  8084. var index = -1;
  8085. var row = firstRow;
  8086. while (true) {
  8087. if (row > foldStart) {
  8088. row = fold.end.row + 1;
  8089. fold = session.getNextFoldLine(row, fold);
  8090. foldStart = fold ? fold.start.row : Infinity;
  8091. }
  8092. if (row > lastRow) {
  8093. while (this.$cells.length > index + 1) {
  8094. cell = this.$cells.pop();
  8095. this.element.removeChild(cell.element);
  8096. }
  8097. break;
  8098. }
  8099. cell = this.$cells[++index];
  8100. if (!cell) {
  8101. cell = {element: null, textNode: null, foldWidget: null};
  8102. cell.element = dom.createElement("div");
  8103. cell.textNode = document.createTextNode('');
  8104. cell.element.appendChild(cell.textNode);
  8105. this.element.appendChild(cell.element);
  8106. this.$cells[index] = cell;
  8107. }
  8108. var className = "ace_gutter-cell ";
  8109. if (breakpoints[row])
  8110. className += breakpoints[row];
  8111. if (decorations[row])
  8112. className += decorations[row];
  8113. if (this.$annotations[row])
  8114. className += this.$annotations[row].className;
  8115. if (cell.element.className != className)
  8116. cell.element.className = className;
  8117. var height = session.getRowLength(row) * config.lineHeight + "px";
  8118. if (height != cell.element.style.height)
  8119. cell.element.style.height = height;
  8120. if (foldWidgets) {
  8121. var c = foldWidgets[row];
  8122. if (c == null)
  8123. c = foldWidgets[row] = session.getFoldWidget(row);
  8124. }
  8125. if (c) {
  8126. if (!cell.foldWidget) {
  8127. cell.foldWidget = dom.createElement("span");
  8128. cell.element.appendChild(cell.foldWidget);
  8129. }
  8130. var className = "ace_fold-widget ace_" + c;
  8131. if (c == "start" && row == foldStart && row < fold.end.row)
  8132. className += " ace_closed";
  8133. else
  8134. className += " ace_open";
  8135. if (cell.foldWidget.className != className)
  8136. cell.foldWidget.className = className;
  8137. var height = config.lineHeight + "px";
  8138. if (cell.foldWidget.style.height != height)
  8139. cell.foldWidget.style.height = height;
  8140. } else {
  8141. if (cell.foldWidget) {
  8142. cell.element.removeChild(cell.foldWidget);
  8143. cell.foldWidget = null;
  8144. }
  8145. }
  8146. var text = lastLineNumber = gutterRenderer
  8147. ? gutterRenderer.getText(session, row)
  8148. : row + firstLineNumber;
  8149. if (text != cell.textNode.data)
  8150. cell.textNode.data = text;
  8151. row++;
  8152. }
  8153. this.element.style.height = config.minHeight + "px";
  8154. if (this.$fixedWidth || session.$useWrapMode)
  8155. lastLineNumber = session.getLength() + firstLineNumber;
  8156. var gutterWidth = gutterRenderer
  8157. ? gutterRenderer.getWidth(session, lastLineNumber, config)
  8158. : lastLineNumber.toString().length * config.characterWidth;
  8159. var padding = this.$padding || this.$computePadding();
  8160. gutterWidth += padding.left + padding.right;
  8161. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  8162. this.gutterWidth = gutterWidth;
  8163. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  8164. this._emit("changeGutterWidth", gutterWidth);
  8165. }
  8166. };
  8167. this.$fixedWidth = false;
  8168. this.$showLineNumbers = true;
  8169. this.$renderer = "";
  8170. this.setShowLineNumbers = function(show) {
  8171. this.$renderer = !show && {
  8172. getWidth: function() {return ""},
  8173. getText: function() {return ""}
  8174. };
  8175. };
  8176. this.getShowLineNumbers = function() {
  8177. return this.$showLineNumbers;
  8178. };
  8179. this.$showFoldWidgets = true;
  8180. this.setShowFoldWidgets = function(show) {
  8181. if (show)
  8182. dom.addCssClass(this.element, "ace_folding-enabled");
  8183. else
  8184. dom.removeCssClass(this.element, "ace_folding-enabled");
  8185. this.$showFoldWidgets = show;
  8186. this.$padding = null;
  8187. };
  8188. this.getShowFoldWidgets = function() {
  8189. return this.$showFoldWidgets;
  8190. };
  8191. this.$computePadding = function() {
  8192. if (!this.element.firstChild)
  8193. return {left: 0, right: 0};
  8194. var style = dom.computedStyle(this.element.firstChild);
  8195. this.$padding = {};
  8196. this.$padding.left = parseInt(style.paddingLeft) + 1 || 0;
  8197. this.$padding.right = parseInt(style.paddingRight) || 0;
  8198. return this.$padding;
  8199. };
  8200. this.getRegion = function(point) {
  8201. var padding = this.$padding || this.$computePadding();
  8202. var rect = this.element.getBoundingClientRect();
  8203. if (point.x < padding.left + rect.left)
  8204. return "markers";
  8205. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  8206. return "foldWidgets";
  8207. };
  8208. }).call(Gutter.prototype);
  8209. exports.Gutter = Gutter;
  8210. });
  8211. ace.define('ace/mouse/dragdrop_handler', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/event', 'ace/lib/useragent'], function(require, exports, module) {
  8212. var dom = require("../lib/dom");
  8213. var event = require("../lib/event");
  8214. var useragent = require("../lib/useragent");
  8215. var AUTOSCROLL_DELAY = 200;
  8216. var SCROLL_CURSOR_DELAY = 200;
  8217. var SCROLL_CURSOR_HYSTERESIS = 5;
  8218. function DragdropHandler(mouseHandler) {
  8219. var editor = mouseHandler.editor;
  8220. var blankImage = dom.createElement("img");
  8221. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  8222. if (useragent.isOpera)
  8223. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  8224. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  8225. exports.forEach(function(x) {
  8226. mouseHandler[x] = this[x];
  8227. }, this);
  8228. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  8229. var mouseTarget = editor.container;
  8230. var dragSelectionMarker, x, y;
  8231. var timerId, range;
  8232. var dragCursor, counter = 0;
  8233. var dragOperation;
  8234. var isInternal;
  8235. var autoScrollStartTime;
  8236. var cursorMovedTime;
  8237. var cursorPointOnCaretMoved;
  8238. this.onDragStart = function(e) {
  8239. if (this.cancelDrag || !mouseTarget.draggable) {
  8240. var self = this;
  8241. setTimeout(function(){
  8242. self.startSelect();
  8243. self.captureMouse(e);
  8244. }, 0);
  8245. return e.preventDefault();
  8246. }
  8247. range = editor.getSelectionRange();
  8248. var dataTransfer = e.dataTransfer;
  8249. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  8250. if (useragent.isOpera) {
  8251. editor.container.appendChild(blankImage);
  8252. blankImage._top = blankImage.offsetTop;
  8253. }
  8254. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  8255. if (useragent.isOpera) {
  8256. editor.container.removeChild(blankImage);
  8257. }
  8258. dataTransfer.clearData();
  8259. dataTransfer.setData("Text", editor.session.getTextRange());
  8260. isInternal = true;
  8261. this.setState("drag");
  8262. };
  8263. this.onDragEnd = function(e) {
  8264. mouseTarget.draggable = false;
  8265. isInternal = false;
  8266. this.setState(null);
  8267. if (!editor.getReadOnly()) {
  8268. var dropEffect = e.dataTransfer.dropEffect;
  8269. if (!dragOperation && dropEffect == "move")
  8270. editor.session.remove(editor.getSelectionRange());
  8271. editor.renderer.$cursorLayer.setBlinking(true);
  8272. }
  8273. this.editor.unsetStyle("ace_dragging");
  8274. };
  8275. this.onDragEnter = function(e) {
  8276. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  8277. return;
  8278. if (!dragSelectionMarker)
  8279. addDragMarker();
  8280. counter++;
  8281. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  8282. return event.preventDefault(e);
  8283. };
  8284. this.onDragOver = function(e) {
  8285. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  8286. return;
  8287. if (!dragSelectionMarker) {
  8288. addDragMarker();
  8289. counter++;
  8290. }
  8291. if (onMouseMoveTimer !== null)
  8292. onMouseMoveTimer = null;
  8293. x = e.clientX;
  8294. y = e.clientY;
  8295. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  8296. return event.preventDefault(e);
  8297. };
  8298. this.onDragLeave = function(e) {
  8299. counter--;
  8300. if (counter <= 0 && dragSelectionMarker) {
  8301. clearDragMarker();
  8302. dragOperation = null;
  8303. return event.preventDefault(e);
  8304. }
  8305. };
  8306. this.onDrop = function(e) {
  8307. if (!dragSelectionMarker)
  8308. return;
  8309. var dataTransfer = e.dataTransfer;
  8310. if (isInternal) {
  8311. switch (dragOperation) {
  8312. case "move":
  8313. if (range.contains(dragCursor.row, dragCursor.column)) {
  8314. range = {
  8315. start: dragCursor,
  8316. end: dragCursor
  8317. };
  8318. } else {
  8319. range = editor.moveText(range, dragCursor);
  8320. }
  8321. break;
  8322. case "copy":
  8323. range = editor.moveText(range, dragCursor, true);
  8324. break;
  8325. }
  8326. } else {
  8327. var dropData = dataTransfer.getData('Text');
  8328. range = {
  8329. start: dragCursor,
  8330. end: editor.session.insert(dragCursor, dropData)
  8331. };
  8332. editor.focus();
  8333. dragOperation = null;
  8334. }
  8335. clearDragMarker();
  8336. return event.preventDefault(e);
  8337. };
  8338. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  8339. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  8340. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  8341. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  8342. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  8343. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  8344. function scrollCursorIntoView(cursor, prevCursor) {
  8345. var now = Date.now();
  8346. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  8347. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  8348. if (!cursorMovedTime || vMovement || hMovement) {
  8349. editor.$blockScrolling += 1;
  8350. editor.moveCursorToPosition(cursor);
  8351. editor.$blockScrolling -= 1;
  8352. cursorMovedTime = now;
  8353. cursorPointOnCaretMoved = {x: x, y: y};
  8354. } else {
  8355. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  8356. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  8357. cursorMovedTime = null;
  8358. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  8359. editor.renderer.scrollCursorIntoView();
  8360. cursorMovedTime = null;
  8361. }
  8362. }
  8363. }
  8364. function autoScroll(cursor, prevCursor) {
  8365. var now = Date.now();
  8366. var lineHeight = editor.renderer.layerConfig.lineHeight;
  8367. var characterWidth = editor.renderer.layerConfig.characterWidth;
  8368. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  8369. var offsets = {
  8370. x: {
  8371. left: x - editorRect.left,
  8372. right: editorRect.right - x
  8373. },
  8374. y: {
  8375. top: y - editorRect.top,
  8376. bottom: editorRect.bottom - y
  8377. }
  8378. };
  8379. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  8380. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  8381. var scrollCursor = {row: cursor.row, column: cursor.column};
  8382. if (nearestXOffset / characterWidth <= 2) {
  8383. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  8384. }
  8385. if (nearestYOffset / lineHeight <= 1) {
  8386. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  8387. }
  8388. var vScroll = cursor.row != scrollCursor.row;
  8389. var hScroll = cursor.column != scrollCursor.column;
  8390. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  8391. if (vScroll || (hScroll && !vMovement)) {
  8392. if (!autoScrollStartTime)
  8393. autoScrollStartTime = now;
  8394. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  8395. editor.renderer.scrollCursorIntoView(scrollCursor);
  8396. } else {
  8397. autoScrollStartTime = null;
  8398. }
  8399. }
  8400. function onDragInterval() {
  8401. var prevCursor = dragCursor;
  8402. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  8403. scrollCursorIntoView(dragCursor, prevCursor);
  8404. autoScroll(dragCursor, prevCursor);
  8405. }
  8406. function addDragMarker() {
  8407. range = editor.selection.toOrientedRange();
  8408. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  8409. editor.clearSelection();
  8410. if (editor.isFocused())
  8411. editor.renderer.$cursorLayer.setBlinking(false);
  8412. clearInterval(timerId);
  8413. timerId = setInterval(onDragInterval, 20);
  8414. counter = 0;
  8415. event.addListener(document, "mousemove", onMouseMove);
  8416. }
  8417. function clearDragMarker() {
  8418. clearInterval(timerId);
  8419. editor.session.removeMarker(dragSelectionMarker);
  8420. dragSelectionMarker = null;
  8421. editor.$blockScrolling += 1;
  8422. editor.selection.fromOrientedRange(range);
  8423. editor.$blockScrolling -= 1;
  8424. if (editor.isFocused() && !isInternal)
  8425. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  8426. range = null;
  8427. counter = 0;
  8428. autoScrollStartTime = null;
  8429. cursorMovedTime = null;
  8430. event.removeListener(document, "mousemove", onMouseMove);
  8431. }
  8432. var onMouseMoveTimer = null;
  8433. function onMouseMove() {
  8434. if (onMouseMoveTimer == null) {
  8435. onMouseMoveTimer = setTimeout(function() {
  8436. if (onMouseMoveTimer != null && dragSelectionMarker)
  8437. clearDragMarker();
  8438. }, 20);
  8439. }
  8440. }
  8441. function canAccept(dataTransfer) {
  8442. var types = dataTransfer.types;
  8443. return !types || Array.prototype.some.call(types, function(type) {
  8444. return type == 'text/plain' || type == 'Text';
  8445. });
  8446. }
  8447. function getDropEffect(e) {
  8448. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  8449. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  8450. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  8451. var effectAllowed = "uninitialized";
  8452. try {
  8453. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  8454. } catch (e) {}
  8455. var dropEffect = "none";
  8456. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  8457. dropEffect = "copy";
  8458. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  8459. dropEffect = "move";
  8460. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  8461. dropEffect = "copy";
  8462. return dropEffect;
  8463. }
  8464. }
  8465. (function() {
  8466. this.dragWait = function() {
  8467. var interval = Date.now() - this.mousedownEvent.time;
  8468. if (interval > this.editor.getDragDelay())
  8469. this.startDrag();
  8470. };
  8471. this.dragWaitEnd = function() {
  8472. var target = this.editor.container;
  8473. target.draggable = false;
  8474. this.startSelect(this.mousedownEvent.getDocumentPosition());
  8475. this.selectEnd();
  8476. };
  8477. this.dragReadyEnd = function(e) {
  8478. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  8479. this.editor.unsetStyle("ace_dragging");
  8480. this.dragWaitEnd();
  8481. };
  8482. this.startDrag = function(){
  8483. this.cancelDrag = false;
  8484. var target = this.editor.container;
  8485. target.draggable = true;
  8486. this.editor.renderer.$cursorLayer.setBlinking(false);
  8487. this.editor.setStyle("ace_dragging");
  8488. this.setState("dragReady");
  8489. };
  8490. this.onMouseDrag = function(e) {
  8491. var target = this.editor.container;
  8492. if (useragent.isIE && this.state == "dragReady") {
  8493. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  8494. if (distance > 3)
  8495. target.dragDrop();
  8496. }
  8497. if (this.state === "dragWait") {
  8498. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  8499. if (distance > 0) {
  8500. target.draggable = false;
  8501. this.startSelect(this.mousedownEvent.getDocumentPosition());
  8502. }
  8503. }
  8504. };
  8505. this.onMouseDown = function(e) {
  8506. if (!this.$dragEnabled)
  8507. return;
  8508. this.mousedownEvent = e;
  8509. var editor = this.editor;
  8510. var inSelection = e.inSelection();
  8511. var button = e.getButton();
  8512. var clickCount = e.domEvent.detail || 1;
  8513. if (clickCount === 1 && button === 0 && inSelection) {
  8514. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  8515. return;
  8516. this.mousedownEvent.time = Date.now();
  8517. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  8518. if ("unselectable" in eventTarget)
  8519. eventTarget.unselectable = "on";
  8520. if (editor.getDragDelay()) {
  8521. if (useragent.isWebKit) {
  8522. this.cancelDrag = true;
  8523. var mouseTarget = editor.container;
  8524. mouseTarget.draggable = true;
  8525. }
  8526. this.setState("dragWait");
  8527. } else {
  8528. this.startDrag();
  8529. }
  8530. this.captureMouse(e, this.onMouseDrag.bind(this));
  8531. e.defaultPrevented = true;
  8532. }
  8533. };
  8534. }).call(DragdropHandler.prototype);
  8535. function calcDistance(ax, ay, bx, by) {
  8536. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  8537. }
  8538. exports.DragdropHandler = DragdropHandler;
  8539. });
  8540. ace.define('ace/layer/marker', ['require', 'exports', 'module' , 'ace/range', 'ace/lib/dom'], function(require, exports, module) {
  8541. var Range = require("../range").Range;
  8542. var dom = require("../lib/dom");
  8543. var Marker = function(parentEl) {
  8544. this.element = dom.createElement("div");
  8545. this.element.className = "ace_layer ace_marker-layer";
  8546. parentEl.appendChild(this.element);
  8547. };
  8548. (function() {
  8549. this.$padding = 0;
  8550. this.setPadding = function(padding) {
  8551. this.$padding = padding;
  8552. };
  8553. this.setSession = function(session) {
  8554. this.session = session;
  8555. };
  8556. this.setMarkers = function(markers) {
  8557. this.markers = markers;
  8558. };
  8559. this.update = function(config) {
  8560. var config = config || this.config;
  8561. if (!config)
  8562. return;
  8563. this.config = config;
  8564. var html = [];
  8565. for (var key in this.markers) {
  8566. var marker = this.markers[key];
  8567. if (!marker.range) {
  8568. marker.update(html, this, this.session, config);
  8569. continue;
  8570. }
  8571. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  8572. if (range.isEmpty()) continue;
  8573. range = range.toScreenRange(this.session);
  8574. if (marker.renderer) {
  8575. var top = this.$getTop(range.start.row, config);
  8576. var left = this.$padding + range.start.column * config.characterWidth;
  8577. marker.renderer(html, range, left, top, config);
  8578. } else if (marker.type == "fullLine") {
  8579. this.drawFullLineMarker(html, range, marker.clazz, config);
  8580. } else if (marker.type == "screenLine") {
  8581. this.drawScreenLineMarker(html, range, marker.clazz, config);
  8582. } else if (range.isMultiLine()) {
  8583. if (marker.type == "text")
  8584. this.drawTextMarker(html, range, marker.clazz, config);
  8585. else
  8586. this.drawMultiLineMarker(html, range, marker.clazz, config);
  8587. } else {
  8588. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config);
  8589. }
  8590. }
  8591. this.element = dom.setInnerHtml(this.element, html.join(""));
  8592. };
  8593. this.$getTop = function(row, layerConfig) {
  8594. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  8595. };
  8596. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  8597. var row = range.start.row;
  8598. var lineRange = new Range(
  8599. row, range.start.column,
  8600. row, this.session.getScreenLastRowColumn(row)
  8601. );
  8602. this.drawSingleLineMarker(stringBuilder, lineRange, clazz + " ace_start", layerConfig, 1, extraStyle);
  8603. row = range.end.row;
  8604. lineRange = new Range(row, 0, row, range.end.column);
  8605. this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);
  8606. for (row = range.start.row + 1; row < range.end.row; row++) {
  8607. lineRange.start.row = row;
  8608. lineRange.end.row = row;
  8609. lineRange.end.column = this.session.getScreenLastRowColumn(row);
  8610. this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);
  8611. }
  8612. };
  8613. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  8614. var padding = this.$padding;
  8615. var height = config.lineHeight;
  8616. var top = this.$getTop(range.start.row, config);
  8617. var left = padding + range.start.column * config.characterWidth;
  8618. extraStyle = extraStyle || "";
  8619. stringBuilder.push(
  8620. "<div class='", clazz, " ace_start' style='",
  8621. "height:", height, "px;",
  8622. "right:0;",
  8623. "top:", top, "px;",
  8624. "left:", left, "px;", extraStyle, "'></div>"
  8625. );
  8626. top = this.$getTop(range.end.row, config);
  8627. var width = range.end.column * config.characterWidth;
  8628. stringBuilder.push(
  8629. "<div class='", clazz, "' style='",
  8630. "height:", height, "px;",
  8631. "width:", width, "px;",
  8632. "top:", top, "px;",
  8633. "left:", padding, "px;", extraStyle, "'></div>"
  8634. );
  8635. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  8636. if (height < 0)
  8637. return;
  8638. top = this.$getTop(range.start.row + 1, config);
  8639. stringBuilder.push(
  8640. "<div class='", clazz, "' style='",
  8641. "height:", height, "px;",
  8642. "right:0;",
  8643. "top:", top, "px;",
  8644. "left:", padding, "px;", extraStyle, "'></div>"
  8645. );
  8646. };
  8647. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  8648. var height = config.lineHeight;
  8649. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  8650. var top = this.$getTop(range.start.row, config);
  8651. var left = this.$padding + range.start.column * config.characterWidth;
  8652. stringBuilder.push(
  8653. "<div class='", clazz, "' style='",
  8654. "height:", height, "px;",
  8655. "width:", width, "px;",
  8656. "top:", top, "px;",
  8657. "left:", left, "px;", extraStyle || "", "'></div>"
  8658. );
  8659. };
  8660. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  8661. var top = this.$getTop(range.start.row, config);
  8662. var height = config.lineHeight;
  8663. if (range.start.row != range.end.row)
  8664. height += this.$getTop(range.end.row, config) - top;
  8665. stringBuilder.push(
  8666. "<div class='", clazz, "' style='",
  8667. "height:", height, "px;",
  8668. "top:", top, "px;",
  8669. "left:0;right:0;", extraStyle || "", "'></div>"
  8670. );
  8671. };
  8672. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  8673. var top = this.$getTop(range.start.row, config);
  8674. var height = config.lineHeight;
  8675. stringBuilder.push(
  8676. "<div class='", clazz, "' style='",
  8677. "height:", height, "px;",
  8678. "top:", top, "px;",
  8679. "left:0;right:0;", extraStyle || "", "'></div>"
  8680. );
  8681. };
  8682. }).call(Marker.prototype);
  8683. exports.Marker = Marker;
  8684. });
  8685. ace.define('ace/mouse/mouse_event', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/lib/useragent'], function(require, exports, module) {
  8686. var event = require("../lib/event");
  8687. var useragent = require("../lib/useragent");
  8688. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  8689. this.domEvent = domEvent;
  8690. this.editor = editor;
  8691. this.x = this.clientX = domEvent.clientX;
  8692. this.y = this.clientY = domEvent.clientY;
  8693. this.$pos = null;
  8694. this.$inSelection = null;
  8695. this.propagationStopped = false;
  8696. this.defaultPrevented = false;
  8697. };
  8698. (function() {
  8699. this.stopPropagation = function() {
  8700. event.stopPropagation(this.domEvent);
  8701. this.propagationStopped = true;
  8702. };
  8703. this.preventDefault = function() {
  8704. event.preventDefault(this.domEvent);
  8705. this.defaultPrevented = true;
  8706. };
  8707. this.stop = function() {
  8708. this.stopPropagation();
  8709. this.preventDefault();
  8710. };
  8711. this.getDocumentPosition = function() {
  8712. if (this.$pos)
  8713. return this.$pos;
  8714. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  8715. return this.$pos;
  8716. };
  8717. this.inSelection = function() {
  8718. if (this.$inSelection !== null)
  8719. return this.$inSelection;
  8720. var editor = this.editor;
  8721. var selectionRange = editor.getSelectionRange();
  8722. if (selectionRange.isEmpty())
  8723. this.$inSelection = false;
  8724. else {
  8725. var pos = this.getDocumentPosition();
  8726. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  8727. }
  8728. return this.$inSelection;
  8729. };
  8730. this.getButton = function() {
  8731. return event.getButton(this.domEvent);
  8732. };
  8733. this.getShiftKey = function() {
  8734. return this.domEvent.shiftKey;
  8735. };
  8736. this.getAccelKey = useragent.isMac
  8737. ? function() { return this.domEvent.metaKey; }
  8738. : function() { return this.domEvent.ctrlKey; };
  8739. }).call(MouseEvent.prototype);
  8740. });
  8741. ace.define('ace/layer/text', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/lang', 'ace/lib/useragent', 'ace/lib/event_emitter'], function(require, exports, module) {
  8742. var oop = require("../lib/oop");
  8743. var dom = require("../lib/dom");
  8744. var lang = require("../lib/lang");
  8745. var useragent = require("../lib/useragent");
  8746. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  8747. var Text = function(parentEl) {
  8748. this.element = dom.createElement("div");
  8749. this.element.className = "ace_layer ace_text-layer";
  8750. parentEl.appendChild(this.element);
  8751. this.$updateEolChar = this.$updateEolChar.bind(this);
  8752. };
  8753. (function() {
  8754. oop.implement(this, EventEmitter);
  8755. this.EOF_CHAR = "\xB6";
  8756. this.EOL_CHAR_LF = "\xAC";
  8757. this.EOL_CHAR_CRLF = "\xa4";
  8758. this.EOL_CHAR = this.EOL_CHAR_LF;
  8759. this.TAB_CHAR = "\u2192"; //"\u21E5";
  8760. this.SPACE_CHAR = "\xB7";
  8761. this.$padding = 0;
  8762. this.$updateEolChar = function() {
  8763. var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
  8764. ? this.EOL_CHAR_LF
  8765. : this.EOL_CHAR_CRLF;
  8766. if (this.EOL_CHAR != EOL_CHAR) {
  8767. this.EOL_CHAR = EOL_CHAR;
  8768. return true;
  8769. }
  8770. }
  8771. this.setPadding = function(padding) {
  8772. this.$padding = padding;
  8773. this.element.style.padding = "0 " + padding + "px";
  8774. };
  8775. this.getLineHeight = function() {
  8776. return this.$fontMetrics.$characterSize.height || 0;
  8777. };
  8778. this.getCharacterWidth = function() {
  8779. return this.$fontMetrics.$characterSize.width || 0;
  8780. };
  8781. this.$setFontMetrics = function(measure) {
  8782. this.$fontMetrics = measure;
  8783. this.$fontMetrics.on("changeCharacterSize", function(e) {
  8784. this._signal("changeCharacterSize", e);
  8785. }.bind(this));
  8786. this.$pollSizeChanges();
  8787. }
  8788. this.checkForSizeChanges = function() {
  8789. this.$fontMetrics.checkForSizeChanges();
  8790. };
  8791. this.$pollSizeChanges = function() {
  8792. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  8793. };
  8794. this.setSession = function(session) {
  8795. this.session = session;
  8796. this.$computeTabString();
  8797. };
  8798. this.showInvisibles = false;
  8799. this.setShowInvisibles = function(showInvisibles) {
  8800. if (this.showInvisibles == showInvisibles)
  8801. return false;
  8802. this.showInvisibles = showInvisibles;
  8803. this.$computeTabString();
  8804. return true;
  8805. };
  8806. this.displayIndentGuides = true;
  8807. this.setDisplayIndentGuides = function(display) {
  8808. if (this.displayIndentGuides == display)
  8809. return false;
  8810. this.displayIndentGuides = display;
  8811. this.$computeTabString();
  8812. return true;
  8813. };
  8814. this.$tabStrings = [];
  8815. this.onChangeTabSize =
  8816. this.$computeTabString = function() {
  8817. var tabSize = this.session.getTabSize();
  8818. this.tabSize = tabSize;
  8819. var tabStr = this.$tabStrings = [0];
  8820. for (var i = 1; i < tabSize + 1; i++) {
  8821. if (this.showInvisibles) {
  8822. tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
  8823. + this.TAB_CHAR
  8824. + lang.stringRepeat("\xa0", i - 1)
  8825. + "</span>");
  8826. } else {
  8827. tabStr.push(lang.stringRepeat("\xa0", i));
  8828. }
  8829. }
  8830. if (this.displayIndentGuides) {
  8831. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  8832. var className = "ace_indent-guide";
  8833. var spaceClass = "";
  8834. var tabClass = "";
  8835. if (this.showInvisibles) {
  8836. className += " ace_invisible";
  8837. spaceClass = " ace_invisible_space";
  8838. tabClass = " ace_invisible_tab";
  8839. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  8840. var tabContent = this.TAB_CHAR + lang.stringRepeat("\xa0", this.tabSize - 1);
  8841. } else{
  8842. var spaceContent = lang.stringRepeat("\xa0", this.tabSize);
  8843. var tabContent = spaceContent;
  8844. }
  8845. this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>";
  8846. this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>";
  8847. }
  8848. };
  8849. this.updateLines = function(config, firstRow, lastRow) {
  8850. if (this.config.lastRow != config.lastRow ||
  8851. this.config.firstRow != config.firstRow) {
  8852. this.scrollLines(config);
  8853. }
  8854. this.config = config;
  8855. var first = Math.max(firstRow, config.firstRow);
  8856. var last = Math.min(lastRow, config.lastRow);
  8857. var lineElements = this.element.childNodes;
  8858. var lineElementsIdx = 0;
  8859. for (var row = config.firstRow; row < first; row++) {
  8860. var foldLine = this.session.getFoldLine(row);
  8861. if (foldLine) {
  8862. if (foldLine.containsRow(first)) {
  8863. first = foldLine.start.row;
  8864. break;
  8865. } else {
  8866. row = foldLine.end.row;
  8867. }
  8868. }
  8869. lineElementsIdx ++;
  8870. }
  8871. var row = first;
  8872. var foldLine = this.session.getNextFoldLine(row);
  8873. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8874. while (true) {
  8875. if (row > foldStart) {
  8876. row = foldLine.end.row+1;
  8877. foldLine = this.session.getNextFoldLine(row, foldLine);
  8878. foldStart = foldLine ? foldLine.start.row :Infinity;
  8879. }
  8880. if (row > last)
  8881. break;
  8882. var lineElement = lineElements[lineElementsIdx++];
  8883. if (lineElement) {
  8884. var html = [];
  8885. this.$renderLine(
  8886. html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
  8887. );
  8888. lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  8889. dom.setInnerHtml(lineElement, html.join(""));
  8890. }
  8891. row++;
  8892. }
  8893. };
  8894. this.scrollLines = function(config) {
  8895. var oldConfig = this.config;
  8896. this.config = config;
  8897. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  8898. return this.update(config);
  8899. if (config.lastRow < oldConfig.firstRow)
  8900. return this.update(config);
  8901. var el = this.element;
  8902. if (oldConfig.firstRow < config.firstRow)
  8903. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  8904. el.removeChild(el.firstChild);
  8905. if (oldConfig.lastRow > config.lastRow)
  8906. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  8907. el.removeChild(el.lastChild);
  8908. if (config.firstRow < oldConfig.firstRow) {
  8909. var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
  8910. if (el.firstChild)
  8911. el.insertBefore(fragment, el.firstChild);
  8912. else
  8913. el.appendChild(fragment);
  8914. }
  8915. if (config.lastRow > oldConfig.lastRow) {
  8916. var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
  8917. el.appendChild(fragment);
  8918. }
  8919. };
  8920. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  8921. var fragment = this.element.ownerDocument.createDocumentFragment();
  8922. var row = firstRow;
  8923. var foldLine = this.session.getNextFoldLine(row);
  8924. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8925. while (true) {
  8926. if (row > foldStart) {
  8927. row = foldLine.end.row+1;
  8928. foldLine = this.session.getNextFoldLine(row, foldLine);
  8929. foldStart = foldLine ? foldLine.start.row : Infinity;
  8930. }
  8931. if (row > lastRow)
  8932. break;
  8933. var container = dom.createElement("div");
  8934. var html = [];
  8935. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  8936. container.innerHTML = html.join("");
  8937. if (this.$useLineGroups()) {
  8938. container.className = 'ace_line_group';
  8939. fragment.appendChild(container);
  8940. container.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  8941. } else {
  8942. while(container.firstChild)
  8943. fragment.appendChild(container.firstChild);
  8944. }
  8945. row++;
  8946. }
  8947. return fragment;
  8948. };
  8949. this.update = function(config) {
  8950. this.config = config;
  8951. var html = [];
  8952. var firstRow = config.firstRow, lastRow = config.lastRow;
  8953. var row = firstRow;
  8954. var foldLine = this.session.getNextFoldLine(row);
  8955. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8956. while (true) {
  8957. if (row > foldStart) {
  8958. row = foldLine.end.row+1;
  8959. foldLine = this.session.getNextFoldLine(row, foldLine);
  8960. foldStart = foldLine ? foldLine.start.row :Infinity;
  8961. }
  8962. if (row > lastRow)
  8963. break;
  8964. if (this.$useLineGroups())
  8965. html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>")
  8966. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  8967. if (this.$useLineGroups())
  8968. html.push("</div>"); // end the line group
  8969. row++;
  8970. }
  8971. this.element = dom.setInnerHtml(this.element, html.join(""));
  8972. };
  8973. this.$textToken = {
  8974. "text": true,
  8975. "rparen": true,
  8976. "lparen": true
  8977. };
  8978. this.$renderToken = function(stringBuilder, screenColumn, token, value) {
  8979. var self = this;
  8980. var replaceReg = /\t|&|<|( +)|([\x00-\x1f\x80-\xa0\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
  8981. var replaceFunc = function(c, a, b, tabIdx, idx4) {
  8982. if (a) {
  8983. return self.showInvisibles ?
  8984. "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>" :
  8985. lang.stringRepeat("\xa0", c.length);
  8986. } else if (c == "&") {
  8987. return "&#38;";
  8988. } else if (c == "<") {
  8989. return "&#60;";
  8990. } else if (c == "\t") {
  8991. var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
  8992. screenColumn += tabSize - 1;
  8993. return self.$tabStrings[tabSize];
  8994. } else if (c == "\u3000") {
  8995. var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  8996. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  8997. screenColumn += 1;
  8998. return "<span class='" + classToUse + "' style='width:" +
  8999. (self.config.characterWidth * 2) +
  9000. "px'>" + space + "</span>";
  9001. } else if (b) {
  9002. return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>";
  9003. } else {
  9004. screenColumn += 1;
  9005. return "<span class='ace_cjk' style='width:" +
  9006. (self.config.characterWidth * 2) +
  9007. "px'>" + c + "</span>";
  9008. }
  9009. };
  9010. var output = value.replace(replaceReg, replaceFunc);
  9011. if (!this.$textToken[token.type]) {
  9012. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  9013. var style = "";
  9014. if (token.type == "fold")
  9015. style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
  9016. stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
  9017. }
  9018. else {
  9019. stringBuilder.push(output);
  9020. }
  9021. return screenColumn + value.length;
  9022. };
  9023. this.renderIndentGuide = function(stringBuilder, value, max) {
  9024. var cols = value.search(this.$indentGuideRe);
  9025. if (cols <= 0 || cols >= max)
  9026. return value;
  9027. if (value[0] == " ") {
  9028. cols -= cols % this.tabSize;
  9029. stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize));
  9030. return value.substr(cols);
  9031. } else if (value[0] == "\t") {
  9032. stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols));
  9033. return value.substr(cols);
  9034. }
  9035. return value;
  9036. };
  9037. this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
  9038. var chars = 0;
  9039. var split = 0;
  9040. var splitChars = splits[0];
  9041. var screenColumn = 0;
  9042. for (var i = 0; i < tokens.length; i++) {
  9043. var token = tokens[i];
  9044. var value = token.value;
  9045. if (i == 0 && this.displayIndentGuides) {
  9046. chars = value.length;
  9047. value = this.renderIndentGuide(stringBuilder, value, splitChars);
  9048. if (!value)
  9049. continue;
  9050. chars -= value.length;
  9051. }
  9052. if (chars + value.length < splitChars) {
  9053. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  9054. chars += value.length;
  9055. } else {
  9056. while (chars + value.length >= splitChars) {
  9057. screenColumn = this.$renderToken(
  9058. stringBuilder, screenColumn,
  9059. token, value.substring(0, splitChars - chars)
  9060. );
  9061. value = value.substring(splitChars - chars);
  9062. chars = splitChars;
  9063. if (!onlyContents) {
  9064. stringBuilder.push("</div>",
  9065. "<div class='ace_line' style='height:",
  9066. this.config.lineHeight, "px'>"
  9067. );
  9068. }
  9069. split ++;
  9070. screenColumn = 0;
  9071. splitChars = splits[split] || Number.MAX_VALUE;
  9072. }
  9073. if (value.length != 0) {
  9074. chars += value.length;
  9075. screenColumn = this.$renderToken(
  9076. stringBuilder, screenColumn, token, value
  9077. );
  9078. }
  9079. }
  9080. }
  9081. };
  9082. this.$renderSimpleLine = function(stringBuilder, tokens) {
  9083. var screenColumn = 0;
  9084. var token = tokens[0];
  9085. var value = token.value;
  9086. if (this.displayIndentGuides)
  9087. value = this.renderIndentGuide(stringBuilder, value);
  9088. if (value)
  9089. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  9090. for (var i = 1; i < tokens.length; i++) {
  9091. token = tokens[i];
  9092. value = token.value;
  9093. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  9094. }
  9095. };
  9096. this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
  9097. if (!foldLine && foldLine != false)
  9098. foldLine = this.session.getFoldLine(row);
  9099. if (foldLine)
  9100. var tokens = this.$getFoldLineTokens(row, foldLine);
  9101. else
  9102. var tokens = this.session.getTokens(row);
  9103. if (!onlyContents) {
  9104. stringBuilder.push(
  9105. "<div class='ace_line' style='height:",
  9106. this.config.lineHeight * (
  9107. this.$useLineGroups() ? 1 :this.session.getRowLength(row)
  9108. ), "px'>"
  9109. );
  9110. }
  9111. if (tokens.length) {
  9112. var splits = this.session.getRowSplitData(row);
  9113. if (splits && splits.length)
  9114. this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
  9115. else
  9116. this.$renderSimpleLine(stringBuilder, tokens);
  9117. }
  9118. if (this.showInvisibles) {
  9119. if (foldLine)
  9120. row = foldLine.end.row
  9121. stringBuilder.push(
  9122. "<span class='ace_invisible ace_invisible_eol'>",
  9123. row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
  9124. "</span>"
  9125. );
  9126. }
  9127. if (!onlyContents)
  9128. stringBuilder.push("</div>");
  9129. };
  9130. this.$getFoldLineTokens = function(row, foldLine) {
  9131. var session = this.session;
  9132. var renderTokens = [];
  9133. function addTokens(tokens, from, to) {
  9134. var idx = 0, col = 0;
  9135. while ((col + tokens[idx].value.length) < from) {
  9136. col += tokens[idx].value.length;
  9137. idx++;
  9138. if (idx == tokens.length)
  9139. return;
  9140. }
  9141. if (col != from) {
  9142. var value = tokens[idx].value.substring(from - col);
  9143. if (value.length > (to - from))
  9144. value = value.substring(0, to - from);
  9145. renderTokens.push({
  9146. type: tokens[idx].type,
  9147. value: value
  9148. });
  9149. col = from + value.length;
  9150. idx += 1;
  9151. }
  9152. while (col < to && idx < tokens.length) {
  9153. var value = tokens[idx].value;
  9154. if (value.length + col > to) {
  9155. renderTokens.push({
  9156. type: tokens[idx].type,
  9157. value: value.substring(0, to - col)
  9158. });
  9159. } else
  9160. renderTokens.push(tokens[idx]);
  9161. col += value.length;
  9162. idx += 1;
  9163. }
  9164. }
  9165. var tokens = session.getTokens(row);
  9166. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  9167. if (placeholder != null) {
  9168. renderTokens.push({
  9169. type: "fold",
  9170. value: placeholder
  9171. });
  9172. } else {
  9173. if (isNewRow)
  9174. tokens = session.getTokens(row);
  9175. if (tokens.length)
  9176. addTokens(tokens, lastColumn, column);
  9177. }
  9178. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  9179. return renderTokens;
  9180. };
  9181. this.$useLineGroups = function() {
  9182. return this.session.getUseWrapMode();
  9183. };
  9184. this.destroy = function() {
  9185. clearInterval(this.$pollSizeChangesTimer);
  9186. if (this.$measureNode)
  9187. this.$measureNode.parentNode.removeChild(this.$measureNode);
  9188. delete this.$measureNode;
  9189. };
  9190. }).call(Text.prototype);
  9191. exports.Text = Text;
  9192. });
  9193. ace.define('ace/tooltip', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom'], function(require, exports, module) {
  9194. var oop = require("./lib/oop");
  9195. var dom = require("./lib/dom");
  9196. function Tooltip (parentNode) {
  9197. this.isOpen = false;
  9198. this.$element = null;
  9199. this.$parentNode = parentNode;
  9200. }
  9201. (function() {
  9202. this.$init = function() {
  9203. this.$element = dom.createElement("div");
  9204. this.$element.className = "ace_tooltip";
  9205. this.$element.style.display = "none";
  9206. this.$parentNode.appendChild(this.$element);
  9207. return this.$element;
  9208. };
  9209. this.getElement = function() {
  9210. return this.$element || this.$init();
  9211. };
  9212. this.setText = function(text) {
  9213. dom.setInnerText(this.getElement(), text);
  9214. };
  9215. this.setHtml = function(html) {
  9216. this.getElement().innerHTML = html;
  9217. };
  9218. this.setPosition = function(x, y) {
  9219. this.getElement().style.left = x + "px";
  9220. this.getElement().style.top = y + "px";
  9221. };
  9222. this.setClassName = function(className) {
  9223. dom.addCssClass(this.getElement(), className);
  9224. };
  9225. this.show = function(text, x, y) {
  9226. if (text != null)
  9227. this.setText(text);
  9228. if (x != null && y != null)
  9229. this.setPosition(x, y);
  9230. if (!this.isOpen) {
  9231. this.getElement().style.display = "block";
  9232. this.isOpen = true;
  9233. }
  9234. };
  9235. this.hide = function() {
  9236. if (this.isOpen) {
  9237. this.getElement().style.display = "none";
  9238. this.isOpen = false;
  9239. }
  9240. };
  9241. this.getHeight = function() {
  9242. return this.getElement().offsetHeight;
  9243. };
  9244. this.getWidth = function() {
  9245. return this.getElement().offsetWidth;
  9246. };
  9247. }).call(Tooltip.prototype);
  9248. exports.Tooltip = Tooltip;
  9249. });
  9250. ace.define('ace/layer/cursor', ['require', 'exports', 'module' , 'ace/lib/dom'], function(require, exports, module) {
  9251. var dom = require("../lib/dom");
  9252. var IE8;
  9253. var Cursor = function(parentEl) {
  9254. this.element = dom.createElement("div");
  9255. this.element.className = "ace_layer ace_cursor-layer";
  9256. parentEl.appendChild(this.element);
  9257. if (IE8 === undefined)
  9258. IE8 = "opacity" in this.element;
  9259. this.isVisible = false;
  9260. this.isBlinking = true;
  9261. this.blinkInterval = 1000;
  9262. this.smoothBlinking = false;
  9263. this.cursors = [];
  9264. this.cursor = this.addCursor();
  9265. dom.addCssClass(this.element, "ace_hidden-cursors");
  9266. this.$updateCursors = this.$updateVisibility.bind(this);
  9267. };
  9268. (function() {
  9269. this.$updateVisibility = function(val) {
  9270. var cursors = this.cursors;
  9271. for (var i = cursors.length; i--; )
  9272. cursors[i].style.visibility = val ? "" : "hidden";
  9273. };
  9274. this.$updateOpacity = function(val) {
  9275. var cursors = this.cursors;
  9276. for (var i = cursors.length; i--; )
  9277. cursors[i].style.opacity = val ? "" : "0";
  9278. };
  9279. this.$padding = 0;
  9280. this.setPadding = function(padding) {
  9281. this.$padding = padding;
  9282. };
  9283. this.setSession = function(session) {
  9284. this.session = session;
  9285. };
  9286. this.setBlinking = function(blinking) {
  9287. if (blinking != this.isBlinking){
  9288. this.isBlinking = blinking;
  9289. this.restartTimer();
  9290. }
  9291. };
  9292. this.setBlinkInterval = function(blinkInterval) {
  9293. if (blinkInterval != this.blinkInterval){
  9294. this.blinkInterval = blinkInterval;
  9295. this.restartTimer();
  9296. }
  9297. };
  9298. this.setSmoothBlinking = function(smoothBlinking) {
  9299. if (smoothBlinking != this.smoothBlinking && !IE8) {
  9300. this.smoothBlinking = smoothBlinking;
  9301. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  9302. this.$updateCursors(true);
  9303. this.$updateCursors = (smoothBlinking
  9304. ? this.$updateOpacity
  9305. : this.$updateVisibility).bind(this);
  9306. this.restartTimer();
  9307. }
  9308. };
  9309. this.addCursor = function() {
  9310. var el = dom.createElement("div");
  9311. el.className = "ace_cursor";
  9312. this.element.appendChild(el);
  9313. this.cursors.push(el);
  9314. return el;
  9315. };
  9316. this.removeCursor = function() {
  9317. if (this.cursors.length > 1) {
  9318. var el = this.cursors.pop();
  9319. el.parentNode.removeChild(el);
  9320. return el;
  9321. }
  9322. };
  9323. this.hideCursor = function() {
  9324. this.isVisible = false;
  9325. dom.addCssClass(this.element, "ace_hidden-cursors");
  9326. this.restartTimer();
  9327. };
  9328. this.showCursor = function() {
  9329. this.isVisible = true;
  9330. dom.removeCssClass(this.element, "ace_hidden-cursors");
  9331. this.restartTimer();
  9332. };
  9333. this.restartTimer = function() {
  9334. var update = this.$updateCursors;
  9335. clearInterval(this.intervalId);
  9336. clearTimeout(this.timeoutId);
  9337. if (this.smoothBlinking) {
  9338. dom.removeCssClass(this.element, "ace_smooth-blinking");
  9339. }
  9340. update(true);
  9341. if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
  9342. return;
  9343. if (this.smoothBlinking) {
  9344. setTimeout(function(){
  9345. dom.addCssClass(this.element, "ace_smooth-blinking");
  9346. }.bind(this));
  9347. }
  9348. var blink = function(){
  9349. this.timeoutId = setTimeout(function() {
  9350. update(false);
  9351. }, 0.6 * this.blinkInterval);
  9352. }.bind(this);
  9353. this.intervalId = setInterval(function() {
  9354. update(true);
  9355. blink();
  9356. }, this.blinkInterval);
  9357. blink();
  9358. };
  9359. this.getPixelPosition = function(position, onScreen) {
  9360. if (!this.config || !this.session)
  9361. return {left : 0, top : 0};
  9362. if (!position)
  9363. position = this.session.selection.getCursor();
  9364. var pos = this.session.documentToScreenPosition(position);
  9365. var cursorLeft = this.$padding + pos.column * this.config.characterWidth;
  9366. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  9367. this.config.lineHeight;
  9368. return {left : cursorLeft, top : cursorTop};
  9369. };
  9370. this.update = function(config) {
  9371. this.config = config;
  9372. var selections = this.session.$selectionMarkers;
  9373. var i = 0, cursorIndex = 0;
  9374. if (selections === undefined || selections.length === 0){
  9375. selections = [{cursor: null}];
  9376. }
  9377. for (var i = 0, n = selections.length; i < n; i++) {
  9378. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  9379. if ((pixelPos.top > config.height + config.offset ||
  9380. pixelPos.top < 0) && i > 1) {
  9381. continue;
  9382. }
  9383. var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
  9384. style.left = pixelPos.left + "px";
  9385. style.top = pixelPos.top + "px";
  9386. style.width = config.characterWidth + "px";
  9387. style.height = config.lineHeight + "px";
  9388. }
  9389. while (this.cursors.length > cursorIndex)
  9390. this.removeCursor();
  9391. var overwrite = this.session.getOverwrite();
  9392. this.$setOverwrite(overwrite);
  9393. this.$pixelPos = pixelPos;
  9394. this.restartTimer();
  9395. };
  9396. this.$setOverwrite = function(overwrite) {
  9397. if (overwrite != this.overwrite) {
  9398. this.overwrite = overwrite;
  9399. if (overwrite)
  9400. dom.addCssClass(this.element, "ace_overwrite-cursors");
  9401. else
  9402. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  9403. }
  9404. };
  9405. this.destroy = function() {
  9406. clearInterval(this.intervalId);
  9407. clearTimeout(this.timeoutId);
  9408. };
  9409. }).call(Cursor.prototype);
  9410. exports.Cursor = Cursor;
  9411. });
  9412. ace.define('ace/mouse/default_gutter_handler', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/oop', 'ace/lib/event', 'ace/tooltip'], function(require, exports, module) {
  9413. var dom = require("../lib/dom");
  9414. var oop = require("../lib/oop");
  9415. var event = require("../lib/event");
  9416. var Tooltip = require("../tooltip").Tooltip;
  9417. function GutterHandler(mouseHandler) {
  9418. var editor = mouseHandler.editor;
  9419. var gutter = editor.renderer.$gutterLayer;
  9420. var tooltip = new GutterTooltip(editor.container);
  9421. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  9422. if (!editor.isFocused() || e.getButton() != 0)
  9423. return;
  9424. var gutterRegion = gutter.getRegion(e);
  9425. if (gutterRegion == "foldWidgets")
  9426. return;
  9427. var row = e.getDocumentPosition().row;
  9428. var selection = editor.session.selection;
  9429. if (e.getShiftKey())
  9430. selection.selectTo(row, 0);
  9431. else {
  9432. if (e.domEvent.detail == 2) {
  9433. editor.selectAll();
  9434. return e.preventDefault();
  9435. }
  9436. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  9437. }
  9438. mouseHandler.setState("selectByLines");
  9439. mouseHandler.captureMouse(e);
  9440. return e.preventDefault();
  9441. });
  9442. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  9443. function showTooltip() {
  9444. var row = mouseEvent.getDocumentPosition().row;
  9445. var annotation = gutter.$annotations[row];
  9446. if (!annotation)
  9447. return hideTooltip();
  9448. var maxRow = editor.session.getLength();
  9449. if (row == maxRow) {
  9450. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  9451. var pos = mouseEvent.$pos;
  9452. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  9453. return hideTooltip();
  9454. }
  9455. if (tooltipAnnotation == annotation)
  9456. return;
  9457. tooltipAnnotation = annotation.text.join("<br/>");
  9458. tooltip.setHtml(tooltipAnnotation);
  9459. tooltip.show();
  9460. editor.on("mousewheel", hideTooltip);
  9461. if (mouseHandler.$tooltipFollowsMouse) {
  9462. moveTooltip(mouseEvent);
  9463. } else {
  9464. var gutterElement = gutter.$cells[editor.session.documentToScreenRow(row, 0)].element;
  9465. var rect = gutterElement.getBoundingClientRect();
  9466. var style = tooltip.getElement().style;
  9467. style.left = rect.right + "px";
  9468. style.top = rect.bottom + "px";
  9469. }
  9470. }
  9471. function hideTooltip() {
  9472. if (tooltipTimeout)
  9473. tooltipTimeout = clearTimeout(tooltipTimeout);
  9474. if (tooltipAnnotation) {
  9475. tooltip.hide();
  9476. tooltipAnnotation = null;
  9477. editor.removeEventListener("mousewheel", hideTooltip);
  9478. }
  9479. }
  9480. function moveTooltip(e) {
  9481. tooltip.setPosition(e.x, e.y);
  9482. }
  9483. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  9484. var target = e.domEvent.target || e.domEvent.srcElement;
  9485. if (dom.hasCssClass(target, "ace_fold-widget"))
  9486. return hideTooltip();
  9487. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  9488. moveTooltip(e);
  9489. mouseEvent = e;
  9490. if (tooltipTimeout)
  9491. return;
  9492. tooltipTimeout = setTimeout(function() {
  9493. tooltipTimeout = null;
  9494. if (mouseEvent && !mouseHandler.isMousePressed)
  9495. showTooltip();
  9496. else
  9497. hideTooltip();
  9498. }, 50);
  9499. });
  9500. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  9501. mouseEvent = null;
  9502. if (!tooltipAnnotation || tooltipTimeout)
  9503. return;
  9504. tooltipTimeout = setTimeout(function() {
  9505. tooltipTimeout = null;
  9506. hideTooltip();
  9507. }, 50);
  9508. });
  9509. editor.on("changeSession", hideTooltip);
  9510. }
  9511. function GutterTooltip(parentNode) {
  9512. Tooltip.call(this, parentNode);
  9513. }
  9514. oop.inherits(GutterTooltip, Tooltip);
  9515. (function(){
  9516. this.setPosition = function(x, y) {
  9517. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  9518. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  9519. var width = this.getWidth();
  9520. var height = this.getHeight();
  9521. x += 15;
  9522. y += 15;
  9523. if (x + width > windowWidth) {
  9524. x -= (x + width) - windowWidth;
  9525. }
  9526. if (y + height > windowHeight) {
  9527. y -= 20 + height;
  9528. }
  9529. Tooltip.prototype.setPosition.call(this, x, y);
  9530. };
  9531. }).call(GutterTooltip.prototype);
  9532. exports.GutterHandler = GutterHandler;
  9533. });
  9534. ace.define('ace/scrollbar', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/event', 'ace/lib/event_emitter'], function(require, exports, module) {
  9535. var oop = require("./lib/oop");
  9536. var dom = require("./lib/dom");
  9537. var event = require("./lib/event");
  9538. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  9539. var ScrollBar = function(parent) {
  9540. this.element = dom.createElement("div");
  9541. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  9542. this.inner = dom.createElement("div");
  9543. this.inner.className = "ace_scrollbar-inner";
  9544. this.element.appendChild(this.inner);
  9545. parent.appendChild(this.element);
  9546. this.setVisible(false);
  9547. this.skipEvent = false;
  9548. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  9549. event.addListener(this.element, "mousedown", event.preventDefault);
  9550. };
  9551. (function() {
  9552. oop.implement(this, EventEmitter);
  9553. this.setVisible = function(isVisible) {
  9554. this.element.style.display = isVisible ? "" : "none";
  9555. this.isVisible = isVisible;
  9556. };
  9557. }).call(ScrollBar.prototype);
  9558. var VScrollBar = function(parent, renderer) {
  9559. ScrollBar.call(this, parent);
  9560. this.scrollTop = 0;
  9561. renderer.$scrollbarWidth =
  9562. this.width = dom.scrollbarWidth(parent.ownerDocument);
  9563. this.inner.style.width =
  9564. this.element.style.width = (this.width || 15) + 5 + "px";
  9565. };
  9566. oop.inherits(VScrollBar, ScrollBar);
  9567. (function() {
  9568. this.classSuffix = '-v';
  9569. this.onScroll = function() {
  9570. if (!this.skipEvent) {
  9571. this.scrollTop = this.element.scrollTop;
  9572. this._emit("scroll", {data: this.scrollTop});
  9573. }
  9574. this.skipEvent = false;
  9575. };
  9576. this.getWidth = function() {
  9577. return this.isVisible ? this.width : 0;
  9578. };
  9579. this.setHeight = function(height) {
  9580. this.element.style.height = height + "px";
  9581. };
  9582. this.setInnerHeight = function(height) {
  9583. this.inner.style.height = height + "px";
  9584. };
  9585. this.setScrollHeight = function(height) {
  9586. this.inner.style.height = height + "px";
  9587. };
  9588. this.setScrollTop = function(scrollTop) {
  9589. if (this.scrollTop != scrollTop) {
  9590. this.skipEvent = true;
  9591. this.scrollTop = this.element.scrollTop = scrollTop;
  9592. }
  9593. };
  9594. }).call(VScrollBar.prototype);
  9595. var HScrollBar = function(parent, renderer) {
  9596. ScrollBar.call(this, parent);
  9597. this.scrollLeft = 0;
  9598. this.height = renderer.$scrollbarWidth;
  9599. this.inner.style.height =
  9600. this.element.style.height = (this.height || 15) + 5 + "px";
  9601. };
  9602. oop.inherits(HScrollBar, ScrollBar);
  9603. (function() {
  9604. this.classSuffix = '-h';
  9605. this.onScroll = function() {
  9606. if (!this.skipEvent) {
  9607. this.scrollLeft = this.element.scrollLeft;
  9608. this._emit("scroll", {data: this.scrollLeft});
  9609. }
  9610. this.skipEvent = false;
  9611. };
  9612. this.getHeight = function() {
  9613. return this.isVisible ? this.height : 0;
  9614. };
  9615. this.setWidth = function(width) {
  9616. this.element.style.width = width + "px";
  9617. };
  9618. this.setInnerWidth = function(width) {
  9619. this.inner.style.width = width + "px";
  9620. };
  9621. this.setScrollWidth = function(width) {
  9622. this.inner.style.width = width + "px";
  9623. };
  9624. this.setScrollLeft = function(scrollLeft) {
  9625. if (this.scrollLeft != scrollLeft) {
  9626. this.skipEvent = true;
  9627. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  9628. }
  9629. };
  9630. }).call(HScrollBar.prototype);
  9631. exports.ScrollBar = VScrollBar; // backward compatibility
  9632. exports.ScrollBarV = VScrollBar; // backward compatibility
  9633. exports.ScrollBarH = HScrollBar; // backward compatibility
  9634. exports.VScrollBar = VScrollBar;
  9635. exports.HScrollBar = HScrollBar;
  9636. });
  9637. ace.define('ace/mouse/default_handlers', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/event', 'ace/lib/useragent'], function(require, exports, module) {
  9638. var dom = require("../lib/dom");
  9639. var event = require("../lib/event");
  9640. var useragent = require("../lib/useragent");
  9641. var DRAG_OFFSET = 0; // pixels
  9642. function DefaultHandlers(mouseHandler) {
  9643. mouseHandler.$clickSelection = null;
  9644. var editor = mouseHandler.editor;
  9645. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  9646. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  9647. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  9648. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  9649. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  9650. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  9651. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  9652. exports.forEach(function(x) {
  9653. mouseHandler[x] = this[x];
  9654. }, this);
  9655. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  9656. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  9657. }
  9658. (function() {
  9659. this.onMouseDown = function(ev) {
  9660. var inSelection = ev.inSelection();
  9661. var pos = ev.getDocumentPosition();
  9662. this.mousedownEvent = ev;
  9663. var editor = this.editor;
  9664. var button = ev.getButton();
  9665. if (button !== 0) {
  9666. var selectionRange = editor.getSelectionRange();
  9667. var selectionEmpty = selectionRange.isEmpty();
  9668. if (selectionEmpty) {
  9669. editor.selection.moveToPosition(pos);
  9670. }
  9671. editor.textInput.onContextMenu(ev.domEvent);
  9672. return; // stopping event here breaks contextmenu on ff mac
  9673. }
  9674. if (inSelection && !editor.isFocused()) {
  9675. editor.focus();
  9676. if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
  9677. this.mousedownEvent.time = Date.now();
  9678. this.setState("focusWait");
  9679. this.captureMouse(ev);
  9680. return;
  9681. }
  9682. }
  9683. this.captureMouse(ev);
  9684. if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {
  9685. this.startSelect(pos);
  9686. } else if (inSelection) {
  9687. this.mousedownEvent.time = Date.now();
  9688. this.startSelect(pos);
  9689. }
  9690. return ev.preventDefault();
  9691. };
  9692. this.startSelect = function(pos) {
  9693. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  9694. var editor = this.editor;
  9695. var shiftPressed = this.mousedownEvent.getShiftKey();
  9696. if (shiftPressed) {
  9697. editor.selection.selectToPosition(pos);
  9698. }
  9699. else if (!this.$clickSelection) {
  9700. editor.selection.moveToPosition(pos);
  9701. }
  9702. if (editor.renderer.scroller.setCapture) {
  9703. editor.renderer.scroller.setCapture();
  9704. }
  9705. editor.setStyle("ace_selecting");
  9706. this.setState("select");
  9707. };
  9708. this.select = function() {
  9709. var anchor, editor = this.editor;
  9710. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  9711. if (this.$clickSelection) {
  9712. var cmp = this.$clickSelection.comparePoint(cursor);
  9713. if (cmp == -1) {
  9714. anchor = this.$clickSelection.end;
  9715. } else if (cmp == 1) {
  9716. anchor = this.$clickSelection.start;
  9717. } else {
  9718. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  9719. cursor = orientedRange.cursor;
  9720. anchor = orientedRange.anchor;
  9721. }
  9722. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  9723. }
  9724. editor.selection.selectToPosition(cursor);
  9725. editor.renderer.scrollCursorIntoView();
  9726. };
  9727. this.extendSelectionBy = function(unitName) {
  9728. var anchor, editor = this.editor;
  9729. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  9730. var range = editor.selection[unitName](cursor.row, cursor.column);
  9731. if (this.$clickSelection) {
  9732. var cmpStart = this.$clickSelection.comparePoint(range.start);
  9733. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  9734. if (cmpStart == -1 && cmpEnd <= 0) {
  9735. anchor = this.$clickSelection.end;
  9736. if (range.end.row != cursor.row || range.end.column != cursor.column)
  9737. cursor = range.start;
  9738. } else if (cmpEnd == 1 && cmpStart >= 0) {
  9739. anchor = this.$clickSelection.start;
  9740. if (range.start.row != cursor.row || range.start.column != cursor.column)
  9741. cursor = range.end;
  9742. } else if (cmpStart == -1 && cmpEnd == 1) {
  9743. cursor = range.end;
  9744. anchor = range.start;
  9745. } else {
  9746. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  9747. cursor = orientedRange.cursor;
  9748. anchor = orientedRange.anchor;
  9749. }
  9750. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  9751. }
  9752. editor.selection.selectToPosition(cursor);
  9753. editor.renderer.scrollCursorIntoView();
  9754. };
  9755. this.selectEnd =
  9756. this.selectAllEnd =
  9757. this.selectByWordsEnd =
  9758. this.selectByLinesEnd = function() {
  9759. this.$clickSelection = null;
  9760. this.editor.unsetStyle("ace_selecting");
  9761. if (this.editor.renderer.scroller.releaseCapture) {
  9762. this.editor.renderer.scroller.releaseCapture();
  9763. }
  9764. };
  9765. this.focusWait = function() {
  9766. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  9767. var time = Date.now();
  9768. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)
  9769. this.startSelect(this.mousedownEvent.getDocumentPosition());
  9770. };
  9771. this.onDoubleClick = function(ev) {
  9772. var pos = ev.getDocumentPosition();
  9773. var editor = this.editor;
  9774. var session = editor.session;
  9775. var range = session.getBracketRange(pos);
  9776. if (range) {
  9777. if (range.isEmpty()) {
  9778. range.start.column--;
  9779. range.end.column++;
  9780. }
  9781. this.setState("select");
  9782. } else {
  9783. range = editor.selection.getWordRange(pos.row, pos.column);
  9784. this.setState("selectByWords");
  9785. }
  9786. this.$clickSelection = range;
  9787. this[this.state] && this[this.state](ev);
  9788. };
  9789. this.onTripleClick = function(ev) {
  9790. var pos = ev.getDocumentPosition();
  9791. var editor = this.editor;
  9792. this.setState("selectByLines");
  9793. this.$clickSelection = editor.selection.getLineRange(pos.row);
  9794. this[this.state] && this[this.state](ev);
  9795. };
  9796. this.onQuadClick = function(ev) {
  9797. var editor = this.editor;
  9798. editor.selectAll();
  9799. this.$clickSelection = editor.getSelectionRange();
  9800. this.setState("selectAll");
  9801. };
  9802. this.onMouseWheel = function(ev) {
  9803. if (ev.getAccelKey())
  9804. return;
  9805. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  9806. ev.wheelX = ev.wheelY;
  9807. ev.wheelY = 0;
  9808. }
  9809. var t = ev.domEvent.timeStamp;
  9810. var dt = t - (this.$lastScrollTime||0);
  9811. var editor = this.editor;
  9812. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  9813. if (isScrolable || dt < 200) {
  9814. this.$lastScrollTime = t;
  9815. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  9816. return ev.stop();
  9817. }
  9818. };
  9819. }).call(DefaultHandlers.prototype);
  9820. exports.DefaultHandlers = DefaultHandlers;
  9821. function calcDistance(ax, ay, bx, by) {
  9822. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  9823. }
  9824. function calcRangeOrientation(range, cursor) {
  9825. if (range.start.row == range.end.row)
  9826. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  9827. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  9828. var cmp = cursor.column - 4;
  9829. else
  9830. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  9831. if (cmp < 0)
  9832. return {cursor: range.start, anchor: range.end};
  9833. else
  9834. return {cursor: range.end, anchor: range.start};
  9835. }
  9836. });
  9837. ace.define('ace/renderloop', ['require', 'exports', 'module' , 'ace/lib/event'], function(require, exports, module) {
  9838. var event = require("./lib/event");
  9839. var RenderLoop = function(onRender, win) {
  9840. this.onRender = onRender;
  9841. this.pending = false;
  9842. this.changes = 0;
  9843. this.window = win || window;
  9844. };
  9845. (function() {
  9846. this.schedule = function(change) {
  9847. this.changes = this.changes | change;
  9848. if (!this.pending && this.changes) {
  9849. this.pending = true;
  9850. var _self = this;
  9851. event.nextFrame(function() {
  9852. _self.pending = false;
  9853. var changes;
  9854. while (changes = _self.changes) {
  9855. _self.changes = 0;
  9856. _self.onRender(changes);
  9857. }
  9858. }, this.window);
  9859. }
  9860. };
  9861. }).call(RenderLoop.prototype);
  9862. exports.RenderLoop = RenderLoop;
  9863. });
  9864. ace.define('ace/mouse/mouse_handler', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/lib/useragent', 'ace/mouse/default_handlers', 'ace/mouse/default_gutter_handler', 'ace/mouse/mouse_event', 'ace/mouse/dragdrop_handler', 'ace/config'], function(require, exports, module) {
  9865. var event = require("../lib/event");
  9866. var useragent = require("../lib/useragent");
  9867. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  9868. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  9869. var MouseEvent = require("./mouse_event").MouseEvent;
  9870. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  9871. var config = require("../config");
  9872. var MouseHandler = function(editor) {
  9873. var _self = this;
  9874. this.editor = editor;
  9875. new DefaultHandlers(this);
  9876. new DefaultGutterHandler(this);
  9877. new DragdropHandler(this);
  9878. var focusEditor = function(e) { editor.focus() };
  9879. var mouseTarget = editor.renderer.getMouseEventTarget();
  9880. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  9881. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  9882. event.addMultiMouseDownListener(mouseTarget, [400, 300, 250], this, "onMouseEvent");
  9883. if (editor.renderer.scrollBarV) {
  9884. event.addMultiMouseDownListener(editor.renderer.scrollBarV.inner, [400, 300, 250], this, "onMouseEvent");
  9885. event.addMultiMouseDownListener(editor.renderer.scrollBarH.inner, [400, 300, 250], this, "onMouseEvent");
  9886. if (useragent.isIE) {
  9887. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  9888. event.addListener(editor.renderer.scrollBarH.element, "mousemove", focusEditor);
  9889. }
  9890. }
  9891. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  9892. var gutterEl = editor.renderer.$gutter;
  9893. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  9894. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  9895. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  9896. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  9897. event.addListener(mouseTarget, "mousedown", focusEditor);
  9898. event.addListener(gutterEl, "mousedown", function(e) {
  9899. editor.focus();
  9900. return event.preventDefault(e);
  9901. });
  9902. editor.on("mousemove", function(e){
  9903. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  9904. return;
  9905. var char = editor.renderer.screenToTextCoordinates(e.x, e.y);
  9906. var range = editor.session.selection.getRange();
  9907. var renderer = editor.renderer;
  9908. if (!range.isEmpty() && range.insideStart(char.row, char.column)) {
  9909. renderer.setCursorStyle("default");
  9910. } else {
  9911. renderer.setCursorStyle("");
  9912. }
  9913. });
  9914. };
  9915. (function() {
  9916. this.onMouseEvent = function(name, e) {
  9917. this.editor._emit(name, new MouseEvent(e, this.editor));
  9918. };
  9919. this.onMouseMove = function(name, e) {
  9920. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  9921. if (!listeners || !listeners.length)
  9922. return;
  9923. this.editor._emit(name, new MouseEvent(e, this.editor));
  9924. };
  9925. this.onMouseWheel = function(name, e) {
  9926. var mouseEvent = new MouseEvent(e, this.editor);
  9927. mouseEvent.speed = this.$scrollSpeed * 2;
  9928. mouseEvent.wheelX = e.wheelX;
  9929. mouseEvent.wheelY = e.wheelY;
  9930. this.editor._emit(name, mouseEvent);
  9931. };
  9932. this.setState = function(state) {
  9933. this.state = state;
  9934. };
  9935. this.captureMouse = function(ev, mouseMoveHandler) {
  9936. this.x = ev.x;
  9937. this.y = ev.y;
  9938. this.isMousePressed = true;
  9939. var renderer = this.editor.renderer;
  9940. if (renderer.$keepTextAreaAtCursor)
  9941. renderer.$keepTextAreaAtCursor = null;
  9942. var self = this;
  9943. var onMouseMove = function(e) {
  9944. if (!e) return;
  9945. if (useragent.isWebKit && !e.which && self.releaseMouse)
  9946. return self.releaseMouse();
  9947. self.x = e.clientX;
  9948. self.y = e.clientY;
  9949. mouseMoveHandler && mouseMoveHandler(e);
  9950. self.mouseEvent = new MouseEvent(e, self.editor);
  9951. self.$mouseMoved = true;
  9952. };
  9953. var onCaptureEnd = function(e) {
  9954. clearInterval(timerId);
  9955. onCaptureInterval();
  9956. self[self.state + "End"] && self[self.state + "End"](e);
  9957. self.state = "";
  9958. if (renderer.$keepTextAreaAtCursor == null) {
  9959. renderer.$keepTextAreaAtCursor = true;
  9960. renderer.$moveTextAreaToCursor();
  9961. }
  9962. self.isMousePressed = false;
  9963. self.$onCaptureMouseMove = self.releaseMouse = null;
  9964. e && self.onMouseEvent("mouseup", e);
  9965. };
  9966. var onCaptureInterval = function() {
  9967. self[self.state] && self[self.state]();
  9968. self.$mouseMoved = false;
  9969. };
  9970. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  9971. return setTimeout(function() {onCaptureEnd(ev);});
  9972. }
  9973. self.$onCaptureMouseMove = onMouseMove;
  9974. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  9975. var timerId = setInterval(onCaptureInterval, 20);
  9976. };
  9977. this.releaseMouse = null;
  9978. }).call(MouseHandler.prototype);
  9979. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  9980. scrollSpeed: {initialValue: 2},
  9981. dragDelay: {initialValue: 150},
  9982. dragEnabled: {initialValue: true},
  9983. focusTimout: {initialValue: 0},
  9984. tooltipFollowsMouse: {initialValue: true}
  9985. });
  9986. exports.MouseHandler = MouseHandler;
  9987. });
  9988. ace.define('ace/layer/font_metrics', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/lang', 'ace/lib/useragent', 'ace/lib/event_emitter'], function(require, exports, module) {
  9989. var oop = require("../lib/oop");
  9990. var dom = require("../lib/dom");
  9991. var lang = require("../lib/lang");
  9992. var useragent = require("../lib/useragent");
  9993. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  9994. var CHAR_COUNT = 0;
  9995. var FontMetrics = exports.FontMetrics = function(parentEl, interval) {
  9996. this.el = dom.createElement("div");
  9997. this.$setMeasureNodeStyles(this.el.style, true);
  9998. this.$main = dom.createElement("div");
  9999. this.$setMeasureNodeStyles(this.$main.style);
  10000. this.$measureNode = dom.createElement("div");
  10001. this.$setMeasureNodeStyles(this.$measureNode.style);
  10002. this.el.appendChild(this.$main);
  10003. this.el.appendChild(this.$measureNode);
  10004. parentEl.appendChild(this.el);
  10005. if (!CHAR_COUNT)
  10006. this.$testFractionalRect();
  10007. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  10008. this.$characterSize = {width: 0, height: 0};
  10009. this.checkForSizeChanges();
  10010. };
  10011. (function() {
  10012. oop.implement(this, EventEmitter);
  10013. this.$characterSize = {width: 0, height: 0};
  10014. this.$testFractionalRect = function() {
  10015. var el = dom.createElement("div");
  10016. this.$setMeasureNodeStyles(el.style);
  10017. el.style.width = "0.2px";
  10018. document.documentElement.appendChild(el);
  10019. var w = el.getBoundingClientRect().width;
  10020. if (w > 0 && w < 1)
  10021. CHAR_COUNT = 1;
  10022. else
  10023. CHAR_COUNT = 100;
  10024. el.parentNode.removeChild(el);
  10025. };
  10026. this.$setMeasureNodeStyles = function(style, isRoot) {
  10027. style.width = style.height = "auto";
  10028. style.left = style.top = "-100px";
  10029. style.visibility = "hidden";
  10030. style.position = "fixed";
  10031. style.whiteSpace = "pre";
  10032. if (useragent.isIE < 8) {
  10033. style["font-family"] = "inherit";
  10034. } else {
  10035. style.font = "inherit";
  10036. }
  10037. style.overflow = isRoot ? "hidden" : "visible";
  10038. };
  10039. this.checkForSizeChanges = function() {
  10040. var size = this.$measureSizes();
  10041. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  10042. this.$measureNode.style.fontWeight = "bold";
  10043. var boldSize = this.$measureSizes();
  10044. this.$measureNode.style.fontWeight = "";
  10045. this.$characterSize = size;
  10046. this.charSizes = Object.create(null);
  10047. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  10048. this._emit("changeCharacterSize", {data: size});
  10049. }
  10050. };
  10051. this.$pollSizeChanges = function() {
  10052. if (this.$pollSizeChangesTimer)
  10053. return this.$pollSizeChangesTimer;
  10054. var self = this;
  10055. return this.$pollSizeChangesTimer = setInterval(function() {
  10056. self.checkForSizeChanges();
  10057. }, 500);
  10058. };
  10059. this.setPolling = function(val) {
  10060. if (val) {
  10061. this.$pollSizeChanges();
  10062. } else {
  10063. if (this.$pollSizeChangesTimer)
  10064. this.$pollSizeChangesTimer;
  10065. }
  10066. };
  10067. this.$measureSizes = function() {
  10068. if (CHAR_COUNT === 1) {
  10069. var rect = this.$measureNode.getBoundingClientRect();
  10070. var size = {
  10071. height: rect.height,
  10072. width: rect.width
  10073. };
  10074. } else {
  10075. var size = {
  10076. height: this.$measureNode.clientHeight,
  10077. width: this.$measureNode.clientWidth / CHAR_COUNT
  10078. };
  10079. }
  10080. if (size.width === 0 || size.height === 0)
  10081. return null;
  10082. return size;
  10083. };
  10084. this.$measureCharWidth = function(ch) {
  10085. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  10086. var rect = this.$main.getBoundingClientRect();
  10087. return rect.width / CHAR_COUNT;
  10088. };
  10089. this.getCharacterWidth = function(ch) {
  10090. var w = this.charSizes[ch];
  10091. if (w === undefined) {
  10092. this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  10093. }
  10094. return w;
  10095. };
  10096. this.destroy = function() {
  10097. clearInterval(this.$pollSizeChangesTimer);
  10098. if (this.el && this.el.parentNode)
  10099. this.el.parentNode.removeChild(this.el);
  10100. };
  10101. }).call(FontMetrics.prototype);
  10102. });
  10103. ace.define('ace/keyboard/textinput', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/lib/useragent', 'ace/lib/dom', 'ace/lib/lang'], function(require, exports, module) {
  10104. var event = require("../lib/event");
  10105. var useragent = require("../lib/useragent");
  10106. var dom = require("../lib/dom");
  10107. var lang = require("../lib/lang");
  10108. var BROKEN_SETDATA = useragent.isChrome < 18;
  10109. var USE_IE_MIME_TYPE = useragent.isIE;
  10110. var TextInput = function(parentNode, host) {
  10111. var text = dom.createElement("textarea");
  10112. text.className = "ace_text-input";
  10113. if (useragent.isTouchPad)
  10114. text.setAttribute("x-palm-disable-auto-cap", true);
  10115. text.wrap = "off";
  10116. text.autocorrect = "off";
  10117. text.autocapitalize = "off";
  10118. text.spellcheck = false;
  10119. text.style.opacity = "0";
  10120. parentNode.insertBefore(text, parentNode.firstChild);
  10121. var PLACEHOLDER = "\x01\x01";
  10122. var copied = false;
  10123. var pasted = false;
  10124. var inComposition = false;
  10125. var tempStyle = '';
  10126. var isSelectionEmpty = true;
  10127. try { var isFocused = document.activeElement === text; } catch(e) {}
  10128. event.addListener(text, "blur", function() {
  10129. host.onBlur();
  10130. isFocused = false;
  10131. });
  10132. event.addListener(text, "focus", function() {
  10133. isFocused = true;
  10134. host.onFocus();
  10135. resetSelection();
  10136. });
  10137. this.focus = function() { text.focus(); };
  10138. this.blur = function() { text.blur(); };
  10139. this.isFocused = function() {
  10140. return isFocused;
  10141. };
  10142. var syncSelection = lang.delayedCall(function() {
  10143. isFocused && resetSelection(isSelectionEmpty);
  10144. });
  10145. var syncValue = lang.delayedCall(function() {
  10146. if (!inComposition) {
  10147. text.value = PLACEHOLDER;
  10148. isFocused && resetSelection();
  10149. }
  10150. });
  10151. function resetSelection(isEmpty) {
  10152. if (inComposition)
  10153. return;
  10154. if (inputHandler) {
  10155. selectionStart = 0;
  10156. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  10157. } else {
  10158. var selectionStart = isEmpty ? 2 : 1;
  10159. var selectionEnd = 2;
  10160. }
  10161. try {
  10162. text.setSelectionRange(selectionStart, selectionEnd);
  10163. } catch(e){}
  10164. }
  10165. function resetValue() {
  10166. if (inComposition)
  10167. return;
  10168. text.value = PLACEHOLDER;
  10169. if (useragent.isWebKit)
  10170. syncValue.schedule();
  10171. }
  10172. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  10173. if (host.selection.isEmpty() != isSelectionEmpty) {
  10174. isSelectionEmpty = !isSelectionEmpty;
  10175. syncSelection.schedule();
  10176. }
  10177. });
  10178. resetValue();
  10179. if (isFocused)
  10180. host.onFocus();
  10181. var isAllSelected = function(text) {
  10182. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  10183. };
  10184. if (!text.setSelectionRange && text.createTextRange) {
  10185. text.setSelectionRange = function(selectionStart, selectionEnd) {
  10186. var range = this.createTextRange();
  10187. range.collapse(true);
  10188. range.moveStart('character', selectionStart);
  10189. range.moveEnd('character', selectionEnd);
  10190. range.select();
  10191. };
  10192. isAllSelected = function(text) {
  10193. try {
  10194. var range = text.ownerDocument.selection.createRange();
  10195. }catch(e) {}
  10196. if (!range || range.parentElement() != text) return false;
  10197. return range.text == text.value;
  10198. }
  10199. }
  10200. if (useragent.isOldIE) {
  10201. var inPropertyChange = false;
  10202. var onPropertyChange = function(e){
  10203. if (inPropertyChange)
  10204. return;
  10205. var data = text.value;
  10206. if (inComposition || !data || data == PLACEHOLDER)
  10207. return;
  10208. if (e && data == PLACEHOLDER[0])
  10209. return syncProperty.schedule();
  10210. sendText(data);
  10211. inPropertyChange = true;
  10212. resetValue();
  10213. inPropertyChange = false;
  10214. };
  10215. var syncProperty = lang.delayedCall(onPropertyChange);
  10216. event.addListener(text, "propertychange", onPropertyChange);
  10217. var keytable = { 13:1, 27:1 };
  10218. event.addListener(text, "keyup", function (e) {
  10219. if (inComposition && (!text.value || keytable[e.keyCode]))
  10220. setTimeout(onCompositionEnd, 0);
  10221. if ((text.value.charCodeAt(0)||0) < 129) {
  10222. return syncProperty.call();
  10223. }
  10224. inComposition ? onCompositionUpdate() : onCompositionStart();
  10225. });
  10226. event.addListener(text, "keydown", function (e) {
  10227. syncProperty.schedule(50);
  10228. });
  10229. }
  10230. var onSelect = function(e) {
  10231. if (copied) {
  10232. copied = false;
  10233. } else if (isAllSelected(text)) {
  10234. host.selectAll();
  10235. resetSelection();
  10236. } else if (inputHandler) {
  10237. resetSelection(host.selection.isEmpty());
  10238. }
  10239. };
  10240. var inputHandler = null;
  10241. this.setInputHandler = function(cb) {inputHandler = cb};
  10242. this.getInputHandler = function() {return inputHandler};
  10243. var afterContextMenu = false;
  10244. var sendText = function(data) {
  10245. if (inputHandler) {
  10246. data = inputHandler(data);
  10247. inputHandler = null;
  10248. }
  10249. if (pasted) {
  10250. resetSelection();
  10251. if (data)
  10252. host.onPaste(data);
  10253. pasted = false;
  10254. } else if (data == PLACEHOLDER.charAt(0)) {
  10255. if (afterContextMenu)
  10256. host.execCommand("del", {source: "ace"});
  10257. else // some versions of android do not fire keydown when pressing backspace
  10258. host.execCommand("backspace", {source: "ace"});
  10259. } else {
  10260. if (data.substring(0, 2) == PLACEHOLDER)
  10261. data = data.substr(2);
  10262. else if (data.charAt(0) == PLACEHOLDER.charAt(0))
  10263. data = data.substr(1);
  10264. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  10265. data = data.slice(0, -1);
  10266. if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  10267. data = data.slice(0, -1);
  10268. if (data)
  10269. host.onTextInput(data);
  10270. }
  10271. if (afterContextMenu)
  10272. afterContextMenu = false;
  10273. };
  10274. var onInput = function(e) {
  10275. if (inComposition)
  10276. return;
  10277. var data = text.value;
  10278. sendText(data);
  10279. resetValue();
  10280. };
  10281. var handleClipboardData = function(e, data) {
  10282. var clipboardData = e.clipboardData || window.clipboardData;
  10283. if (!clipboardData || BROKEN_SETDATA)
  10284. return;
  10285. var mime = USE_IE_MIME_TYPE ? "Text" : "text/plain";
  10286. if (data) {
  10287. return clipboardData.setData(mime, data) !== false;
  10288. } else {
  10289. return clipboardData.getData(mime);
  10290. }
  10291. }
  10292. var doCopy = function(e, isCut) {
  10293. var data = host.getCopyText();
  10294. if (!data)
  10295. return event.preventDefault(e);
  10296. if (handleClipboardData(e, data)) {
  10297. isCut ? host.onCut() : host.onCopy();
  10298. event.preventDefault(e);
  10299. } else {
  10300. copied = true;
  10301. text.value = data;
  10302. text.select();
  10303. setTimeout(function(){
  10304. copied = false;
  10305. resetValue();
  10306. resetSelection();
  10307. isCut ? host.onCut() : host.onCopy();
  10308. });
  10309. }
  10310. };
  10311. var onCut = function(e) {
  10312. doCopy(e, true);
  10313. }
  10314. var onCopy = function(e) {
  10315. doCopy(e, false);
  10316. }
  10317. var onPaste = function(e) {
  10318. var data = handleClipboardData(e);
  10319. if (typeof data == "string") {
  10320. if (data)
  10321. host.onPaste(data);
  10322. if (useragent.isIE)
  10323. setTimeout(resetSelection);
  10324. event.preventDefault(e);
  10325. }
  10326. else {
  10327. text.value = "";
  10328. pasted = true;
  10329. }
  10330. };
  10331. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  10332. event.addListener(text, "select", onSelect);
  10333. event.addListener(text, "input", onInput);
  10334. event.addListener(text, "cut", onCut);
  10335. event.addListener(text, "copy", onCopy);
  10336. event.addListener(text, "paste", onPaste);
  10337. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)){
  10338. event.addListener(parentNode, "keydown", function(e) {
  10339. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  10340. return;
  10341. switch (e.keyCode) {
  10342. case 67:
  10343. onCopy(e);
  10344. break;
  10345. case 86:
  10346. onPaste(e);
  10347. break;
  10348. case 88:
  10349. onCut(e);
  10350. break;
  10351. }
  10352. });
  10353. }
  10354. var onCompositionStart = function(e) {
  10355. if (inComposition || !host.onCompositionStart) return;
  10356. inComposition = {};
  10357. host.onCompositionStart();
  10358. setTimeout(onCompositionUpdate, 0);
  10359. host.on("mousedown", onCompositionEnd);
  10360. if (!host.selection.isEmpty()) {
  10361. host.insert("");
  10362. host.session.markUndoGroup();
  10363. host.selection.clearSelection();
  10364. }
  10365. host.session.markUndoGroup();
  10366. };
  10367. var onCompositionUpdate = function() {
  10368. if (!inComposition || !host.onCompositionUpdate) return;
  10369. var val = text.value.replace(/\x01/g, "");
  10370. if (inComposition.lastValue === val) return;
  10371. host.onCompositionUpdate(val);
  10372. if (inComposition.lastValue)
  10373. host.undo();
  10374. inComposition.lastValue = val;
  10375. if (inComposition.lastValue) {
  10376. var r = host.selection.getRange();
  10377. host.insert(inComposition.lastValue);
  10378. host.session.markUndoGroup();
  10379. inComposition.range = host.selection.getRange();
  10380. host.selection.setRange(r);
  10381. host.selection.clearSelection();
  10382. }
  10383. };
  10384. var onCompositionEnd = function(e) {
  10385. if (!host.onCompositionEnd) return;
  10386. var c = inComposition;
  10387. inComposition = false;
  10388. var timer = setTimeout(function() {
  10389. timer = null;
  10390. var str = text.value.replace(/\x01/g, "");
  10391. if (inComposition)
  10392. return
  10393. else if (str == c.lastValue)
  10394. resetValue();
  10395. else if (!c.lastValue && str) {
  10396. resetValue();
  10397. sendText(str);
  10398. }
  10399. });
  10400. inputHandler = function compositionInputHandler(str) {
  10401. if (timer)
  10402. clearTimeout(timer);
  10403. str = str.replace(/\x01/g, "");
  10404. if (str == c.lastValue)
  10405. return "";
  10406. if (c.lastValue && timer)
  10407. host.undo();
  10408. return str;
  10409. };
  10410. host.onCompositionEnd();
  10411. host.removeListener("mousedown", onCompositionEnd);
  10412. if (e.type == "compositionend" && c.range) {
  10413. host.selection.setRange(c.range);
  10414. }
  10415. };
  10416. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  10417. event.addListener(text, "compositionstart", onCompositionStart);
  10418. if (useragent.isGecko) {
  10419. event.addListener(text, "text", function(){syncComposition.schedule()});
  10420. } else {
  10421. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  10422. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  10423. }
  10424. event.addListener(text, "compositionend", onCompositionEnd);
  10425. this.getElement = function() {
  10426. return text;
  10427. };
  10428. this.setReadOnly = function(readOnly) {
  10429. text.readOnly = readOnly;
  10430. };
  10431. this.onContextMenu = function(e) {
  10432. afterContextMenu = true;
  10433. if (!tempStyle)
  10434. tempStyle = text.style.cssText;
  10435. text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : "");
  10436. resetSelection(host.selection.isEmpty());
  10437. host._emit("nativecontextmenu", {target: host, domEvent: e});
  10438. var rect = host.container.getBoundingClientRect();
  10439. var style = dom.computedStyle(host.container);
  10440. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  10441. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  10442. var maxTop = rect.bottom - top - text.clientHeight;
  10443. var move = function(e) {
  10444. text.style.left = e.clientX - left - 2 + "px";
  10445. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  10446. };
  10447. move(e);
  10448. if (e.type != "mousedown")
  10449. return;
  10450. if (host.renderer.$keepTextAreaAtCursor)
  10451. host.renderer.$keepTextAreaAtCursor = null;
  10452. if (useragent.isWin)
  10453. event.capture(host.container, move, onContextMenuClose);
  10454. };
  10455. this.onContextMenuClose = onContextMenuClose;
  10456. function onContextMenuClose() {
  10457. setTimeout(function () {
  10458. if (tempStyle) {
  10459. text.style.cssText = tempStyle;
  10460. tempStyle = '';
  10461. }
  10462. if (host.renderer.$keepTextAreaAtCursor == null) {
  10463. host.renderer.$keepTextAreaAtCursor = true;
  10464. host.renderer.$moveTextAreaToCursor();
  10465. }
  10466. }, 0);
  10467. }
  10468. if (!useragent.isGecko || useragent.isMac) {
  10469. var onContextMenu = function(e) {
  10470. host.textInput.onContextMenu(e);
  10471. onContextMenuClose();
  10472. };
  10473. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  10474. event.addListener(text, "contextmenu", onContextMenu);
  10475. }
  10476. };
  10477. exports.TextInput = TextInput;
  10478. });
  10479. ace.define('ace/lib/lang', ['require', 'exports', 'module' ], function(require, exports, module) {
  10480. exports.last = function(a) {
  10481. return a[a.length - 1];
  10482. };
  10483. exports.stringReverse = function(string) {
  10484. return string.split("").reverse().join("");
  10485. };
  10486. exports.stringRepeat = function (string, count) {
  10487. var result = '';
  10488. while (count > 0) {
  10489. if (count & 1)
  10490. result += string;
  10491. if (count >>= 1)
  10492. string += string;
  10493. }
  10494. return result;
  10495. };
  10496. var trimBeginRegexp = /^\s\s*/;
  10497. var trimEndRegexp = /\s\s*$/;
  10498. exports.stringTrimLeft = function (string) {
  10499. return string.replace(trimBeginRegexp, '');
  10500. };
  10501. exports.stringTrimRight = function (string) {
  10502. return string.replace(trimEndRegexp, '');
  10503. };
  10504. exports.copyObject = function(obj) {
  10505. var copy = {};
  10506. for (var key in obj) {
  10507. copy[key] = obj[key];
  10508. }
  10509. return copy;
  10510. };
  10511. exports.copyArray = function(array){
  10512. var copy = [];
  10513. for (var i=0, l=array.length; i<l; i++) {
  10514. if (array[i] && typeof array[i] == "object")
  10515. copy[i] = this.copyObject( array[i] );
  10516. else
  10517. copy[i] = array[i];
  10518. }
  10519. return copy;
  10520. };
  10521. exports.deepCopy = function (obj) {
  10522. if (typeof obj !== "object" || !obj)
  10523. return obj;
  10524. var cons = obj.constructor;
  10525. if (cons === RegExp)
  10526. return obj;
  10527. var copy = cons();
  10528. for (var key in obj) {
  10529. if (typeof obj[key] === "object") {
  10530. copy[key] = exports.deepCopy(obj[key]);
  10531. } else {
  10532. copy[key] = obj[key];
  10533. }
  10534. }
  10535. return copy;
  10536. };
  10537. exports.arrayToMap = function(arr) {
  10538. var map = {};
  10539. for (var i=0; i<arr.length; i++) {
  10540. map[arr[i]] = 1;
  10541. }
  10542. return map;
  10543. };
  10544. exports.createMap = function(props) {
  10545. var map = Object.create(null);
  10546. for (var i in props) {
  10547. map[i] = props[i];
  10548. }
  10549. return map;
  10550. };
  10551. exports.arrayRemove = function(array, value) {
  10552. for (var i = 0; i <= array.length; i++) {
  10553. if (value === array[i]) {
  10554. array.splice(i, 1);
  10555. }
  10556. }
  10557. };
  10558. exports.escapeRegExp = function(str) {
  10559. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  10560. };
  10561. exports.escapeHTML = function(str) {
  10562. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  10563. };
  10564. exports.getMatchOffsets = function(string, regExp) {
  10565. var matches = [];
  10566. string.replace(regExp, function(str) {
  10567. matches.push({
  10568. offset: arguments[arguments.length-2],
  10569. length: str.length
  10570. });
  10571. });
  10572. return matches;
  10573. };
  10574. exports.deferredCall = function(fcn) {
  10575. var timer = null;
  10576. var callback = function() {
  10577. timer = null;
  10578. fcn();
  10579. };
  10580. var deferred = function(timeout) {
  10581. deferred.cancel();
  10582. timer = setTimeout(callback, timeout || 0);
  10583. return deferred;
  10584. };
  10585. deferred.schedule = deferred;
  10586. deferred.call = function() {
  10587. this.cancel();
  10588. fcn();
  10589. return deferred;
  10590. };
  10591. deferred.cancel = function() {
  10592. clearTimeout(timer);
  10593. timer = null;
  10594. return deferred;
  10595. };
  10596. deferred.isPending = function() {
  10597. return timer;
  10598. };
  10599. return deferred;
  10600. };
  10601. exports.delayedCall = function(fcn, defaultTimeout) {
  10602. var timer = null;
  10603. var callback = function() {
  10604. timer = null;
  10605. fcn();
  10606. };
  10607. var _self = function(timeout) {
  10608. if (timer == null)
  10609. timer = setTimeout(callback, timeout || defaultTimeout);
  10610. };
  10611. _self.delay = function(timeout) {
  10612. timer && clearTimeout(timer);
  10613. timer = setTimeout(callback, timeout || defaultTimeout);
  10614. };
  10615. _self.schedule = _self;
  10616. _self.call = function() {
  10617. this.cancel();
  10618. fcn();
  10619. };
  10620. _self.cancel = function() {
  10621. timer && clearTimeout(timer);
  10622. timer = null;
  10623. };
  10624. _self.isPending = function() {
  10625. return timer;
  10626. };
  10627. return _self;
  10628. };
  10629. });
  10630. ace.define('ace/worker/worker_client', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/net', 'ace/lib/event_emitter', 'ace/config'], function(require, exports, module) {
  10631. var oop = require("../lib/oop");
  10632. var net = require("../lib/net");
  10633. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10634. var config = require("../config");
  10635. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl) {
  10636. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  10637. this.changeListener = this.changeListener.bind(this);
  10638. this.onMessage = this.onMessage.bind(this);
  10639. if (require.nameToUrl && !require.toUrl)
  10640. require.toUrl = require.nameToUrl;
  10641. if (config.get("packaged") || !require.toUrl) {
  10642. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  10643. } else {
  10644. var normalizePath = this.$normalizePath;
  10645. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  10646. var tlns = {};
  10647. topLevelNamespaces.forEach(function(ns) {
  10648. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  10649. });
  10650. }
  10651. try {
  10652. this.$worker = new Worker(workerUrl);
  10653. } catch(e) {
  10654. if (e instanceof window.DOMException) {
  10655. var blob = this.$workerBlob(workerUrl);
  10656. var URL = window.URL || window.webkitURL;
  10657. var blobURL = URL.createObjectURL(blob);
  10658. this.$worker = new Worker(blobURL);
  10659. URL.revokeObjectURL(blobURL);
  10660. } else {
  10661. throw e;
  10662. }
  10663. }
  10664. this.$worker.postMessage({
  10665. init : true,
  10666. tlns : tlns,
  10667. module : mod,
  10668. classname : classname
  10669. });
  10670. this.callbackId = 1;
  10671. this.callbacks = {};
  10672. this.$worker.onmessage = this.onMessage;
  10673. };
  10674. (function(){
  10675. oop.implement(this, EventEmitter);
  10676. this.onMessage = function(e) {
  10677. var msg = e.data;
  10678. switch(msg.type) {
  10679. case "log":
  10680. window.console && console.log && console.log.apply(console, msg.data);
  10681. break;
  10682. case "event":
  10683. this._signal(msg.name, {data: msg.data});
  10684. break;
  10685. case "call":
  10686. var callback = this.callbacks[msg.id];
  10687. if (callback) {
  10688. callback(msg.data);
  10689. delete this.callbacks[msg.id];
  10690. }
  10691. break;
  10692. }
  10693. };
  10694. this.$normalizePath = function(path) {
  10695. return net.qualifyURL(path);
  10696. };
  10697. this.terminate = function() {
  10698. this._signal("terminate", {});
  10699. this.deltaQueue = null;
  10700. this.$worker.terminate();
  10701. this.$worker = null;
  10702. this.$doc.removeEventListener("change", this.changeListener);
  10703. this.$doc = null;
  10704. };
  10705. this.send = function(cmd, args) {
  10706. this.$worker.postMessage({command: cmd, args: args});
  10707. };
  10708. this.call = function(cmd, args, callback) {
  10709. if (callback) {
  10710. var id = this.callbackId++;
  10711. this.callbacks[id] = callback;
  10712. args.push(id);
  10713. }
  10714. this.send(cmd, args);
  10715. };
  10716. this.emit = function(event, data) {
  10717. try {
  10718. this.$worker.postMessage({event: event, data: {data: data.data}});
  10719. }
  10720. catch(ex) {
  10721. console.error(ex.stack);
  10722. }
  10723. };
  10724. this.attachToDocument = function(doc) {
  10725. if(this.$doc)
  10726. this.terminate();
  10727. this.$doc = doc;
  10728. this.call("setValue", [doc.getValue()]);
  10729. doc.on("change", this.changeListener);
  10730. };
  10731. this.changeListener = function(e) {
  10732. if (!this.deltaQueue) {
  10733. this.deltaQueue = [e.data];
  10734. setTimeout(this.$sendDeltaQueue, 0);
  10735. } else
  10736. this.deltaQueue.push(e.data);
  10737. };
  10738. this.$sendDeltaQueue = function() {
  10739. var q = this.deltaQueue;
  10740. if (!q) return;
  10741. this.deltaQueue = null;
  10742. if (q.length > 20 && q.length > this.$doc.getLength() >> 1) {
  10743. this.call("setValue", [this.$doc.getValue()]);
  10744. } else
  10745. this.emit("change", {data: q});
  10746. };
  10747. this.$workerBlob = function(workerUrl) {
  10748. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  10749. try {
  10750. return new Blob([script], {"type": "application/javascript"});
  10751. } catch (e) { // Backwards-compatibility
  10752. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  10753. var blobBuilder = new BlobBuilder();
  10754. blobBuilder.append(script);
  10755. return blobBuilder.getBlob("application/javascript");
  10756. }
  10757. };
  10758. }).call(WorkerClient.prototype);
  10759. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  10760. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  10761. this.changeListener = this.changeListener.bind(this);
  10762. this.callbackId = 1;
  10763. this.callbacks = {};
  10764. this.messageBuffer = [];
  10765. var main = null;
  10766. var emitSync = false;
  10767. var sender = Object.create(EventEmitter);
  10768. var _self = this;
  10769. this.$worker = {};
  10770. this.$worker.terminate = function() {};
  10771. this.$worker.postMessage = function(e) {
  10772. _self.messageBuffer.push(e);
  10773. if (main) {
  10774. if (emitSync)
  10775. setTimeout(processNext);
  10776. else
  10777. processNext();
  10778. }
  10779. };
  10780. this.setEmitSync = function(val) { emitSync = val };
  10781. var processNext = function() {
  10782. var msg = _self.messageBuffer.shift();
  10783. if (msg.command)
  10784. main[msg.command].apply(main, msg.args);
  10785. else if (msg.event)
  10786. sender._signal(msg.event, msg.data);
  10787. };
  10788. sender.postMessage = function(msg) {
  10789. _self.onMessage({data: msg});
  10790. };
  10791. sender.callback = function(data, callbackId) {
  10792. this.postMessage({type: "call", id: callbackId, data: data});
  10793. };
  10794. sender.emit = function(name, data) {
  10795. this.postMessage({type: "event", name: name, data: data});
  10796. };
  10797. config.loadModule(["worker", mod], function(Main) {
  10798. main = new Main[classname](sender);
  10799. while (_self.messageBuffer.length)
  10800. processNext();
  10801. });
  10802. };
  10803. UIWorkerClient.prototype = WorkerClient.prototype;
  10804. exports.UIWorkerClient = UIWorkerClient;
  10805. exports.WorkerClient = WorkerClient;
  10806. });
  10807. ace.define('ace/editor', ['require', 'exports', 'module' , 'ace/lib/fixoldbrowsers', 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/lang', 'ace/lib/useragent', 'ace/keyboard/textinput', 'ace/mouse/mouse_handler', 'ace/mouse/fold_handler', 'ace/keyboard/keybinding', 'ace/edit_session', 'ace/search', 'ace/range', 'ace/lib/event_emitter', 'ace/commands/command_manager', 'ace/commands/default_commands', 'ace/config', 'ace/token_iterator'], function(require, exports, module) {
  10808. require("./lib/fixoldbrowsers");
  10809. var oop = require("./lib/oop");
  10810. var dom = require("./lib/dom");
  10811. var lang = require("./lib/lang");
  10812. var useragent = require("./lib/useragent");
  10813. var TextInput = require("./keyboard/textinput").TextInput;
  10814. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  10815. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  10816. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  10817. var EditSession = require("./edit_session").EditSession;
  10818. var Search = require("./search").Search;
  10819. var Range = require("./range").Range;
  10820. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  10821. var CommandManager = require("./commands/command_manager").CommandManager;
  10822. var defaultCommands = require("./commands/default_commands").commands;
  10823. var config = require("./config");
  10824. var TokenIterator = require("./token_iterator").TokenIterator;
  10825. var Editor = function(renderer, session) {
  10826. var container = renderer.getContainerElement();
  10827. this.container = container;
  10828. this.renderer = renderer;
  10829. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  10830. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  10831. this.renderer.textarea = this.textInput.getElement();
  10832. this.keyBinding = new KeyBinding(this);
  10833. this.$mouseHandler = new MouseHandler(this);
  10834. new FoldHandler(this);
  10835. this.$blockScrolling = 0;
  10836. this.$search = new Search().set({
  10837. wrap: true
  10838. });
  10839. this.$historyTracker = this.$historyTracker.bind(this);
  10840. this.commands.on("exec", this.$historyTracker);
  10841. this.$initOperationListeners();
  10842. this._$emitInputEvent = lang.delayedCall(function() {
  10843. this._signal("input", {});
  10844. this.session.bgTokenizer && this.session.bgTokenizer.scheduleStart();
  10845. }.bind(this));
  10846. this.on("change", function(_, _self) {
  10847. _self._$emitInputEvent.schedule(31);
  10848. });
  10849. this.setSession(session || new EditSession(""));
  10850. config.resetOptions(this);
  10851. config._signal("editor", this);
  10852. };
  10853. (function(){
  10854. oop.implement(this, EventEmitter);
  10855. this.$initOperationListeners = function() {
  10856. function last(a) {return a[a.length - 1]}
  10857. this.selections = [];
  10858. this.commands.on("exec", function(e) {
  10859. this.startOperation(e);
  10860. var command = e.command;
  10861. if (command.aceCommandGroup == "fileJump") {
  10862. var prev = this.prevOp;
  10863. if (!prev || prev.command.aceCommandGroup != "fileJump") {
  10864. this.lastFileJumpPos = last(this.selections);
  10865. }
  10866. } else {
  10867. this.lastFileJumpPos = null;
  10868. }
  10869. }.bind(this), true);
  10870. this.commands.on("afterExec", function(e) {
  10871. var command = e.command;
  10872. if (command.aceCommandGroup == "fileJump") {
  10873. if (this.lastFileJumpPos && !this.curOp.selectionChanged) {
  10874. this.selection.fromJSON(this.lastFileJumpPos);
  10875. }
  10876. }
  10877. this.endOperation(e);
  10878. }.bind(this), true);
  10879. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
  10880. this.on("change", function() {
  10881. this.curOp || this.startOperation();
  10882. this.curOp.docChanged = true;
  10883. }.bind(this), true);
  10884. this.on("changeSelection", function() {
  10885. this.curOp || this.startOperation();
  10886. this.curOp.selectionChanged = true;
  10887. }.bind(this), true);
  10888. };
  10889. this.curOp = null;
  10890. this.prevOp = {};
  10891. this.startOperation = function(commadEvent) {
  10892. if (this.curOp) {
  10893. if (!commadEvent || this.curOp.command)
  10894. return;
  10895. this.prevOp = this.curOp;
  10896. }
  10897. if (!commadEvent) {
  10898. this.previousCommand = null;
  10899. commadEvent = {};
  10900. }
  10901. this.$opResetTimer.schedule();
  10902. this.curOp = {
  10903. command: commadEvent.command || {},
  10904. args: commadEvent.args,
  10905. scrollTop: this.renderer.scrollTop
  10906. };
  10907. var command = this.curOp.command;
  10908. if (command && command.scrollIntoView)
  10909. this.$blockScrolling++;
  10910. this.selections.push(this.selection.toJSON());
  10911. };
  10912. this.endOperation = function() {
  10913. if (this.curOp) {
  10914. var command = this.curOp.command;
  10915. if (command && command.scrollIntoView) {
  10916. this.$blockScrolling--;
  10917. switch (command.scrollIntoView) {
  10918. case "center":
  10919. this.renderer.scrollCursorIntoView(null, 0.5);
  10920. break;
  10921. case "animate":
  10922. case "cursor":
  10923. this.renderer.scrollCursorIntoView();
  10924. break;
  10925. case "selectionPart":
  10926. var range = this.selection.getRange();
  10927. var config = this.renderer.layerConfig;
  10928. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  10929. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  10930. }
  10931. break;
  10932. default:
  10933. break;
  10934. }
  10935. if (command.scrollIntoView == "animate")
  10936. this.renderer.animateScrolling(this.curOp.scrollTop);
  10937. }
  10938. this.prevOp = this.curOp;
  10939. this.curOp = null;
  10940. }
  10941. };
  10942. this.$historyTracker = function(e) {
  10943. if (!this.$mergeUndoDeltas)
  10944. return;
  10945. var prev = this.prevOp;
  10946. var mergeableCommands = ["backspace", "del", "insertstring"];
  10947. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  10948. if (e.command.name == "insertstring") {
  10949. var text = e.args;
  10950. if (this.mergeNextCommand === undefined)
  10951. this.mergeNextCommand = true;
  10952. shouldMerge = shouldMerge
  10953. && this.mergeNextCommand // previous command allows to coalesce with
  10954. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  10955. this.mergeNextCommand = true;
  10956. } else {
  10957. shouldMerge = shouldMerge
  10958. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  10959. }
  10960. if (
  10961. this.$mergeUndoDeltas != "always"
  10962. && Date.now() - this.sequenceStartTime > 2000
  10963. ) {
  10964. shouldMerge = false; // the sequence is too long
  10965. }
  10966. if (shouldMerge)
  10967. this.session.mergeUndoDeltas = true;
  10968. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  10969. this.sequenceStartTime = Date.now();
  10970. };
  10971. this.setKeyboardHandler = function(keyboardHandler) {
  10972. if (!keyboardHandler) {
  10973. this.keyBinding.setKeyboardHandler(null);
  10974. } else if (typeof keyboardHandler === "string") {
  10975. this.$keybindingId = keyboardHandler;
  10976. var _self = this;
  10977. config.loadModule(["keybinding", keyboardHandler], function(module) {
  10978. if (_self.$keybindingId == keyboardHandler)
  10979. _self.keyBinding.setKeyboardHandler(module && module.handler);
  10980. });
  10981. } else {
  10982. this.$keybindingId = null;
  10983. this.keyBinding.setKeyboardHandler(keyboardHandler);
  10984. }
  10985. };
  10986. this.getKeyboardHandler = function() {
  10987. return this.keyBinding.getKeyboardHandler();
  10988. };
  10989. this.setSession = function(session) {
  10990. if (this.session == session)
  10991. return;
  10992. var oldSession = this.session;
  10993. if (oldSession) {
  10994. this.session.removeEventListener("change", this.$onDocumentChange);
  10995. this.session.removeEventListener("changeMode", this.$onChangeMode);
  10996. this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
  10997. this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
  10998. this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
  10999. this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
  11000. this.session.removeEventListener("onChangeFold", this.$onChangeFold);
  11001. this.session.removeEventListener("changeFrontMarker", this.$onChangeFrontMarker);
  11002. this.session.removeEventListener("changeBackMarker", this.$onChangeBackMarker);
  11003. this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
  11004. this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
  11005. this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
  11006. this.session.removeEventListener("changeScrollTop", this.$onScrollTopChange);
  11007. this.session.removeEventListener("changeScrollLeft", this.$onScrollLeftChange);
  11008. var selection = this.session.getSelection();
  11009. selection.removeEventListener("changeCursor", this.$onCursorChange);
  11010. selection.removeEventListener("changeSelection", this.$onSelectionChange);
  11011. }
  11012. this.session = session;
  11013. if (session) {
  11014. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11015. session.addEventListener("change", this.$onDocumentChange);
  11016. this.renderer.setSession(session);
  11017. this.$onChangeMode = this.onChangeMode.bind(this);
  11018. session.addEventListener("changeMode", this.$onChangeMode);
  11019. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11020. session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
  11021. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11022. session.addEventListener("changeTabSize", this.$onChangeTabSize);
  11023. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11024. session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
  11025. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11026. session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
  11027. this.$onChangeFold = this.onChangeFold.bind(this);
  11028. session.addEventListener("changeFold", this.$onChangeFold);
  11029. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11030. this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
  11031. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11032. this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
  11033. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11034. this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
  11035. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11036. this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
  11037. this.$onCursorChange = this.onCursorChange.bind(this);
  11038. this.session.addEventListener("changeOverwrite", this.$onCursorChange);
  11039. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11040. this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
  11041. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11042. this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
  11043. this.selection = session.getSelection();
  11044. this.selection.addEventListener("changeCursor", this.$onCursorChange);
  11045. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11046. this.selection.addEventListener("changeSelection", this.$onSelectionChange);
  11047. this.onChangeMode();
  11048. this.$blockScrolling += 1;
  11049. this.onCursorChange();
  11050. this.$blockScrolling -= 1;
  11051. this.onScrollTopChange();
  11052. this.onScrollLeftChange();
  11053. this.onSelectionChange();
  11054. this.onChangeFrontMarker();
  11055. this.onChangeBackMarker();
  11056. this.onChangeBreakpoint();
  11057. this.onChangeAnnotation();
  11058. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11059. this.renderer.updateFull();
  11060. }
  11061. this._signal("changeSession", {
  11062. session: session,
  11063. oldSession: oldSession
  11064. });
  11065. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11066. session && session._signal("changeEditor", {editor: this});
  11067. };
  11068. this.getSession = function() {
  11069. return this.session;
  11070. };
  11071. this.setValue = function(val, cursorPos) {
  11072. this.session.doc.setValue(val);
  11073. if (!cursorPos)
  11074. this.selectAll();
  11075. else if (cursorPos == 1)
  11076. this.navigateFileEnd();
  11077. else if (cursorPos == -1)
  11078. this.navigateFileStart();
  11079. return val;
  11080. };
  11081. this.getValue = function() {
  11082. return this.session.getValue();
  11083. };
  11084. this.getSelection = function() {
  11085. return this.selection;
  11086. };
  11087. this.resize = function(force) {
  11088. this.renderer.onResize(force);
  11089. };
  11090. this.setTheme = function(theme, cb) {
  11091. this.renderer.setTheme(theme, cb);
  11092. };
  11093. this.getTheme = function() {
  11094. return this.renderer.getTheme();
  11095. };
  11096. this.setStyle = function(style) {
  11097. this.renderer.setStyle(style);
  11098. };
  11099. this.unsetStyle = function(style) {
  11100. this.renderer.unsetStyle(style);
  11101. };
  11102. this.getFontSize = function () {
  11103. return this.getOption("fontSize") ||
  11104. dom.computedStyle(this.container, "fontSize");
  11105. };
  11106. this.setFontSize = function(size) {
  11107. this.setOption("fontSize", size);
  11108. };
  11109. this.$highlightBrackets = function() {
  11110. if (this.session.$bracketHighlight) {
  11111. this.session.removeMarker(this.session.$bracketHighlight);
  11112. this.session.$bracketHighlight = null;
  11113. }
  11114. if (this.$highlightPending) {
  11115. return;
  11116. }
  11117. var self = this;
  11118. this.$highlightPending = true;
  11119. setTimeout(function() {
  11120. self.$highlightPending = false;
  11121. var pos = self.session.findMatchingBracket(self.getCursorPosition());
  11122. if (pos) {
  11123. var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
  11124. } else if (self.session.$mode.getMatching) {
  11125. var range = self.session.$mode.getMatching(self.session);
  11126. }
  11127. if (range)
  11128. self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
  11129. }, 50);
  11130. };
  11131. this.$highlightTags = function() {
  11132. var session = this.session;
  11133. if (this.$highlightTagPending) {
  11134. return;
  11135. }
  11136. var self = this;
  11137. this.$highlightTagPending = true;
  11138. setTimeout(function() {
  11139. self.$highlightTagPending = false;
  11140. var pos = self.getCursorPosition();
  11141. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11142. var token = iterator.getCurrentToken();
  11143. if (!token || token.type.indexOf('tag-name') === -1) {
  11144. session.removeMarker(session.$tagHighlight);
  11145. session.$tagHighlight = null;
  11146. return;
  11147. }
  11148. var tag = token.value;
  11149. var depth = 0;
  11150. var prevToken = iterator.stepBackward();
  11151. if (prevToken.value == '<'){
  11152. do {
  11153. prevToken = token;
  11154. token = iterator.stepForward();
  11155. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11156. if (prevToken.value==='<'){
  11157. depth++;
  11158. } else if (prevToken.value==='</'){
  11159. depth--;
  11160. }
  11161. }
  11162. } while (token && depth>=0);
  11163. }else{
  11164. do {
  11165. token = prevToken;
  11166. prevToken = iterator.stepBackward();
  11167. if(token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11168. if (prevToken.value==='<') {
  11169. depth++;
  11170. } else if( prevToken.value==='</') {
  11171. depth--;
  11172. }
  11173. }
  11174. } while (prevToken && depth<=0);
  11175. iterator.stepForward();
  11176. }
  11177. if (!token) {
  11178. session.removeMarker(session.$tagHighlight);
  11179. session.$tagHighlight = null;
  11180. return;
  11181. }
  11182. var row = iterator.getCurrentTokenRow();
  11183. var column = iterator.getCurrentTokenColumn();
  11184. var range = new Range(row, column, row, column+token.value.length);
  11185. if (session.$tagHighlight && range.compareRange(session.$backMarkers[session.$tagHighlight].range)!==0) {
  11186. session.removeMarker(session.$tagHighlight);
  11187. session.$tagHighlight = null;
  11188. }
  11189. if (range && !session.$tagHighlight)
  11190. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11191. }, 50);
  11192. };
  11193. this.focus = function() {
  11194. var _self = this;
  11195. setTimeout(function() {
  11196. _self.textInput.focus();
  11197. });
  11198. this.textInput.focus();
  11199. };
  11200. this.isFocused = function() {
  11201. return this.textInput.isFocused();
  11202. };
  11203. this.blur = function() {
  11204. this.textInput.blur();
  11205. };
  11206. this.onFocus = function() {
  11207. if (this.$isFocused)
  11208. return;
  11209. this.$isFocused = true;
  11210. this.renderer.showCursor();
  11211. this.renderer.visualizeFocus();
  11212. this._emit("focus");
  11213. };
  11214. this.onBlur = function() {
  11215. if (!this.$isFocused)
  11216. return;
  11217. this.$isFocused = false;
  11218. this.renderer.hideCursor();
  11219. this.renderer.visualizeBlur();
  11220. this._emit("blur");
  11221. };
  11222. this.$cursorChange = function() {
  11223. this.renderer.updateCursor();
  11224. };
  11225. this.onDocumentChange = function(e) {
  11226. var delta = e.data;
  11227. var range = delta.range;
  11228. var lastRow;
  11229. if (range.start.row == range.end.row && delta.action != "insertLines" && delta.action != "removeLines")
  11230. lastRow = range.end.row;
  11231. else
  11232. lastRow = Infinity;
  11233. this.renderer.updateLines(range.start.row, lastRow);
  11234. this._signal("change", e);
  11235. this.$cursorChange();
  11236. };
  11237. this.onTokenizerUpdate = function(e) {
  11238. var rows = e.data;
  11239. this.renderer.updateLines(rows.first, rows.last);
  11240. };
  11241. this.onScrollTopChange = function() {
  11242. this.renderer.scrollToY(this.session.getScrollTop());
  11243. };
  11244. this.onScrollLeftChange = function() {
  11245. this.renderer.scrollToX(this.session.getScrollLeft());
  11246. };
  11247. this.onCursorChange = function() {
  11248. this.$cursorChange();
  11249. if (!this.$blockScrolling) {
  11250. this.renderer.scrollCursorIntoView();
  11251. }
  11252. this.$highlightBrackets();
  11253. this.$highlightTags();
  11254. this.$updateHighlightActiveLine();
  11255. this._signal("changeSelection");
  11256. };
  11257. this.$updateHighlightActiveLine = function() {
  11258. var session = this.getSession();
  11259. var highlight;
  11260. if (this.$highlightActiveLine) {
  11261. if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
  11262. highlight = this.getCursorPosition();
  11263. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11264. highlight = false;
  11265. }
  11266. if (session.$highlightLineMarker && !highlight) {
  11267. session.removeMarker(session.$highlightLineMarker.id);
  11268. session.$highlightLineMarker = null;
  11269. } else if (!session.$highlightLineMarker && highlight) {
  11270. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11271. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11272. session.$highlightLineMarker = range;
  11273. } else if (highlight) {
  11274. session.$highlightLineMarker.start.row = highlight.row;
  11275. session.$highlightLineMarker.end.row = highlight.row;
  11276. session.$highlightLineMarker.start.column = highlight.column;
  11277. session._signal("changeBackMarker");
  11278. }
  11279. };
  11280. this.onSelectionChange = function(e) {
  11281. var session = this.session;
  11282. if (session.$selectionMarker) {
  11283. session.removeMarker(session.$selectionMarker);
  11284. }
  11285. session.$selectionMarker = null;
  11286. if (!this.selection.isEmpty()) {
  11287. var range = this.selection.getRange();
  11288. var style = this.getSelectionStyle();
  11289. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11290. } else {
  11291. this.$updateHighlightActiveLine();
  11292. }
  11293. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11294. this.session.highlight(re);
  11295. this._signal("changeSelection");
  11296. };
  11297. this.$getSelectionHighLightRegexp = function() {
  11298. var session = this.session;
  11299. var selection = this.getSelectionRange();
  11300. if (selection.isEmpty() || selection.isMultiLine())
  11301. return;
  11302. var startOuter = selection.start.column - 1;
  11303. var endOuter = selection.end.column + 1;
  11304. var line = session.getLine(selection.start.row);
  11305. var lineCols = line.length;
  11306. var needle = line.substring(Math.max(startOuter, 0),
  11307. Math.min(endOuter, lineCols));
  11308. if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
  11309. (endOuter <= lineCols && /[\w\d]$/.test(needle)))
  11310. return;
  11311. needle = line.substring(selection.start.column, selection.end.column);
  11312. if (!/^[\w\d]+$/.test(needle))
  11313. return;
  11314. var re = this.$search.$assembleRegExp({
  11315. wholeWord: true,
  11316. caseSensitive: true,
  11317. needle: needle
  11318. });
  11319. return re;
  11320. };
  11321. this.onChangeFrontMarker = function() {
  11322. this.renderer.updateFrontMarkers();
  11323. };
  11324. this.onChangeBackMarker = function() {
  11325. this.renderer.updateBackMarkers();
  11326. };
  11327. this.onChangeBreakpoint = function() {
  11328. this.renderer.updateBreakpoints();
  11329. };
  11330. this.onChangeAnnotation = function() {
  11331. this.renderer.setAnnotations(this.session.getAnnotations());
  11332. };
  11333. this.onChangeMode = function(e) {
  11334. this.renderer.updateText();
  11335. this._emit("changeMode", e);
  11336. };
  11337. this.onChangeWrapLimit = function() {
  11338. this.renderer.updateFull();
  11339. };
  11340. this.onChangeWrapMode = function() {
  11341. this.renderer.onResize(true);
  11342. };
  11343. this.onChangeFold = function() {
  11344. this.$updateHighlightActiveLine();
  11345. this.renderer.updateFull();
  11346. };
  11347. this.getSelectedText = function() {
  11348. return this.session.getTextRange(this.getSelectionRange());
  11349. };
  11350. this.getCopyText = function() {
  11351. var text = this.getSelectedText();
  11352. this._signal("copy", text);
  11353. return text;
  11354. };
  11355. this.onCopy = function() {
  11356. this.commands.exec("copy", this);
  11357. };
  11358. this.onCut = function() {
  11359. this.commands.exec("cut", this);
  11360. };
  11361. this.onPaste = function(text) {
  11362. if (this.$readOnly)
  11363. return;
  11364. var e = {text: text};
  11365. this._signal("paste", e);
  11366. this.insert(e.text, true);
  11367. };
  11368. this.execCommand = function(command, args) {
  11369. this.commands.exec(command, this, args);
  11370. };
  11371. this.insert = function(text, pasted) {
  11372. var session = this.session;
  11373. var mode = session.getMode();
  11374. var cursor = this.getCursorPosition();
  11375. if (this.getBehavioursEnabled() && !pasted) {
  11376. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11377. if (transform) {
  11378. if (text !== transform.text) {
  11379. this.session.mergeUndoDeltas = false;
  11380. this.$mergeNextCommand = false;
  11381. }
  11382. text = transform.text;
  11383. }
  11384. }
  11385. if (text == "\t")
  11386. text = this.session.getTabString();
  11387. if (!this.selection.isEmpty()) {
  11388. var range = this.getSelectionRange();
  11389. cursor = this.session.remove(range);
  11390. this.clearSelection();
  11391. }
  11392. else if (this.session.getOverwrite()) {
  11393. var range = new Range.fromPoints(cursor, cursor);
  11394. range.end.column += text.length;
  11395. this.session.remove(range);
  11396. }
  11397. if (text == "\n" || text == "\r\n") {
  11398. var line = session.getLine(cursor.row);
  11399. if (cursor.column > line.search(/\S|$/)) {
  11400. var d = line.substr(cursor.column).search(/\S|$/);
  11401. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11402. }
  11403. }
  11404. this.clearSelection();
  11405. var start = cursor.column;
  11406. var lineState = session.getState(cursor.row);
  11407. var line = session.getLine(cursor.row);
  11408. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11409. var end = session.insert(cursor, text);
  11410. if (transform && transform.selection) {
  11411. if (transform.selection.length == 2) { // Transform relative to the current column
  11412. this.selection.setSelectionRange(
  11413. new Range(cursor.row, start + transform.selection[0],
  11414. cursor.row, start + transform.selection[1]));
  11415. } else { // Transform relative to the current row.
  11416. this.selection.setSelectionRange(
  11417. new Range(cursor.row + transform.selection[0],
  11418. transform.selection[1],
  11419. cursor.row + transform.selection[2],
  11420. transform.selection[3]));
  11421. }
  11422. }
  11423. if (session.getDocument().isNewLine(text)) {
  11424. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11425. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11426. }
  11427. if (shouldOutdent)
  11428. mode.autoOutdent(lineState, session, cursor.row);
  11429. };
  11430. this.onTextInput = function(text) {
  11431. this.keyBinding.onTextInput(text);
  11432. };
  11433. this.onCommandKey = function(e, hashId, keyCode) {
  11434. this.keyBinding.onCommandKey(e, hashId, keyCode);
  11435. };
  11436. this.setOverwrite = function(overwrite) {
  11437. this.session.setOverwrite(overwrite);
  11438. };
  11439. this.getOverwrite = function() {
  11440. return this.session.getOverwrite();
  11441. };
  11442. this.toggleOverwrite = function() {
  11443. this.session.toggleOverwrite();
  11444. };
  11445. this.setScrollSpeed = function(speed) {
  11446. this.setOption("scrollSpeed", speed);
  11447. };
  11448. this.getScrollSpeed = function() {
  11449. return this.getOption("scrollSpeed");
  11450. };
  11451. this.setDragDelay = function(dragDelay) {
  11452. this.setOption("dragDelay", dragDelay);
  11453. };
  11454. this.getDragDelay = function() {
  11455. return this.getOption("dragDelay");
  11456. };
  11457. this.setSelectionStyle = function(val) {
  11458. this.setOption("selectionStyle", val);
  11459. };
  11460. this.getSelectionStyle = function() {
  11461. return this.getOption("selectionStyle");
  11462. };
  11463. this.setHighlightActiveLine = function(shouldHighlight) {
  11464. this.setOption("highlightActiveLine", shouldHighlight);
  11465. };
  11466. this.getHighlightActiveLine = function() {
  11467. return this.getOption("highlightActiveLine");
  11468. };
  11469. this.setHighlightGutterLine = function(shouldHighlight) {
  11470. this.setOption("highlightGutterLine", shouldHighlight);
  11471. };
  11472. this.getHighlightGutterLine = function() {
  11473. return this.getOption("highlightGutterLine");
  11474. };
  11475. this.setHighlightSelectedWord = function(shouldHighlight) {
  11476. this.setOption("highlightSelectedWord", shouldHighlight);
  11477. };
  11478. this.getHighlightSelectedWord = function() {
  11479. return this.$highlightSelectedWord;
  11480. };
  11481. this.setAnimatedScroll = function(shouldAnimate){
  11482. this.renderer.setAnimatedScroll(shouldAnimate);
  11483. };
  11484. this.getAnimatedScroll = function(){
  11485. return this.renderer.getAnimatedScroll();
  11486. };
  11487. this.setShowInvisibles = function(showInvisibles) {
  11488. this.renderer.setShowInvisibles(showInvisibles);
  11489. };
  11490. this.getShowInvisibles = function() {
  11491. return this.renderer.getShowInvisibles();
  11492. };
  11493. this.setDisplayIndentGuides = function(display) {
  11494. this.renderer.setDisplayIndentGuides(display);
  11495. };
  11496. this.getDisplayIndentGuides = function() {
  11497. return this.renderer.getDisplayIndentGuides();
  11498. };
  11499. this.setShowPrintMargin = function(showPrintMargin) {
  11500. this.renderer.setShowPrintMargin(showPrintMargin);
  11501. };
  11502. this.getShowPrintMargin = function() {
  11503. return this.renderer.getShowPrintMargin();
  11504. };
  11505. this.setPrintMarginColumn = function(showPrintMargin) {
  11506. this.renderer.setPrintMarginColumn(showPrintMargin);
  11507. };
  11508. this.getPrintMarginColumn = function() {
  11509. return this.renderer.getPrintMarginColumn();
  11510. };
  11511. this.setReadOnly = function(readOnly) {
  11512. this.setOption("readOnly", readOnly);
  11513. };
  11514. this.getReadOnly = function() {
  11515. return this.getOption("readOnly");
  11516. };
  11517. this.setBehavioursEnabled = function (enabled) {
  11518. this.setOption("behavioursEnabled", enabled);
  11519. };
  11520. this.getBehavioursEnabled = function () {
  11521. return this.getOption("behavioursEnabled");
  11522. };
  11523. this.setWrapBehavioursEnabled = function (enabled) {
  11524. this.setOption("wrapBehavioursEnabled", enabled);
  11525. };
  11526. this.getWrapBehavioursEnabled = function () {
  11527. return this.getOption("wrapBehavioursEnabled");
  11528. };
  11529. this.setShowFoldWidgets = function(show) {
  11530. this.setOption("showFoldWidgets", show);
  11531. };
  11532. this.getShowFoldWidgets = function() {
  11533. return this.getOption("showFoldWidgets");
  11534. };
  11535. this.setFadeFoldWidgets = function(fade) {
  11536. this.setOption("fadeFoldWidgets", fade);
  11537. };
  11538. this.getFadeFoldWidgets = function() {
  11539. return this.getOption("fadeFoldWidgets");
  11540. };
  11541. this.remove = function(dir) {
  11542. if (this.selection.isEmpty()){
  11543. if (dir == "left")
  11544. this.selection.selectLeft();
  11545. else
  11546. this.selection.selectRight();
  11547. }
  11548. var range = this.getSelectionRange();
  11549. if (this.getBehavioursEnabled()) {
  11550. var session = this.session;
  11551. var state = session.getState(range.start.row);
  11552. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11553. if (range.end.column === 0) {
  11554. var text = session.getTextRange(range);
  11555. if (text[text.length - 1] == "\n") {
  11556. var line = session.getLine(range.end.row);
  11557. if (/^\s+$/.test(line)) {
  11558. range.end.column = line.length;
  11559. }
  11560. }
  11561. }
  11562. if (new_range)
  11563. range = new_range;
  11564. }
  11565. this.session.remove(range);
  11566. this.clearSelection();
  11567. };
  11568. this.removeWordRight = function() {
  11569. if (this.selection.isEmpty())
  11570. this.selection.selectWordRight();
  11571. this.session.remove(this.getSelectionRange());
  11572. this.clearSelection();
  11573. };
  11574. this.removeWordLeft = function() {
  11575. if (this.selection.isEmpty())
  11576. this.selection.selectWordLeft();
  11577. this.session.remove(this.getSelectionRange());
  11578. this.clearSelection();
  11579. };
  11580. this.removeToLineStart = function() {
  11581. if (this.selection.isEmpty())
  11582. this.selection.selectLineStart();
  11583. this.session.remove(this.getSelectionRange());
  11584. this.clearSelection();
  11585. };
  11586. this.removeToLineEnd = function() {
  11587. if (this.selection.isEmpty())
  11588. this.selection.selectLineEnd();
  11589. var range = this.getSelectionRange();
  11590. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  11591. range.end.column = 0;
  11592. range.end.row++;
  11593. }
  11594. this.session.remove(range);
  11595. this.clearSelection();
  11596. };
  11597. this.splitLine = function() {
  11598. if (!this.selection.isEmpty()) {
  11599. this.session.remove(this.getSelectionRange());
  11600. this.clearSelection();
  11601. }
  11602. var cursor = this.getCursorPosition();
  11603. this.insert("\n");
  11604. this.moveCursorToPosition(cursor);
  11605. };
  11606. this.transposeLetters = function() {
  11607. if (!this.selection.isEmpty()) {
  11608. return;
  11609. }
  11610. var cursor = this.getCursorPosition();
  11611. var column = cursor.column;
  11612. if (column === 0)
  11613. return;
  11614. var line = this.session.getLine(cursor.row);
  11615. var swap, range;
  11616. if (column < line.length) {
  11617. swap = line.charAt(column) + line.charAt(column-1);
  11618. range = new Range(cursor.row, column-1, cursor.row, column+1);
  11619. }
  11620. else {
  11621. swap = line.charAt(column-1) + line.charAt(column-2);
  11622. range = new Range(cursor.row, column-2, cursor.row, column);
  11623. }
  11624. this.session.replace(range, swap);
  11625. };
  11626. this.toLowerCase = function() {
  11627. var originalRange = this.getSelectionRange();
  11628. if (this.selection.isEmpty()) {
  11629. this.selection.selectWord();
  11630. }
  11631. var range = this.getSelectionRange();
  11632. var text = this.session.getTextRange(range);
  11633. this.session.replace(range, text.toLowerCase());
  11634. this.selection.setSelectionRange(originalRange);
  11635. };
  11636. this.toUpperCase = function() {
  11637. var originalRange = this.getSelectionRange();
  11638. if (this.selection.isEmpty()) {
  11639. this.selection.selectWord();
  11640. }
  11641. var range = this.getSelectionRange();
  11642. var text = this.session.getTextRange(range);
  11643. this.session.replace(range, text.toUpperCase());
  11644. this.selection.setSelectionRange(originalRange);
  11645. };
  11646. this.indent = function() {
  11647. var session = this.session;
  11648. var range = this.getSelectionRange();
  11649. if (range.start.row < range.end.row) {
  11650. var rows = this.$getSelectedRows();
  11651. session.indentRows(rows.first, rows.last, "\t");
  11652. return;
  11653. } else if (range.start.column < range.end.column) {
  11654. var text = session.getTextRange(range);
  11655. if (!/^\s+$/.test(text)) {
  11656. var rows = this.$getSelectedRows();
  11657. session.indentRows(rows.first, rows.last, "\t");
  11658. return;
  11659. }
  11660. }
  11661. var line = session.getLine(range.start.row);
  11662. var position = range.start;
  11663. var size = session.getTabSize();
  11664. var column = session.documentToScreenColumn(position.row, position.column);
  11665. if (this.session.getUseSoftTabs()) {
  11666. var count = (size - column % size);
  11667. var indentString = lang.stringRepeat(" ", count);
  11668. } else {
  11669. var count = column % size;
  11670. while (line[range.start.column] == " " && count) {
  11671. range.start.column--;
  11672. count--;
  11673. }
  11674. this.selection.setSelectionRange(range);
  11675. indentString = "\t";
  11676. }
  11677. return this.insert(indentString);
  11678. };
  11679. this.blockIndent = function() {
  11680. var rows = this.$getSelectedRows();
  11681. this.session.indentRows(rows.first, rows.last, "\t");
  11682. };
  11683. this.blockOutdent = function() {
  11684. var selection = this.session.getSelection();
  11685. this.session.outdentRows(selection.getRange());
  11686. };
  11687. this.sortLines = function() {
  11688. var rows = this.$getSelectedRows();
  11689. var session = this.session;
  11690. var lines = [];
  11691. for (i = rows.first; i <= rows.last; i++)
  11692. lines.push(session.getLine(i));
  11693. lines.sort(function(a, b) {
  11694. if (a.toLowerCase() < b.toLowerCase()) return -1;
  11695. if (a.toLowerCase() > b.toLowerCase()) return 1;
  11696. return 0;
  11697. });
  11698. var deleteRange = new Range(0, 0, 0, 0);
  11699. for (var i = rows.first; i <= rows.last; i++) {
  11700. var line = session.getLine(i);
  11701. deleteRange.start.row = i;
  11702. deleteRange.end.row = i;
  11703. deleteRange.end.column = line.length;
  11704. session.replace(deleteRange, lines[i-rows.first]);
  11705. }
  11706. };
  11707. this.toggleCommentLines = function() {
  11708. var state = this.session.getState(this.getCursorPosition().row);
  11709. var rows = this.$getSelectedRows();
  11710. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  11711. };
  11712. this.toggleBlockComment = function() {
  11713. var cursor = this.getCursorPosition();
  11714. var state = this.session.getState(cursor.row);
  11715. var range = this.getSelectionRange();
  11716. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  11717. };
  11718. this.getNumberAt = function(row, column) {
  11719. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  11720. _numberRx.lastIndex = 0;
  11721. var s = this.session.getLine(row);
  11722. while (_numberRx.lastIndex < column) {
  11723. var m = _numberRx.exec(s);
  11724. if(m.index <= column && m.index+m[0].length >= column){
  11725. var number = {
  11726. value: m[0],
  11727. start: m.index,
  11728. end: m.index+m[0].length
  11729. };
  11730. return number;
  11731. }
  11732. }
  11733. return null;
  11734. };
  11735. this.modifyNumber = function(amount) {
  11736. var row = this.selection.getCursor().row;
  11737. var column = this.selection.getCursor().column;
  11738. var charRange = new Range(row, column-1, row, column);
  11739. var c = this.session.getTextRange(charRange);
  11740. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  11741. var nr = this.getNumberAt(row, column);
  11742. if (nr) {
  11743. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  11744. var decimals = nr.start + nr.value.length - fp;
  11745. var t = parseFloat(nr.value);
  11746. t *= Math.pow(10, decimals);
  11747. if(fp !== nr.end && column < fp){
  11748. amount *= Math.pow(10, nr.end - column - 1);
  11749. } else {
  11750. amount *= Math.pow(10, nr.end - column);
  11751. }
  11752. t += amount;
  11753. t /= Math.pow(10, decimals);
  11754. var nnr = t.toFixed(decimals);
  11755. var replaceRange = new Range(row, nr.start, row, nr.end);
  11756. this.session.replace(replaceRange, nnr);
  11757. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  11758. }
  11759. }
  11760. };
  11761. this.removeLines = function() {
  11762. var rows = this.$getSelectedRows();
  11763. var range;
  11764. if (rows.first === 0 || rows.last+1 < this.session.getLength())
  11765. range = new Range(rows.first, 0, rows.last+1, 0);
  11766. else
  11767. range = new Range(
  11768. rows.first-1, this.session.getLine(rows.first-1).length,
  11769. rows.last, this.session.getLine(rows.last).length
  11770. );
  11771. this.session.remove(range);
  11772. this.clearSelection();
  11773. };
  11774. this.duplicateSelection = function() {
  11775. var sel = this.selection;
  11776. var doc = this.session;
  11777. var range = sel.getRange();
  11778. var reverse = sel.isBackwards();
  11779. if (range.isEmpty()) {
  11780. var row = range.start.row;
  11781. doc.duplicateLines(row, row);
  11782. } else {
  11783. var point = reverse ? range.start : range.end;
  11784. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  11785. range.start = point;
  11786. range.end = endPoint;
  11787. sel.setSelectionRange(range, reverse);
  11788. }
  11789. };
  11790. this.moveLinesDown = function() {
  11791. this.$moveLines(function(firstRow, lastRow) {
  11792. return this.session.moveLinesDown(firstRow, lastRow);
  11793. });
  11794. };
  11795. this.moveLinesUp = function() {
  11796. this.$moveLines(function(firstRow, lastRow) {
  11797. return this.session.moveLinesUp(firstRow, lastRow);
  11798. });
  11799. };
  11800. this.moveText = function(range, toPosition, copy) {
  11801. return this.session.moveText(range, toPosition, copy);
  11802. };
  11803. this.copyLinesUp = function() {
  11804. this.$moveLines(function(firstRow, lastRow) {
  11805. this.session.duplicateLines(firstRow, lastRow);
  11806. return 0;
  11807. });
  11808. };
  11809. this.copyLinesDown = function() {
  11810. this.$moveLines(function(firstRow, lastRow) {
  11811. return this.session.duplicateLines(firstRow, lastRow);
  11812. });
  11813. };
  11814. this.$moveLines = function(mover) {
  11815. var selection = this.selection;
  11816. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  11817. var range = selection.toOrientedRange();
  11818. var rows = this.$getSelectedRows(range);
  11819. var linesMoved = mover.call(this, rows.first, rows.last);
  11820. range.moveBy(linesMoved, 0);
  11821. selection.fromOrientedRange(range);
  11822. } else {
  11823. var ranges = selection.rangeList.ranges;
  11824. selection.rangeList.detach(this.session);
  11825. for (var i = ranges.length; i--; ) {
  11826. var rangeIndex = i;
  11827. var rows = ranges[i].collapseRows();
  11828. var last = rows.end.row;
  11829. var first = rows.start.row;
  11830. while (i--) {
  11831. rows = ranges[i].collapseRows();
  11832. if (first - rows.end.row <= 1)
  11833. first = rows.end.row;
  11834. else
  11835. break;
  11836. }
  11837. i++;
  11838. var linesMoved = mover.call(this, first, last);
  11839. while (rangeIndex >= i) {
  11840. ranges[rangeIndex].moveBy(linesMoved, 0);
  11841. rangeIndex--;
  11842. }
  11843. }
  11844. selection.fromOrientedRange(selection.ranges[0]);
  11845. selection.rangeList.attach(this.session);
  11846. }
  11847. };
  11848. this.$getSelectedRows = function() {
  11849. var range = this.getSelectionRange().collapseRows();
  11850. return {
  11851. first: this.session.getRowFoldStart(range.start.row),
  11852. last: this.session.getRowFoldEnd(range.end.row)
  11853. };
  11854. };
  11855. this.onCompositionStart = function(text) {
  11856. this.renderer.showComposition(this.getCursorPosition());
  11857. };
  11858. this.onCompositionUpdate = function(text) {
  11859. this.renderer.setCompositionText(text);
  11860. };
  11861. this.onCompositionEnd = function() {
  11862. this.renderer.hideComposition();
  11863. };
  11864. this.getFirstVisibleRow = function() {
  11865. return this.renderer.getFirstVisibleRow();
  11866. };
  11867. this.getLastVisibleRow = function() {
  11868. return this.renderer.getLastVisibleRow();
  11869. };
  11870. this.isRowVisible = function(row) {
  11871. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  11872. };
  11873. this.isRowFullyVisible = function(row) {
  11874. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  11875. };
  11876. this.$getVisibleRowCount = function() {
  11877. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  11878. };
  11879. this.$moveByPage = function(dir, select) {
  11880. var renderer = this.renderer;
  11881. var config = this.renderer.layerConfig;
  11882. var rows = dir * Math.floor(config.height / config.lineHeight);
  11883. this.$blockScrolling++;
  11884. if (select === true) {
  11885. this.selection.$moveSelection(function(){
  11886. this.moveCursorBy(rows, 0);
  11887. });
  11888. } else if (select === false) {
  11889. this.selection.moveCursorBy(rows, 0);
  11890. this.selection.clearSelection();
  11891. }
  11892. this.$blockScrolling--;
  11893. var scrollTop = renderer.scrollTop;
  11894. renderer.scrollBy(0, rows * config.lineHeight);
  11895. if (select != null)
  11896. renderer.scrollCursorIntoView(null, 0.5);
  11897. renderer.animateScrolling(scrollTop);
  11898. };
  11899. this.selectPageDown = function() {
  11900. this.$moveByPage(1, true);
  11901. };
  11902. this.selectPageUp = function() {
  11903. this.$moveByPage(-1, true);
  11904. };
  11905. this.gotoPageDown = function() {
  11906. this.$moveByPage(1, false);
  11907. };
  11908. this.gotoPageUp = function() {
  11909. this.$moveByPage(-1, false);
  11910. };
  11911. this.scrollPageDown = function() {
  11912. this.$moveByPage(1);
  11913. };
  11914. this.scrollPageUp = function() {
  11915. this.$moveByPage(-1);
  11916. };
  11917. this.scrollToRow = function(row) {
  11918. this.renderer.scrollToRow(row);
  11919. };
  11920. this.scrollToLine = function(line, center, animate, callback) {
  11921. this.renderer.scrollToLine(line, center, animate, callback);
  11922. };
  11923. this.centerSelection = function() {
  11924. var range = this.getSelectionRange();
  11925. var pos = {
  11926. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  11927. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  11928. };
  11929. this.renderer.alignCursor(pos, 0.5);
  11930. };
  11931. this.getCursorPosition = function() {
  11932. return this.selection.getCursor();
  11933. };
  11934. this.getCursorPositionScreen = function() {
  11935. return this.session.documentToScreenPosition(this.getCursorPosition());
  11936. };
  11937. this.getSelectionRange = function() {
  11938. return this.selection.getRange();
  11939. };
  11940. this.selectAll = function() {
  11941. this.$blockScrolling += 1;
  11942. this.selection.selectAll();
  11943. this.$blockScrolling -= 1;
  11944. };
  11945. this.clearSelection = function() {
  11946. this.selection.clearSelection();
  11947. };
  11948. this.moveCursorTo = function(row, column) {
  11949. this.selection.moveCursorTo(row, column);
  11950. };
  11951. this.moveCursorToPosition = function(pos) {
  11952. this.selection.moveCursorToPosition(pos);
  11953. };
  11954. this.jumpToMatching = function(select) {
  11955. var cursor = this.getCursorPosition();
  11956. var range = this.session.getBracketRange(cursor);
  11957. if (!range) {
  11958. range = this.find({
  11959. needle: /[{}()\[\]]/g,
  11960. preventScroll:true,
  11961. start: {row: cursor.row, column: cursor.column - 1}
  11962. });
  11963. if (!range)
  11964. return;
  11965. var pos = range.start;
  11966. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  11967. range = this.session.getBracketRange(pos);
  11968. }
  11969. pos = range && range.cursor || pos;
  11970. if (pos) {
  11971. if (select) {
  11972. if (range && range.isEqual(this.getSelectionRange()))
  11973. this.clearSelection();
  11974. else
  11975. this.selection.selectTo(pos.row, pos.column);
  11976. } else {
  11977. this.selection.moveTo(pos.row, pos.column);
  11978. }
  11979. }
  11980. };
  11981. this.gotoLine = function(lineNumber, column, animate) {
  11982. this.selection.clearSelection();
  11983. this.session.unfold({row: lineNumber - 1, column: column || 0});
  11984. this.$blockScrolling += 1;
  11985. this.exitMultiSelectMode && this.exitMultiSelectMode();
  11986. this.moveCursorTo(lineNumber - 1, column || 0);
  11987. this.$blockScrolling -= 1;
  11988. if (!this.isRowFullyVisible(lineNumber - 1))
  11989. this.scrollToLine(lineNumber - 1, true, animate);
  11990. };
  11991. this.navigateTo = function(row, column) {
  11992. this.selection.moveTo(row, column);
  11993. };
  11994. this.navigateUp = function(times) {
  11995. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  11996. var selectionStart = this.selection.anchor.getPosition();
  11997. return this.moveCursorToPosition(selectionStart);
  11998. }
  11999. this.selection.clearSelection();
  12000. this.selection.moveCursorBy(-times || -1, 0);
  12001. };
  12002. this.navigateDown = function(times) {
  12003. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12004. var selectionEnd = this.selection.anchor.getPosition();
  12005. return this.moveCursorToPosition(selectionEnd);
  12006. }
  12007. this.selection.clearSelection();
  12008. this.selection.moveCursorBy(times || 1, 0);
  12009. };
  12010. this.navigateLeft = function(times) {
  12011. if (!this.selection.isEmpty()) {
  12012. var selectionStart = this.getSelectionRange().start;
  12013. this.moveCursorToPosition(selectionStart);
  12014. }
  12015. else {
  12016. times = times || 1;
  12017. while (times--) {
  12018. this.selection.moveCursorLeft();
  12019. }
  12020. }
  12021. this.clearSelection();
  12022. };
  12023. this.navigateRight = function(times) {
  12024. if (!this.selection.isEmpty()) {
  12025. var selectionEnd = this.getSelectionRange().end;
  12026. this.moveCursorToPosition(selectionEnd);
  12027. }
  12028. else {
  12029. times = times || 1;
  12030. while (times--) {
  12031. this.selection.moveCursorRight();
  12032. }
  12033. }
  12034. this.clearSelection();
  12035. };
  12036. this.navigateLineStart = function() {
  12037. this.selection.moveCursorLineStart();
  12038. this.clearSelection();
  12039. };
  12040. this.navigateLineEnd = function() {
  12041. this.selection.moveCursorLineEnd();
  12042. this.clearSelection();
  12043. };
  12044. this.navigateFileEnd = function() {
  12045. this.selection.moveCursorFileEnd();
  12046. this.clearSelection();
  12047. };
  12048. this.navigateFileStart = function() {
  12049. this.selection.moveCursorFileStart();
  12050. this.clearSelection();
  12051. };
  12052. this.navigateWordRight = function() {
  12053. this.selection.moveCursorWordRight();
  12054. this.clearSelection();
  12055. };
  12056. this.navigateWordLeft = function() {
  12057. this.selection.moveCursorWordLeft();
  12058. this.clearSelection();
  12059. };
  12060. this.replace = function(replacement, options) {
  12061. if (options)
  12062. this.$search.set(options);
  12063. var range = this.$search.find(this.session);
  12064. var replaced = 0;
  12065. if (!range)
  12066. return replaced;
  12067. if (this.$tryReplace(range, replacement)) {
  12068. replaced = 1;
  12069. }
  12070. if (range !== null) {
  12071. this.selection.setSelectionRange(range);
  12072. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12073. }
  12074. return replaced;
  12075. };
  12076. this.replaceAll = function(replacement, options) {
  12077. if (options) {
  12078. this.$search.set(options);
  12079. }
  12080. var ranges = this.$search.findAll(this.session);
  12081. var replaced = 0;
  12082. if (!ranges.length)
  12083. return replaced;
  12084. this.$blockScrolling += 1;
  12085. var selection = this.getSelectionRange();
  12086. this.selection.moveTo(0, 0);
  12087. for (var i = ranges.length - 1; i >= 0; --i) {
  12088. if(this.$tryReplace(ranges[i], replacement)) {
  12089. replaced++;
  12090. }
  12091. }
  12092. this.selection.setSelectionRange(selection);
  12093. this.$blockScrolling -= 1;
  12094. return replaced;
  12095. };
  12096. this.$tryReplace = function(range, replacement) {
  12097. var input = this.session.getTextRange(range);
  12098. replacement = this.$search.replace(input, replacement);
  12099. if (replacement !== null) {
  12100. range.end = this.session.replace(range, replacement);
  12101. return range;
  12102. } else {
  12103. return null;
  12104. }
  12105. };
  12106. this.getLastSearchOptions = function() {
  12107. return this.$search.getOptions();
  12108. };
  12109. this.find = function(needle, options, animate) {
  12110. if (!options)
  12111. options = {};
  12112. if (typeof needle == "string" || needle instanceof RegExp)
  12113. options.needle = needle;
  12114. else if (typeof needle == "object")
  12115. oop.mixin(options, needle);
  12116. var range = this.selection.getRange();
  12117. if (options.needle == null) {
  12118. needle = this.session.getTextRange(range)
  12119. || this.$search.$options.needle;
  12120. if (!needle) {
  12121. range = this.session.getWordRange(range.start.row, range.start.column);
  12122. needle = this.session.getTextRange(range);
  12123. }
  12124. this.$search.set({needle: needle});
  12125. }
  12126. this.$search.set(options);
  12127. if (!options.start)
  12128. this.$search.set({start: range});
  12129. var newRange = this.$search.find(this.session);
  12130. if (options.preventScroll)
  12131. return newRange;
  12132. if (newRange) {
  12133. this.revealRange(newRange, animate);
  12134. return newRange;
  12135. }
  12136. if (options.backwards)
  12137. range.start = range.end;
  12138. else
  12139. range.end = range.start;
  12140. this.selection.setRange(range);
  12141. };
  12142. this.findNext = function(options, animate) {
  12143. this.find({skipCurrent: true, backwards: false}, options, animate);
  12144. };
  12145. this.findPrevious = function(options, animate) {
  12146. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12147. };
  12148. this.revealRange = function(range, animate) {
  12149. this.$blockScrolling += 1;
  12150. this.session.unfold(range);
  12151. this.selection.setSelectionRange(range);
  12152. this.$blockScrolling -= 1;
  12153. var scrollTop = this.renderer.scrollTop;
  12154. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12155. if (animate !== false)
  12156. this.renderer.animateScrolling(scrollTop);
  12157. };
  12158. this.undo = function() {
  12159. this.$blockScrolling++;
  12160. this.session.getUndoManager().undo();
  12161. this.$blockScrolling--;
  12162. this.renderer.scrollCursorIntoView(null, 0.5);
  12163. };
  12164. this.redo = function() {
  12165. this.$blockScrolling++;
  12166. this.session.getUndoManager().redo();
  12167. this.$blockScrolling--;
  12168. this.renderer.scrollCursorIntoView(null, 0.5);
  12169. };
  12170. this.destroy = function() {
  12171. this.renderer.destroy();
  12172. this._signal("destroy", this);
  12173. };
  12174. this.setAutoScrollEditorIntoView = function(enable) {
  12175. if (!enable)
  12176. return;
  12177. var rect;
  12178. var self = this;
  12179. var shouldScroll = false;
  12180. if (!this.$scrollAnchor)
  12181. this.$scrollAnchor = document.createElement("div");
  12182. var scrollAnchor = this.$scrollAnchor;
  12183. scrollAnchor.style.cssText = "position:absolute";
  12184. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12185. var onChangeSelection = this.on("changeSelection", function() {
  12186. shouldScroll = true;
  12187. });
  12188. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12189. if (shouldScroll)
  12190. rect = self.renderer.container.getBoundingClientRect();
  12191. });
  12192. var onAfterRender = this.renderer.on("afterRender", function() {
  12193. if (shouldScroll && rect && self.isFocused()) {
  12194. var renderer = self.renderer;
  12195. var pos = renderer.$cursorLayer.$pixelPos;
  12196. var config = renderer.layerConfig;
  12197. var top = pos.top - config.offset;
  12198. if (pos.top >= 0 && top + rect.top < 0) {
  12199. shouldScroll = true;
  12200. } else if (pos.top < config.height &&
  12201. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12202. shouldScroll = false;
  12203. } else {
  12204. shouldScroll = null;
  12205. }
  12206. if (shouldScroll != null) {
  12207. scrollAnchor.style.top = top + "px";
  12208. scrollAnchor.style.left = pos.left + "px";
  12209. scrollAnchor.style.height = config.lineHeight + "px";
  12210. scrollAnchor.scrollIntoView(shouldScroll);
  12211. }
  12212. shouldScroll = rect = null;
  12213. }
  12214. });
  12215. this.setAutoScrollEditorIntoView = function(enable) {
  12216. if (enable)
  12217. return;
  12218. delete this.setAutoScrollEditorIntoView;
  12219. this.removeEventListener("changeSelection", onChangeSelection);
  12220. this.renderer.removeEventListener("afterRender", onAfterRender);
  12221. this.renderer.removeEventListener("beforeRender", onBeforeRender);
  12222. };
  12223. };
  12224. this.$resetCursorStyle = function() {
  12225. var style = this.$cursorStyle || "ace";
  12226. var cursorLayer = this.renderer.$cursorLayer;
  12227. if (!cursorLayer)
  12228. return;
  12229. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12230. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12231. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12232. };
  12233. }).call(Editor.prototype);
  12234. config.defineOptions(Editor.prototype, "editor", {
  12235. selectionStyle: {
  12236. set: function(style) {
  12237. this.onSelectionChange();
  12238. this._signal("changeSelectionStyle", {data: style});
  12239. },
  12240. initialValue: "line"
  12241. },
  12242. highlightActiveLine: {
  12243. set: function() {this.$updateHighlightActiveLine();},
  12244. initialValue: true
  12245. },
  12246. highlightSelectedWord: {
  12247. set: function(shouldHighlight) {this.$onSelectionChange();},
  12248. initialValue: true
  12249. },
  12250. readOnly: {
  12251. set: function(readOnly) {
  12252. this.$resetCursorStyle();
  12253. },
  12254. initialValue: false
  12255. },
  12256. cursorStyle: {
  12257. set: function(val) { this.$resetCursorStyle(); },
  12258. values: ["ace", "slim", "smooth", "wide"],
  12259. initialValue: "ace"
  12260. },
  12261. mergeUndoDeltas: {
  12262. values: [false, true, "always"],
  12263. initialValue: true
  12264. },
  12265. behavioursEnabled: {initialValue: true},
  12266. wrapBehavioursEnabled: {initialValue: true},
  12267. autoScrollEditorIntoView: {
  12268. set: function(val) {this.setAutoScrollEditorIntoView(val)}
  12269. },
  12270. hScrollBarAlwaysVisible: "renderer",
  12271. vScrollBarAlwaysVisible: "renderer",
  12272. highlightGutterLine: "renderer",
  12273. animatedScroll: "renderer",
  12274. showInvisibles: "renderer",
  12275. showPrintMargin: "renderer",
  12276. printMarginColumn: "renderer",
  12277. printMargin: "renderer",
  12278. fadeFoldWidgets: "renderer",
  12279. showFoldWidgets: "renderer",
  12280. showLineNumbers: "renderer",
  12281. showGutter: "renderer",
  12282. displayIndentGuides: "renderer",
  12283. fontSize: "renderer",
  12284. fontFamily: "renderer",
  12285. maxLines: "renderer",
  12286. minLines: "renderer",
  12287. scrollPastEnd: "renderer",
  12288. fixedWidthGutter: "renderer",
  12289. theme: "renderer",
  12290. scrollSpeed: "$mouseHandler",
  12291. dragDelay: "$mouseHandler",
  12292. dragEnabled: "$mouseHandler",
  12293. focusTimout: "$mouseHandler",
  12294. tooltipFollowsMouse: "$mouseHandler",
  12295. firstLineNumber: "session",
  12296. overwrite: "session",
  12297. newLineMode: "session",
  12298. useWorker: "session",
  12299. useSoftTabs: "session",
  12300. tabSize: "session",
  12301. wrap: "session",
  12302. foldStyle: "session",
  12303. mode: "session"
  12304. });
  12305. exports.Editor = Editor;
  12306. });
  12307. ace.define('ace/placeholder', ['require', 'exports', 'module' , 'ace/range', 'ace/lib/event_emitter', 'ace/lib/oop'], function(require, exports, module) {
  12308. var Range = require("./range").Range;
  12309. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  12310. var oop = require("./lib/oop");
  12311. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  12312. var _self = this;
  12313. this.length = length;
  12314. this.session = session;
  12315. this.doc = session.getDocument();
  12316. this.mainClass = mainClass;
  12317. this.othersClass = othersClass;
  12318. this.$onUpdate = this.onUpdate.bind(this);
  12319. this.doc.on("change", this.$onUpdate);
  12320. this.$others = others;
  12321. this.$onCursorChange = function() {
  12322. setTimeout(function() {
  12323. _self.onCursorChange();
  12324. });
  12325. };
  12326. this.$pos = pos;
  12327. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  12328. this.$undoStackDepth = undoStack.length;
  12329. this.setup();
  12330. session.selection.on("changeCursor", this.$onCursorChange);
  12331. };
  12332. (function() {
  12333. oop.implement(this, EventEmitter);
  12334. this.setup = function() {
  12335. var _self = this;
  12336. var doc = this.doc;
  12337. var session = this.session;
  12338. var pos = this.$pos;
  12339. this.pos = doc.createAnchor(pos.row, pos.column);
  12340. this.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  12341. this.pos.on("change", function(event) {
  12342. session.removeMarker(_self.markerId);
  12343. _self.markerId = session.addMarker(new Range(event.value.row, event.value.column, event.value.row, event.value.column+_self.length), _self.mainClass, null, false);
  12344. });
  12345. this.others = [];
  12346. this.$others.forEach(function(other) {
  12347. var anchor = doc.createAnchor(other.row, other.column);
  12348. _self.others.push(anchor);
  12349. });
  12350. session.setUndoSelect(false);
  12351. };
  12352. this.showOtherMarkers = function() {
  12353. if(this.othersActive) return;
  12354. var session = this.session;
  12355. var _self = this;
  12356. this.othersActive = true;
  12357. this.others.forEach(function(anchor) {
  12358. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  12359. anchor.on("change", function(event) {
  12360. session.removeMarker(anchor.markerId);
  12361. anchor.markerId = session.addMarker(new Range(event.value.row, event.value.column, event.value.row, event.value.column+_self.length), _self.othersClass, null, false);
  12362. });
  12363. });
  12364. };
  12365. this.hideOtherMarkers = function() {
  12366. if(!this.othersActive) return;
  12367. this.othersActive = false;
  12368. for (var i = 0; i < this.others.length; i++) {
  12369. this.session.removeMarker(this.others[i].markerId);
  12370. }
  12371. };
  12372. this.onUpdate = function(event) {
  12373. var delta = event.data;
  12374. var range = delta.range;
  12375. if(range.start.row !== range.end.row) return;
  12376. if(range.start.row !== this.pos.row) return;
  12377. if (this.$updating) return;
  12378. this.$updating = true;
  12379. var lengthDiff = delta.action === "insertText" ? range.end.column - range.start.column : range.start.column - range.end.column;
  12380. if(range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1) {
  12381. var distanceFromStart = range.start.column - this.pos.column;
  12382. this.length += lengthDiff;
  12383. if(!this.session.$fromUndo) {
  12384. if(delta.action === "insertText") {
  12385. for (var i = this.others.length - 1; i >= 0; i--) {
  12386. var otherPos = this.others[i];
  12387. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  12388. if(otherPos.row === range.start.row && range.start.column < otherPos.column)
  12389. newPos.column += lengthDiff;
  12390. this.doc.insert(newPos, delta.text);
  12391. }
  12392. } else if(delta.action === "removeText") {
  12393. for (var i = this.others.length - 1; i >= 0; i--) {
  12394. var otherPos = this.others[i];
  12395. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  12396. if(otherPos.row === range.start.row && range.start.column < otherPos.column)
  12397. newPos.column += lengthDiff;
  12398. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  12399. }
  12400. }
  12401. if(range.start.column === this.pos.column && delta.action === "insertText") {
  12402. setTimeout(function() {
  12403. this.pos.setPosition(this.pos.row, this.pos.column - lengthDiff);
  12404. for (var i = 0; i < this.others.length; i++) {
  12405. var other = this.others[i];
  12406. var newPos = {row: other.row, column: other.column - lengthDiff};
  12407. if(other.row === range.start.row && range.start.column < other.column)
  12408. newPos.column += lengthDiff;
  12409. other.setPosition(newPos.row, newPos.column);
  12410. }
  12411. }.bind(this), 0);
  12412. }
  12413. else if(range.start.column === this.pos.column && delta.action === "removeText") {
  12414. setTimeout(function() {
  12415. for (var i = 0; i < this.others.length; i++) {
  12416. var other = this.others[i];
  12417. if(other.row === range.start.row && range.start.column < other.column) {
  12418. other.setPosition(other.row, other.column - lengthDiff);
  12419. }
  12420. }
  12421. }.bind(this), 0);
  12422. }
  12423. }
  12424. this.pos._emit("change", {value: this.pos});
  12425. for (var i = 0; i < this.others.length; i++) {
  12426. this.others[i]._emit("change", {value: this.others[i]});
  12427. }
  12428. }
  12429. this.$updating = false;
  12430. };
  12431. this.onCursorChange = function(event) {
  12432. if (this.$updating) return;
  12433. var pos = this.session.selection.getCursor();
  12434. if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  12435. this.showOtherMarkers();
  12436. this._emit("cursorEnter", event);
  12437. } else {
  12438. this.hideOtherMarkers();
  12439. this._emit("cursorLeave", event);
  12440. }
  12441. };
  12442. this.detach = function() {
  12443. this.session.removeMarker(this.markerId);
  12444. this.hideOtherMarkers();
  12445. this.doc.removeEventListener("change", this.$onUpdate);
  12446. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  12447. this.pos.detach();
  12448. for (var i = 0; i < this.others.length; i++) {
  12449. this.others[i].detach();
  12450. }
  12451. this.session.setUndoSelect(true);
  12452. };
  12453. this.cancel = function() {
  12454. if(this.$undoStackDepth === -1)
  12455. throw Error("Canceling placeholders only supported with undo manager attached to session.");
  12456. var undoManager = this.session.getUndoManager();
  12457. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  12458. for (var i = 0; i < undosRequired; i++) {
  12459. undoManager.undo(true);
  12460. }
  12461. };
  12462. }).call(PlaceHolder.prototype);
  12463. exports.PlaceHolder = PlaceHolder;
  12464. });
  12465. ace.define('ace/lib/useragent', ['require', 'exports', 'module' ], function(require, exports, module) {
  12466. exports.OS = {
  12467. LINUX: "LINUX",
  12468. MAC: "MAC",
  12469. WINDOWS: "WINDOWS"
  12470. };
  12471. exports.getOS = function() {
  12472. if (exports.isMac) {
  12473. return exports.OS.MAC;
  12474. } else if (exports.isLinux) {
  12475. return exports.OS.LINUX;
  12476. } else {
  12477. re