Log updates
[beagleboard.org.git] / static / ace.js
blob79f7bada4f33c328197a69b636391cca4306f1ab
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 ***** */
31 /**
32  * Define a module along with a payload
33  * @param module a name for the payload
34  * @param payload a function to call with (require, exports, module) params
35  */
37 (function() {
39 var ACE_NAMESPACE = "";
41 var global = (function() {
42     return this;
43 })();
45 // take care of the case when requirejs is used and we just need to patch it a little bit
46 if (!ACE_NAMESPACE && typeof requirejs !== "undefined") {
48     var define = global.define;
49     global.define = function(id, deps, callback) {
50         if (typeof callback !== "function")
51             return define.apply(this, arguments);
53         return define(id, deps, function(require, exports, module) {
54             if (deps[2] == "module")
55                 module.packaged = true;
56             return callback.apply(this, arguments);
57         });
58     };
59     global.define.packaged = true;
61     return;
65 var _define = function(module, deps, payload) {
66     if (typeof module !== 'string') {
67         if (_define.original)
68             _define.original.apply(window, arguments);
69         else {
70             console.error('dropping module because define wasn\'t a string.');
71             console.trace();
72         }
73         return;
74     }
76     if (arguments.length == 2)
77         payload = deps;
79     if (!_define.modules)
80         _define.modules = {};
82     _define.modules[module] = payload;
84 var _require = function(parentId, module, callback) {
85     if (Object.prototype.toString.call(module) === "[object Array]") {
86         var params = [];
87         for (var i = 0, l = module.length; i < l; ++i) {
88             var dep = lookup(parentId, module[i]);
89             if (!dep && _require.original)
90                 return _require.original.apply(window, arguments);
91             params.push(dep);
92         }
93         if (callback) {
94             callback.apply(null, params);
95         }
96     }
97     else if (typeof module === 'string') {
98         var payload = lookup(parentId, module);
99         if (!payload && _require.original)
100             return _require.original.apply(window, arguments);
102         if (callback) {
103             callback();
104         }
106         return payload;
107     }
108     else {
109         if (_require.original)
110             return _require.original.apply(window, arguments);
111     }
114 var normalizeModule = function(parentId, moduleName) {
115     // normalize plugin requires
116     if (moduleName.indexOf("!") !== -1) {
117         var chunks = moduleName.split("!");
118         return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
119     }
120     // normalize relative requires
121     if (moduleName.charAt(0) == ".") {
122         var base = parentId.split("/").slice(0, -1).join("/");
123         moduleName = base + "/" + moduleName;
125         while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
126             var previous = moduleName;
127             moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
128         }
129     }
131     return moduleName;
133 var lookup = function(parentId, moduleName) {
135     moduleName = normalizeModule(parentId, moduleName);
137     var module = _define.modules[moduleName];
138     if (!module) {
139         return null;
140     }
142     if (typeof module === 'function') {
143         var exports = {};
144         var mod = {
145             id: moduleName,
146             uri: '',
147             exports: exports,
148             packaged: true
149         };
151         var req = function(module, callback) {
152             return _require(moduleName, module, callback);
153         };
155         var returnValue = module(req, exports, mod);
156         exports = returnValue || mod.exports;
158         // cache the resulting module object for next time
159         _define.modules[moduleName] = exports;
160         return exports;
161     }
163     return module;
166 function exportAce(ns) {
167     var require = function(module, callback) {
168         return _require("", module, callback);
169     };    
171     var root = global;
172     if (ns) {
173         if (!global[ns])
174             global[ns] = {};
175         root = global[ns];
176     }
178     if (!root.define || !root.define.packaged) {
179         _define.original = root.define;
180         root.define = _define;
181         root.define.packaged = true;
182     }
184     if (!root.require || !root.require.packaged) {
185         _require.original = root.require;
186         root.require = require;
187         root.require.packaged = true;
188     }
191 exportAce(ACE_NAMESPACE);
193 })();
196  * class Ace
198  * The main class required to set up an Ace instance in the browser.
201  **/
203 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/multi_select', 'ace/worker/worker_client', 'ace/keyboard/hash_handler', 'ace/keyboard/state_handler', 'ace/placeholder', 'ace/config', 'ace/theme/textmate'], function(require, exports, module) {
206 require("./lib/fixoldbrowsers");
208 var Dom = require("./lib/dom");
209 var Event = require("./lib/event");
211 var Editor = require("./editor").Editor;
212 var EditSession = require("./edit_session").EditSession;
213 var UndoManager = require("./undomanager").UndoManager;
214 var Renderer = require("./virtual_renderer").VirtualRenderer;
215 var MultiSelect = require("./multi_select").MultiSelect;
217 // The following require()s are for inclusion in the built ace file
218 require("./worker/worker_client");
219 require("./keyboard/hash_handler");
220 require("./keyboard/state_handler");
221 require("./placeholder");
222 exports.config = require("./config");
223 exports.edit = function(el) {
224     if (typeof(el) == "string") {
225         var _id = el;
226         if (!(el = document.getElementById(el))) {
227           console.log("can't match div #" + _id);
228         }
229     }
231     if (el.env && el.env.editor instanceof Editor)
232         return el.env.editor;
234     var doc = new EditSession(Dom.getInnerText(el));
235     doc.setUndoManager(new UndoManager());
236     el.innerHTML = '';
238     var editor = new Editor(new Renderer(el, require("./theme/textmate")));
239     new MultiSelect(editor);
240     editor.setSession(doc);
242     var env = {};
243     env.document = doc;
244     env.editor = editor;
245     editor.resize();
246     Event.addListener(window, "resize", function() {
247         editor.resize();
248     });
249     el.env = env;
250     // Store env on editor such that it can be accessed later on from
251     // the returned object.
252     editor.env = env;
253     return editor;
257 // vim:set ts=4 sts=4 sw=4 st:
258 // -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
259 // -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
260 // -- dantman Daniel Friesen Copyright(C) 2010 XXX No License Specified
261 // -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
262 // -- Irakli Gozalishvili Copyright (C) 2010 MIT License
265     Copyright (c) 2009, 280 North Inc. http://280north.com/
266     MIT License. http://github.com/280north/narwhal/blob/master/README.md
269 define('ace/lib/fixoldbrowsers', ['require', 'exports', 'module' , 'ace/lib/regexp', 'ace/lib/es5-shim'], function(require, exports, module) {
272 require("./regexp");
273 require("./es5-shim");
277 define('ace/lib/regexp', ['require', 'exports', 'module' ], function(require, exports, module) {
280     //---------------------------------
281     //  Private variables
282     //---------------------------------
284     var real = {
285             exec: RegExp.prototype.exec,
286             test: RegExp.prototype.test,
287             match: String.prototype.match,
288             replace: String.prototype.replace,
289             split: String.prototype.split
290         },
291         compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
292         compliantLastIndexIncrement = function () {
293             var x = /^/g;
294             real.test.call(x, "");
295             return !x.lastIndex;
296         }();
298     if (compliantLastIndexIncrement && compliantExecNpcg)
299         return;
301     //---------------------------------
302     //  Overriden native methods
303     //---------------------------------
305     // Adds named capture support (with backreferences returned as `result.name`), and fixes two
306     // cross-browser issues per ES3:
307     // - Captured values for nonparticipating capturing groups should be returned as `undefined`,
308     //   rather than the empty string.
309     // - `lastIndex` should not be incremented after zero-length matches.
310     RegExp.prototype.exec = function (str) {
311         var match = real.exec.apply(this, arguments),
312             name, r2;
313         if ( typeof(str) == 'string' && match) {
314             // Fix browsers whose `exec` methods don't consistently return `undefined` for
315             // nonparticipating capturing groups
316             if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
317                 r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
318                 // Using `str.slice(match.index)` rather than `match[0]` in case lookahead allowed
319                 // matching due to characters outside the match
320                 real.replace.call(str.slice(match.index), r2, function () {
321                     for (var i = 1; i < arguments.length - 2; i++) {
322                         if (arguments[i] === undefined)
323                             match[i] = undefined;
324                     }
325                 });
326             }
327             // Attach named capture properties
328             if (this._xregexp && this._xregexp.captureNames) {
329                 for (var i = 1; i < match.length; i++) {
330                     name = this._xregexp.captureNames[i - 1];
331                     if (name)
332                        match[name] = match[i];
333                 }
334             }
335             // Fix browsers that increment `lastIndex` after zero-length matches
336             if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
337                 this.lastIndex--;
338         }
339         return match;
340     };
342     // Don't override `test` if it won't change anything
343     if (!compliantLastIndexIncrement) {
344         // Fix browser bug in native method
345         RegExp.prototype.test = function (str) {
346             // Use the native `exec` to skip some processing overhead, even though the overriden
347             // `exec` would take care of the `lastIndex` fix
348             var match = real.exec.call(this, str);
349             // Fix browsers that increment `lastIndex` after zero-length matches
350             if (match && this.global && !match[0].length && (this.lastIndex > match.index))
351                 this.lastIndex--;
352             return !!match;
353         };
354     }
356     //---------------------------------
357     //  Private helper functions
358     //---------------------------------
360     function getNativeFlags (regex) {
361         return (regex.global     ? "g" : "") +
362                (regex.ignoreCase ? "i" : "") +
363                (regex.multiline  ? "m" : "") +
364                (regex.extended   ? "x" : "") + // Proposed for ES4; included in AS3
365                (regex.sticky     ? "y" : "");
366     }
368     function indexOf (array, item, from) {
369         if (Array.prototype.indexOf) // Use the native array method if available
370             return array.indexOf(item, from);
371         for (var i = from || 0; i < array.length; i++) {
372             if (array[i] === item)
373                 return i;
374         }
375         return -1;
376     }
379 // vim: ts=4 sts=4 sw=4 expandtab
380 // -- kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License
381 // -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
382 // -- dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA
383 // -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
384 // -- Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License
385 // -- kitcambridge Kit Cambridge Copyright (C) 2011 MIT License
386 // -- kossnocorp Sasha Koss XXX TODO License or CLA
387 // -- bryanforbes Bryan Forbes XXX TODO License or CLA
388 // -- killdream Quildreen Motta Copyright (C) 2011 MIT Licence
389 // -- michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD License
390 // -- sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License
391 // -- bbqsrc Brendan Molloy (C) 2011 Creative Commons Zero (public domain)
392 // -- iwyg XXX TODO License or CLA
393 // -- DomenicDenicola Domenic Denicola Copyright (C) 2011 MIT License
394 // -- xavierm02 Montillet Xavier XXX TODO License or CLA
395 // -- Raynos Raynos XXX TODO License or CLA
396 // -- samsonjs Sami Samhuri Copyright (C) 2010 MIT License
397 // -- rwldrn Rick Waldron Copyright (C) 2011 MIT License
398 // -- lexer Alexey Zakharov XXX TODO License or CLA
401     Copyright (c) 2009, 280 North Inc. http://280north.com/
402     MIT License. http://github.com/280north/narwhal/blob/master/README.md
405 define('ace/lib/es5-shim', ['require', 'exports', 'module' ], function(require, exports, module) {
408  * Brings an environment as close to ECMAScript 5 compliance
409  * as is possible with the facilities of erstwhile engines.
411  * Annotated ES5: http://es5.github.com/ (specific links below)
412  * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
414  * @module
415  */
417 /*whatsupdoc*/
420 // Function
421 // ========
424 // ES-5 15.3.4.5
425 // http://es5.github.com/#x15.3.4.5
427 if (!Function.prototype.bind) {
428     Function.prototype.bind = function bind(that) { // .length is 1
429         // 1. Let Target be the this value.
430         var target = this;
431         // 2. If IsCallable(Target) is false, throw a TypeError exception.
432         if (typeof target != "function")
433             throw new TypeError(); // TODO message
434         // 3. Let A be a new (possibly empty) internal list of all of the
435         //   argument values provided after thisArg (arg1, arg2 etc), in order.
436         // XXX slicedArgs will stand in for "A" if used
437         var args = slice.call(arguments, 1); // for normal call
438         // 4. Let F be a new native ECMAScript object.
439         // 11. Set the [[Prototype]] internal property of F to the standard
440         //   built-in Function prototype object as specified in 15.3.3.1.
441         // 12. Set the [[Call]] internal property of F as described in
442         //   15.3.4.5.1.
443         // 13. Set the [[Construct]] internal property of F as described in
444         //   15.3.4.5.2.
445         // 14. Set the [[HasInstance]] internal property of F as described in
446         //   15.3.4.5.3.
447         var bound = function () {
449             if (this instanceof bound) {
450                 // 15.3.4.5.2 [[Construct]]
451                 // When the [[Construct]] internal method of a function object,
452                 // F that was created using the bind function is called with a
453                 // list of arguments ExtraArgs, the following steps are taken:
454                 // 1. Let target be the value of F's [[TargetFunction]]
455                 //   internal property.
456                 // 2. If target has no [[Construct]] internal method, a
457                 //   TypeError exception is thrown.
458                 // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
459                 //   property.
460                 // 4. Let args be a new list containing the same values as the
461                 //   list boundArgs in the same order followed by the same
462                 //   values as the list ExtraArgs in the same order.
463                 // 5. Return the result of calling the [[Construct]] internal 
464                 //   method of target providing args as the arguments.
466                 var F = function(){};
467                 F.prototype = target.prototype;
468                 var self = new F;
470                 var result = target.apply(
471                     self,
472                     args.concat(slice.call(arguments))
473                 );
474                 if (result !== null && Object(result) === result)
475                     return result;
476                 return self;
478             } else {
479                 // 15.3.4.5.1 [[Call]]
480                 // When the [[Call]] internal method of a function object, F,
481                 // which was created using the bind function is called with a
482                 // this value and a list of arguments ExtraArgs, the following
483                 // steps are taken:
484                 // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
485                 //   property.
486                 // 2. Let boundThis be the value of F's [[BoundThis]] internal
487                 //   property.
488                 // 3. Let target be the value of F's [[TargetFunction]] internal
489                 //   property.
490                 // 4. Let args be a new list containing the same values as the 
491                 //   list boundArgs in the same order followed by the same 
492                 //   values as the list ExtraArgs in the same order.
493                 // 5. Return the result of calling the [[Call]] internal method 
494                 //   of target providing boundThis as the this value and 
495                 //   providing args as the arguments.
497                 // equiv: target.call(this, ...boundArgs, ...args)
498                 return target.apply(
499                     that,
500                     args.concat(slice.call(arguments))
501                 );
503             }
505         };
506         // XXX bound.length is never writable, so don't even try
507         //
508         // 15. If the [[Class]] internal property of Target is "Function", then
509         //     a. Let L be the length property of Target minus the length of A.
510         //     b. Set the length own property of F to either 0 or L, whichever is 
511         //       larger.
512         // 16. Else set the length own property of F to 0.
513         // 17. Set the attributes of the length own property of F to the values
514         //   specified in 15.3.5.1.
516         // TODO
517         // 18. Set the [[Extensible]] internal property of F to true.
518         
519         // TODO
520         // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
521         // 20. Call the [[DefineOwnProperty]] internal method of F with 
522         //   arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
523         //   thrower, [[Enumerable]]: false, [[Configurable]]: false}, and 
524         //   false.
525         // 21. Call the [[DefineOwnProperty]] internal method of F with 
526         //   arguments "arguments", PropertyDescriptor {[[Get]]: thrower, 
527         //   [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
528         //   and false.
530         // TODO
531         // NOTE Function objects created using Function.prototype.bind do not 
532         // have a prototype property or the [[Code]], [[FormalParameters]], and
533         // [[Scope]] internal properties.
534         // XXX can't delete prototype in pure-js.
536         // 22. Return F.
537         return bound;
538     };
541 // Shortcut to an often accessed properties, in order to avoid multiple
542 // dereference that costs universally.
543 // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
544 // us it in defining shortcuts.
545 var call = Function.prototype.call;
546 var prototypeOfArray = Array.prototype;
547 var prototypeOfObject = Object.prototype;
548 var slice = prototypeOfArray.slice;
549 var toString = call.bind(prototypeOfObject.toString);
550 var owns = call.bind(prototypeOfObject.hasOwnProperty);
552 // If JS engine supports accessors creating shortcuts.
553 var defineGetter;
554 var defineSetter;
555 var lookupGetter;
556 var lookupSetter;
557 var supportsAccessors;
558 if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
559     defineGetter = call.bind(prototypeOfObject.__defineGetter__);
560     defineSetter = call.bind(prototypeOfObject.__defineSetter__);
561     lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
562     lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
566 // Array
567 // =====
570 // ES5 15.4.3.2
571 // http://es5.github.com/#x15.4.3.2
572 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
573 if (!Array.isArray) {
574     Array.isArray = function isArray(obj) {
575         return toString(obj) == "[object Array]";
576     };
579 // The IsCallable() check in the Array functions
580 // has been replaced with a strict check on the
581 // internal class of the object to trap cases where
582 // the provided function was actually a regular
583 // expression literal, which in V8 and
584 // JavaScriptCore is a typeof "function".  Only in
585 // V8 are regular expression literals permitted as
586 // reduce parameters, so it is desirable in the
587 // general case for the shim to match the more
588 // strict and common behavior of rejecting regular
589 // expressions.
591 // ES5 15.4.4.18
592 // http://es5.github.com/#x15.4.4.18
593 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
594 if (!Array.prototype.forEach) {
595     Array.prototype.forEach = function forEach(fun /*, thisp*/) {
596         var self = toObject(this),
597             thisp = arguments[1],
598             i = 0,
599             length = self.length >>> 0;
601         // If no callback function or if callback is not a callable function
602         if (toString(fun) != "[object Function]") {
603             throw new TypeError(); // TODO message
604         }
606         while (i < length) {
607             if (i in self) {
608                 // Invoke the callback function with call, passing arguments:
609                 // context, property value, property key, thisArg object context
610                 fun.call(thisp, self[i], i, self);
611             }
612             i++;
613         }
614     };
617 // ES5 15.4.4.19
618 // http://es5.github.com/#x15.4.4.19
619 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
620 if (!Array.prototype.map) {
621     Array.prototype.map = function map(fun /*, thisp*/) {
622         var self = toObject(this),
623             length = self.length >>> 0,
624             result = Array(length),
625             thisp = arguments[1];
627         // If no callback function or if callback is not a callable function
628         if (toString(fun) != "[object Function]") {
629             throw new TypeError(); // TODO message
630         }
632         for (var i = 0; i < length; i++) {
633             if (i in self)
634                 result[i] = fun.call(thisp, self[i], i, self);
635         }
636         return result;
637     };
640 // ES5 15.4.4.20
641 // http://es5.github.com/#x15.4.4.20
642 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
643 if (!Array.prototype.filter) {
644     Array.prototype.filter = function filter(fun /*, thisp */) {
645         var self = toObject(this),
646             length = self.length >>> 0,
647             result = [],
648             thisp = arguments[1];
650         // If no callback function or if callback is not a callable function
651         if (toString(fun) != "[object Function]") {
652             throw new TypeError(); // TODO message
653         }
655         for (var i = 0; i < length; i++) {
656             if (i in self && fun.call(thisp, self[i], i, self))
657                 result.push(self[i]);
658         }
659         return result;
660     };
663 // ES5 15.4.4.16
664 // http://es5.github.com/#x15.4.4.16
665 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
666 if (!Array.prototype.every) {
667     Array.prototype.every = function every(fun /*, thisp */) {
668         var self = toObject(this),
669             length = self.length >>> 0,
670             thisp = arguments[1];
672         // If no callback function or if callback is not a callable function
673         if (toString(fun) != "[object Function]") {
674             throw new TypeError(); // TODO message
675         }
677         for (var i = 0; i < length; i++) {
678             if (i in self && !fun.call(thisp, self[i], i, self))
679                 return false;
680         }
681         return true;
682     };
685 // ES5 15.4.4.17
686 // http://es5.github.com/#x15.4.4.17
687 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
688 if (!Array.prototype.some) {
689     Array.prototype.some = function some(fun /*, thisp */) {
690         var self = toObject(this),
691             length = self.length >>> 0,
692             thisp = arguments[1];
694         // If no callback function or if callback is not a callable function
695         if (toString(fun) != "[object Function]") {
696             throw new TypeError(); // TODO message
697         }
699         for (var i = 0; i < length; i++) {
700             if (i in self && fun.call(thisp, self[i], i, self))
701                 return true;
702         }
703         return false;
704     };
707 // ES5 15.4.4.21
708 // http://es5.github.com/#x15.4.4.21
709 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
710 if (!Array.prototype.reduce) {
711     Array.prototype.reduce = function reduce(fun /*, initial*/) {
712         var self = toObject(this),
713             length = self.length >>> 0;
715         // If no callback function or if callback is not a callable function
716         if (toString(fun) != "[object Function]") {
717             throw new TypeError(); // TODO message
718         }
720         // no value to return if no initial value and an empty array
721         if (!length && arguments.length == 1)
722             throw new TypeError(); // TODO message
724         var i = 0;
725         var result;
726         if (arguments.length >= 2) {
727             result = arguments[1];
728         } else {
729             do {
730                 if (i in self) {
731                     result = self[i++];
732                     break;
733                 }
735                 // if array contains no values, no initial value to return
736                 if (++i >= length)
737                     throw new TypeError(); // TODO message
738             } while (true);
739         }
741         for (; i < length; i++) {
742             if (i in self)
743                 result = fun.call(void 0, result, self[i], i, self);
744         }
746         return result;
747     };
750 // ES5 15.4.4.22
751 // http://es5.github.com/#x15.4.4.22
752 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
753 if (!Array.prototype.reduceRight) {
754     Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
755         var self = toObject(this),
756             length = self.length >>> 0;
758         // If no callback function or if callback is not a callable function
759         if (toString(fun) != "[object Function]") {
760             throw new TypeError(); // TODO message
761         }
763         // no value to return if no initial value, empty array
764         if (!length && arguments.length == 1)
765             throw new TypeError(); // TODO message
767         var result, i = length - 1;
768         if (arguments.length >= 2) {
769             result = arguments[1];
770         } else {
771             do {
772                 if (i in self) {
773                     result = self[i--];
774                     break;
775                 }
777                 // if array contains no values, no initial value to return
778                 if (--i < 0)
779                     throw new TypeError(); // TODO message
780             } while (true);
781         }
783         do {
784             if (i in this)
785                 result = fun.call(void 0, result, self[i], i, self);
786         } while (i--);
788         return result;
789     };
792 // ES5 15.4.4.14
793 // http://es5.github.com/#x15.4.4.14
794 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
795 if (!Array.prototype.indexOf) {
796     Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
797         var self = toObject(this),
798             length = self.length >>> 0;
800         if (!length)
801             return -1;
803         var i = 0;
804         if (arguments.length > 1)
805             i = toInteger(arguments[1]);
807         // handle negative indices
808         i = i >= 0 ? i : Math.max(0, length + i);
809         for (; i < length; i++) {
810             if (i in self && self[i] === sought) {
811                 return i;
812             }
813         }
814         return -1;
815     };
818 // ES5 15.4.4.15
819 // http://es5.github.com/#x15.4.4.15
820 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
821 if (!Array.prototype.lastIndexOf) {
822     Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
823         var self = toObject(this),
824             length = self.length >>> 0;
826         if (!length)
827             return -1;
828         var i = length - 1;
829         if (arguments.length > 1)
830             i = Math.min(i, toInteger(arguments[1]));
831         // handle negative indices
832         i = i >= 0 ? i : length - Math.abs(i);
833         for (; i >= 0; i--) {
834             if (i in self && sought === self[i])
835                 return i;
836         }
837         return -1;
838     };
842 // Object
843 // ======
846 // ES5 15.2.3.2
847 // http://es5.github.com/#x15.2.3.2
848 if (!Object.getPrototypeOf) {
849     // https://github.com/kriskowal/es5-shim/issues#issue/2
850     // http://ejohn.org/blog/objectgetprototypeof/
851     // recommended by fschaefer on github
852     Object.getPrototypeOf = function getPrototypeOf(object) {
853         return object.__proto__ || (
854             object.constructor ?
855             object.constructor.prototype :
856             prototypeOfObject
857         );
858     };
861 // ES5 15.2.3.3
862 // http://es5.github.com/#x15.2.3.3
863 if (!Object.getOwnPropertyDescriptor) {
864     var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
865                          "non-object: ";
866     Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
867         if ((typeof object != "object" && typeof object != "function") || object === null)
868             throw new TypeError(ERR_NON_OBJECT + object);
869         // If object does not owns property return undefined immediately.
870         if (!owns(object, property))
871             return;
873         var descriptor, getter, setter;
875         // If object has a property then it's for sure both `enumerable` and
876         // `configurable`.
877         descriptor =  { enumerable: true, configurable: true };
879         // If JS engine supports accessor properties then property may be a
880         // getter or setter.
881         if (supportsAccessors) {
882             // Unfortunately `__lookupGetter__` will return a getter even
883             // if object has own non getter property along with a same named
884             // inherited getter. To avoid misbehavior we temporary remove
885             // `__proto__` so that `__lookupGetter__` will return getter only
886             // if it's owned by an object.
887             var prototype = object.__proto__;
888             object.__proto__ = prototypeOfObject;
890             var getter = lookupGetter(object, property);
891             var setter = lookupSetter(object, property);
893             // Once we have getter and setter we can put values back.
894             object.__proto__ = prototype;
896             if (getter || setter) {
897                 if (getter) descriptor.get = getter;
898                 if (setter) descriptor.set = setter;
900                 // If it was accessor property we're done and return here
901                 // in order to avoid adding `value` to the descriptor.
902                 return descriptor;
903             }
904         }
906         // If we got this far we know that object has an own property that is
907         // not an accessor so we set it as a value and return descriptor.
908         descriptor.value = object[property];
909         return descriptor;
910     };
913 // ES5 15.2.3.4
914 // http://es5.github.com/#x15.2.3.4
915 if (!Object.getOwnPropertyNames) {
916     Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
917         return Object.keys(object);
918     };
921 // ES5 15.2.3.5
922 // http://es5.github.com/#x15.2.3.5
923 if (!Object.create) {
924     Object.create = function create(prototype, properties) {
925         var object;
926         if (prototype === null) {
927             object = { "__proto__": null };
928         } else {
929             if (typeof prototype != "object")
930                 throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
931             var Type = function () {};
932             Type.prototype = prototype;
933             object = new Type();
934             // IE has no built-in implementation of `Object.getPrototypeOf`
935             // neither `__proto__`, but this manually setting `__proto__` will
936             // guarantee that `Object.getPrototypeOf` will work as expected with
937             // objects created using `Object.create`
938             object.__proto__ = prototype;
939         }
940         if (properties !== void 0)
941             Object.defineProperties(object, properties);
942         return object;
943     };
946 // ES5 15.2.3.6
947 // http://es5.github.com/#x15.2.3.6
949 // Patch for WebKit and IE8 standard mode
950 // Designed by hax <hax.github.com>
951 // related issue: https://github.com/kriskowal/es5-shim/issues#issue/5
952 // IE8 Reference:
953 //     http://msdn.microsoft.com/en-us/library/dd282900.aspx
954 //     http://msdn.microsoft.com/en-us/library/dd229916.aspx
955 // WebKit Bugs:
956 //     https://bugs.webkit.org/show_bug.cgi?id=36423
958 function doesDefinePropertyWork(object) {
959     try {
960         Object.defineProperty(object, "sentinel", {});
961         return "sentinel" in object;
962     } catch (exception) {
963         // returns falsy
964     }
967 // check whether defineProperty works if it's given. Otherwise,
968 // shim partially.
969 if (Object.defineProperty) {
970     var definePropertyWorksOnObject = doesDefinePropertyWork({});
971     var definePropertyWorksOnDom = typeof document == "undefined" ||
972         doesDefinePropertyWork(document.createElement("div"));
973     if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
974         var definePropertyFallback = Object.defineProperty;
975     }
978 if (!Object.defineProperty || definePropertyFallback) {
979     var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
980     var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
981     var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
982                                       "on this javascript engine";
984     Object.defineProperty = function defineProperty(object, property, descriptor) {
985         if ((typeof object != "object" && typeof object != "function") || object === null)
986             throw new TypeError(ERR_NON_OBJECT_TARGET + object);
987         if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
988             throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
990         // make a valiant attempt to use the real defineProperty
991         // for I8's DOM elements.
992         if (definePropertyFallback) {
993             try {
994                 return definePropertyFallback.call(Object, object, property, descriptor);
995             } catch (exception) {
996                 // try the shim if the real one doesn't work
997             }
998         }
1000         // If it's a data property.
1001         if (owns(descriptor, "value")) {
1002             // fail silently if "writable", "enumerable", or "configurable"
1003             // are requested but not supported
1004             /*
1005             // alternate approach:
1006             if ( // can't implement these features; allow false but not true
1007                 !(owns(descriptor, "writable") ? descriptor.writable : true) ||
1008                 !(owns(descriptor, "enumerable") ? descriptor.enumerable : true) ||
1009                 !(owns(descriptor, "configurable") ? descriptor.configurable : true)
1010             )
1011                 throw new RangeError(
1012                     "This implementation of Object.defineProperty does not " +
1013                     "support configurable, enumerable, or writable."
1014                 );
1015             */
1017             if (supportsAccessors && (lookupGetter(object, property) ||
1018                                       lookupSetter(object, property)))
1019             {
1020                 // As accessors are supported only on engines implementing
1021                 // `__proto__` we can safely override `__proto__` while defining
1022                 // a property to make sure that we don't hit an inherited
1023                 // accessor.
1024                 var prototype = object.__proto__;
1025                 object.__proto__ = prototypeOfObject;
1026                 // Deleting a property anyway since getter / setter may be
1027                 // defined on object itself.
1028                 delete object[property];
1029                 object[property] = descriptor.value;
1030                 // Setting original `__proto__` back now.
1031                 object.__proto__ = prototype;
1032             } else {
1033                 object[property] = descriptor.value;
1034             }
1035         } else {
1036             if (!supportsAccessors)
1037                 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1038             // If we got that far then getters and setters can be defined !!
1039             if (owns(descriptor, "get"))
1040                 defineGetter(object, property, descriptor.get);
1041             if (owns(descriptor, "set"))
1042                 defineSetter(object, property, descriptor.set);
1043         }
1045         return object;
1046     };
1049 // ES5 15.2.3.7
1050 // http://es5.github.com/#x15.2.3.7
1051 if (!Object.defineProperties) {
1052     Object.defineProperties = function defineProperties(object, properties) {
1053         for (var property in properties) {
1054             if (owns(properties, property))
1055                 Object.defineProperty(object, property, properties[property]);
1056         }
1057         return object;
1058     };
1061 // ES5 15.2.3.8
1062 // http://es5.github.com/#x15.2.3.8
1063 if (!Object.seal) {
1064     Object.seal = function seal(object) {
1065         // this is misleading and breaks feature-detection, but
1066         // allows "securable" code to "gracefully" degrade to working
1067         // but insecure code.
1068         return object;
1069     };
1072 // ES5 15.2.3.9
1073 // http://es5.github.com/#x15.2.3.9
1074 if (!Object.freeze) {
1075     Object.freeze = function freeze(object) {
1076         // this is misleading and breaks feature-detection, but
1077         // allows "securable" code to "gracefully" degrade to working
1078         // but insecure code.
1079         return object;
1080     };
1083 // detect a Rhino bug and patch it
1084 try {
1085     Object.freeze(function () {});
1086 } catch (exception) {
1087     Object.freeze = (function freeze(freezeObject) {
1088         return function freeze(object) {
1089             if (typeof object == "function") {
1090                 return object;
1091             } else {
1092                 return freezeObject(object);
1093             }
1094         };
1095     })(Object.freeze);
1098 // ES5 15.2.3.10
1099 // http://es5.github.com/#x15.2.3.10
1100 if (!Object.preventExtensions) {
1101     Object.preventExtensions = function preventExtensions(object) {
1102         // this is misleading and breaks feature-detection, but
1103         // allows "securable" code to "gracefully" degrade to working
1104         // but insecure code.
1105         return object;
1106     };
1109 // ES5 15.2.3.11
1110 // http://es5.github.com/#x15.2.3.11
1111 if (!Object.isSealed) {
1112     Object.isSealed = function isSealed(object) {
1113         return false;
1114     };
1117 // ES5 15.2.3.12
1118 // http://es5.github.com/#x15.2.3.12
1119 if (!Object.isFrozen) {
1120     Object.isFrozen = function isFrozen(object) {
1121         return false;
1122     };
1125 // ES5 15.2.3.13
1126 // http://es5.github.com/#x15.2.3.13
1127 if (!Object.isExtensible) {
1128     Object.isExtensible = function isExtensible(object) {
1129         // 1. If Type(O) is not Object throw a TypeError exception.
1130         if (Object(object) === object) {
1131             throw new TypeError(); // TODO message
1132         }
1133         // 2. Return the Boolean value of the [[Extensible]] internal property of O.
1134         var name = '';
1135         while (owns(object, name)) {
1136             name += '?';
1137         }
1138         object[name] = true;
1139         var returnValue = owns(object, name);
1140         delete object[name];
1141         return returnValue;
1142     };
1145 // ES5 15.2.3.14
1146 // http://es5.github.com/#x15.2.3.14
1147 if (!Object.keys) {
1148     // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
1149     var hasDontEnumBug = true,
1150         dontEnums = [
1151             "toString",
1152             "toLocaleString",
1153             "valueOf",
1154             "hasOwnProperty",
1155             "isPrototypeOf",
1156             "propertyIsEnumerable",
1157             "constructor"
1158         ],
1159         dontEnumsLength = dontEnums.length;
1161     for (var key in {"toString": null})
1162         hasDontEnumBug = false;
1164     Object.keys = function keys(object) {
1166         if ((typeof object != "object" && typeof object != "function") || object === null)
1167             throw new TypeError("Object.keys called on a non-object");
1169         var keys = [];
1170         for (var name in object) {
1171             if (owns(object, name)) {
1172                 keys.push(name);
1173             }
1174         }
1176         if (hasDontEnumBug) {
1177             for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
1178                 var dontEnum = dontEnums[i];
1179                 if (owns(object, dontEnum)) {
1180                     keys.push(dontEnum);
1181                 }
1182             }
1183         }
1185         return keys;
1186     };
1191 // Date
1192 // ====
1195 // ES5 15.9.5.43
1196 // http://es5.github.com/#x15.9.5.43
1197 // This function returns a String value represent the instance in time 
1198 // represented by this Date object. The format of the String is the Date Time 
1199 // string format defined in 15.9.1.15. All fields are present in the String. 
1200 // The time zone is always UTC, denoted by the suffix Z. If the time value of 
1201 // this object is not a finite Number a RangeError exception is thrown.
1202 if (!Date.prototype.toISOString || (new Date(-62198755200000).toISOString().indexOf('-000001') === -1)) {
1203     Date.prototype.toISOString = function toISOString() {
1204         var result, length, value, year;
1205         if (!isFinite(this))
1206             throw new RangeError;
1208         // the date time string format is specified in 15.9.1.15.
1209         result = [this.getUTCMonth() + 1, this.getUTCDate(),
1210             this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
1211         year = this.getUTCFullYear();
1212         year = (year < 0 ? '-' : (year > 9999 ? '+' : '')) + ('00000' + Math.abs(year)).slice(0 <= year && year <= 9999 ? -4 : -6);
1214         length = result.length;
1215         while (length--) {
1216             value = result[length];
1217             // pad months, days, hours, minutes, and seconds to have two digits.
1218             if (value < 10)
1219                 result[length] = "0" + value;
1220         }
1221         // pad milliseconds to have three digits.
1222         return year + "-" + result.slice(0, 2).join("-") + "T" + result.slice(2).join(":") + "." +
1223             ("000" + this.getUTCMilliseconds()).slice(-3) + "Z";
1224     }
1227 // ES5 15.9.4.4
1228 // http://es5.github.com/#x15.9.4.4
1229 if (!Date.now) {
1230     Date.now = function now() {
1231         return new Date().getTime();
1232     };
1235 // ES5 15.9.5.44
1236 // http://es5.github.com/#x15.9.5.44
1237 // This function provides a String representation of a Date object for use by 
1238 // JSON.stringify (15.12.3).
1239 if (!Date.prototype.toJSON) {
1240     Date.prototype.toJSON = function toJSON(key) {
1241         // When the toJSON method is called with argument key, the following 
1242         // steps are taken:
1244         // 1.  Let O be the result of calling ToObject, giving it the this
1245         // value as its argument.
1246         // 2. Let tv be ToPrimitive(O, hint Number).
1247         // 3. If tv is a Number and is not finite, return null.
1248         // XXX
1249         // 4. Let toISO be the result of calling the [[Get]] internal method of
1250         // O with argument "toISOString".
1251         // 5. If IsCallable(toISO) is false, throw a TypeError exception.
1252         if (typeof this.toISOString != "function")
1253             throw new TypeError(); // TODO message
1254         // 6. Return the result of calling the [[Call]] internal method of
1255         //  toISO with O as the this value and an empty argument list.
1256         return this.toISOString();
1258         // NOTE 1 The argument is ignored.
1260         // NOTE 2 The toJSON function is intentionally generic; it does not
1261         // require that its this value be a Date object. Therefore, it can be
1262         // transferred to other kinds of objects for use as a method. However,
1263         // it does require that any such object have a toISOString method. An
1264         // object is free to use the argument key to filter its
1265         // stringification.
1266     };
1269 // ES5 15.9.4.2
1270 // http://es5.github.com/#x15.9.4.2
1271 // based on work shared by Daniel Friesen (dantman)
1272 // http://gist.github.com/303249
1273 if (Date.parse("+275760-09-13T00:00:00.000Z") !== 8.64e15) {
1274     // XXX global assignment won't work in embeddings that use
1275     // an alternate object for the context.
1276     Date = (function(NativeDate) {
1278         // Date.length === 7
1279         var Date = function Date(Y, M, D, h, m, s, ms) {
1280             var length = arguments.length;
1281             if (this instanceof NativeDate) {
1282                 var date = length == 1 && String(Y) === Y ? // isString(Y)
1283                     // We explicitly pass it through parse:
1284                     new NativeDate(Date.parse(Y)) :
1285                     // We have to manually make calls depending on argument
1286                     // length here
1287                     length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
1288                     length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
1289                     length >= 5 ? new NativeDate(Y, M, D, h, m) :
1290                     length >= 4 ? new NativeDate(Y, M, D, h) :
1291                     length >= 3 ? new NativeDate(Y, M, D) :
1292                     length >= 2 ? new NativeDate(Y, M) :
1293                     length >= 1 ? new NativeDate(Y) :
1294                                   new NativeDate();
1295                 // Prevent mixups with unfixed Date object
1296                 date.constructor = Date;
1297                 return date;
1298             }
1299             return NativeDate.apply(this, arguments);
1300         };
1302         // 15.9.1.15 Date Time String Format.
1303         var isoDateExpression = new RegExp("^" +
1304             "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign + 6-digit extended year
1305             "(?:-(\\d{2})" + // optional month capture
1306             "(?:-(\\d{2})" + // optional day capture
1307             "(?:" + // capture hours:minutes:seconds.milliseconds
1308                 "T(\\d{2})" + // hours capture
1309                 ":(\\d{2})" + // minutes capture
1310                 "(?:" + // optional :seconds.milliseconds
1311                     ":(\\d{2})" + // seconds capture
1312                     "(?:\\.(\\d{3}))?" + // milliseconds capture
1313                 ")?" +
1314             "(?:" + // capture UTC offset component
1315                 "Z|" + // UTC capture
1316                 "(?:" + // offset specifier +/-hours:minutes
1317                     "([-+])" + // sign capture
1318                     "(\\d{2})" + // hours offset capture
1319                     ":(\\d{2})" + // minutes offset capture
1320                 ")" +
1321             ")?)?)?)?" +
1322         "$");
1324         // Copy any custom methods a 3rd party library may have added
1325         for (var key in NativeDate)
1326             Date[key] = NativeDate[key];
1328         // Copy "native" methods explicitly; they may be non-enumerable
1329         Date.now = NativeDate.now;
1330         Date.UTC = NativeDate.UTC;
1331         Date.prototype = NativeDate.prototype;
1332         Date.prototype.constructor = Date;
1334         // Upgrade Date.parse to handle simplified ISO 8601 strings
1335         Date.parse = function parse(string) {
1336             var match = isoDateExpression.exec(string);
1337             if (match) {
1338                 match.shift(); // kill match[0], the full match
1339                 // parse months, days, hours, minutes, seconds, and milliseconds
1340                 for (var i = 1; i < 7; i++) {
1341                     // provide default values if necessary
1342                     match[i] = +(match[i] || (i < 3 ? 1 : 0));
1343                     // match[1] is the month. Months are 0-11 in JavaScript
1344                     // `Date` objects, but 1-12 in ISO notation, so we
1345                     // decrement.
1346                     if (i == 1)
1347                         match[i]--;
1348                 }
1350                 // parse the UTC offset component
1351                 var minuteOffset = +match.pop(), hourOffset = +match.pop(), sign = match.pop();
1353                 // compute the explicit time zone offset if specified
1354                 var offset = 0;
1355                 if (sign) {
1356                     // detect invalid offsets and return early
1357                     if (hourOffset > 23 || minuteOffset > 59)
1358                         return NaN;
1360                     // express the provided time zone offset in minutes. The offset is
1361                     // negative for time zones west of UTC; positive otherwise.
1362                     offset = (hourOffset * 60 + minuteOffset) * 6e4 * (sign == "+" ? -1 : 1);
1363                 }
1365                 // Date.UTC for years between 0 and 99 converts year to 1900 + year
1366                 // The Gregorian calendar has a 400-year cycle, so 
1367                 // to Date.UTC(year + 400, .... ) - 12622780800000 == Date.UTC(year, ...),
1368                 // where 12622780800000 - number of milliseconds in Gregorian calendar 400 years
1369                 var year = +match[0];
1370                 if (0 <= year && year <= 99) {
1371                     match[0] = year + 400;
1372                     return NativeDate.UTC.apply(this, match) + offset - 12622780800000;
1373                 }
1375                 // compute a new UTC date value, accounting for the optional offset
1376                 return NativeDate.UTC.apply(this, match) + offset;
1377             }
1378             return NativeDate.parse.apply(this, arguments);
1379         };
1381         return Date;
1382     })(Date);
1386 // String
1387 // ======
1390 // ES5 15.5.4.20
1391 // http://es5.github.com/#x15.5.4.20
1392 var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
1393     "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
1394     "\u2029\uFEFF";
1395 if (!String.prototype.trim || ws.trim()) {
1396     // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1397     // http://perfectionkills.com/whitespace-deviations/
1398     ws = "[" + ws + "]";
1399     var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
1400         trimEndRegexp = new RegExp(ws + ws + "*$");
1401     String.prototype.trim = function trim() {
1402         return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
1403     };
1407 // Util
1408 // ======
1411 // ES5 9.4
1412 // http://es5.github.com/#x9.4
1413 // http://jsperf.com/to-integer
1414 var toInteger = function (n) {
1415     n = +n;
1416     if (n !== n) // isNaN
1417         n = 0;
1418     else if (n !== 0 && n !== (1/0) && n !== -(1/0))
1419         n = (n > 0 || -1) * Math.floor(Math.abs(n));
1420     return n;
1423 var prepareString = "a"[0] != "a",
1424     // ES5 9.9
1425     // http://es5.github.com/#x9.9
1426     toObject = function (o) {
1427         if (o == null) { // this matches both null and undefined
1428             throw new TypeError(); // TODO message
1429         }
1430         // If the implementation doesn't support by-index access of
1431         // string characters (ex. IE < 7), split the string
1432         if (prepareString && typeof o == "string" && o) {
1433             return o.split("");
1434         }
1435         return Object(o);
1436     };
1439 define('ace/lib/dom', ['require', 'exports', 'module' ], function(require, exports, module) {
1442 var XHTML_NS = "http://www.w3.org/1999/xhtml";
1444 exports.createElement = function(tag, ns) {
1445     return document.createElementNS ?
1446            document.createElementNS(ns || XHTML_NS, tag) :
1447            document.createElement(tag);
1450 exports.setText = function(elem, text) {
1451     if (elem.innerText !== undefined) {
1452         elem.innerText = text;
1453     }
1454     if (elem.textContent !== undefined) {
1455         elem.textContent = text;
1456     }
1459 exports.hasCssClass = function(el, name) {
1460     var classes = el.className.split(/\s+/g);
1461     return classes.indexOf(name) !== -1;
1463 exports.addCssClass = function(el, name) {
1464     if (!exports.hasCssClass(el, name)) {
1465         el.className += " " + name;
1466     }
1468 exports.removeCssClass = function(el, name) {
1469     var classes = el.className.split(/\s+/g);
1470     while (true) {
1471         var index = classes.indexOf(name);
1472         if (index == -1) {
1473             break;
1474         }
1475         classes.splice(index, 1);
1476     }
1477     el.className = classes.join(" ");
1480 exports.toggleCssClass = function(el, name) {
1481     var classes = el.className.split(/\s+/g), add = true;
1482     while (true) {
1483         var index = classes.indexOf(name);
1484         if (index == -1) {
1485             break;
1486         }
1487         add = false;
1488         classes.splice(index, 1);
1489     }
1490     if(add)
1491         classes.push(name);
1493     el.className = classes.join(" ");
1494     return add;
1496 exports.setCssClass = function(node, className, include) {
1497     if (include) {
1498         exports.addCssClass(node, className);
1499     } else {
1500         exports.removeCssClass(node, className);
1501     }
1504 exports.hasCssString = function(id, doc) {
1505     var index = 0, sheets;
1506     doc = doc || document;
1508     if (doc.createStyleSheet && (sheets = doc.styleSheets)) {
1509         while (index < sheets.length)
1510             if (sheets[index++].owningElement.id === id) return true;
1511     } else if ((sheets = doc.getElementsByTagName("style"))) {
1512         while (index < sheets.length)
1513             if (sheets[index++].id === id) return true;
1514     }
1516     return false;
1519 exports.importCssString = function importCssString(cssText, id, doc) {
1520     doc = doc || document;
1521     // If style is already imported return immediately.
1522     if (id && exports.hasCssString(id, doc))
1523         return null;
1524     
1525     var style;
1526     
1527     if (doc.createStyleSheet) {
1528         style = doc.createStyleSheet();
1529         style.cssText = cssText;
1530         if (id)
1531             style.owningElement.id = id;
1532     } else {
1533         style = doc.createElementNS
1534             ? doc.createElementNS(XHTML_NS, "style")
1535             : doc.createElement("style");
1537         style.appendChild(doc.createTextNode(cssText));
1538         if (id)
1539             style.id = id;
1541         var head = doc.getElementsByTagName("head")[0] || doc.documentElement;
1542         head.appendChild(style);
1543     }
1546 exports.importCssStylsheet = function(uri, doc) {
1547     if (doc.createStyleSheet) {
1548         doc.createStyleSheet(uri);
1549     } else {
1550         var link = exports.createElement('link');
1551         link.rel = 'stylesheet';
1552         link.href = uri;
1554         var head = doc.getElementsByTagName("head")[0] || doc.documentElement;
1555         head.appendChild(link);
1556     }
1559 exports.getInnerWidth = function(element) {
1560     return (
1561         parseInt(exports.computedStyle(element, "paddingLeft"), 10) +
1562         parseInt(exports.computedStyle(element, "paddingRight"), 10) + 
1563         element.clientWidth
1564     );
1567 exports.getInnerHeight = function(element) {
1568     return (
1569         parseInt(exports.computedStyle(element, "paddingTop"), 10) +
1570         parseInt(exports.computedStyle(element, "paddingBottom"), 10) +
1571         element.clientHeight
1572     );
1575 if (window.pageYOffset !== undefined) {
1576     exports.getPageScrollTop = function() {
1577         return window.pageYOffset;
1578     };
1580     exports.getPageScrollLeft = function() {
1581         return window.pageXOffset;
1582     };
1584 else {
1585     exports.getPageScrollTop = function() {
1586         return document.body.scrollTop;
1587     };
1589     exports.getPageScrollLeft = function() {
1590         return document.body.scrollLeft;
1591     };
1594 if (window.getComputedStyle)
1595     exports.computedStyle = function(element, style) {
1596         if (style)
1597             return (window.getComputedStyle(element, "") || {})[style] || "";
1598         return window.getComputedStyle(element, "") || {};
1599     };
1600 else
1601     exports.computedStyle = function(element, style) {
1602         if (style)
1603             return element.currentStyle[style];
1604         return element.currentStyle;
1605     };
1607 exports.scrollbarWidth = function(document) {
1609     var inner = exports.createElement("p");
1610     inner.style.width = "100%";
1611     inner.style.minWidth = "0px";
1612     inner.style.height = "200px";
1614     var outer = exports.createElement("div");
1615     var style = outer.style;
1617     style.position = "absolute";
1618     style.left = "-10000px";
1619     style.overflow = "hidden";
1620     style.width = "200px";
1621     style.minWidth = "0px";
1622     style.height = "150px";
1624     outer.appendChild(inner);
1626     var body = document.body || document.documentElement;
1627     body.appendChild(outer);
1629     var noScrollbar = inner.offsetWidth;
1631     style.overflow = "scroll";
1632     var withScrollbar = inner.offsetWidth;
1634     if (noScrollbar == withScrollbar) {
1635         withScrollbar = outer.clientWidth;
1636     }
1638     body.removeChild(outer);
1640     return noScrollbar-withScrollbar;
1642 exports.setInnerHtml = function(el, innerHtml) {
1643     var element = el.cloneNode(false);//document.createElement("div");
1644     element.innerHTML = innerHtml;
1645     el.parentNode.replaceChild(element, el);
1646     return element;
1649 exports.setInnerText = function(el, innerText) {
1650     var document = el.ownerDocument;
1651     if (document.body && "textContent" in document.body)
1652         el.textContent = innerText;
1653     else
1654         el.innerText = innerText;
1658 exports.getInnerText = function(el) {
1659     var document = el.ownerDocument;
1660     if (document.body && "textContent" in document.body)
1661         return el.textContent;
1662     else
1663          return el.innerText || el.textContent || "";
1666 exports.getParentWindow = function(document) {
1667     return document.defaultView || document.parentWindow;
1672 define('ace/lib/event', ['require', 'exports', 'module' , 'ace/lib/keys', 'ace/lib/useragent', 'ace/lib/dom'], function(require, exports, module) {
1675 var keys = require("./keys");
1676 var useragent = require("./useragent");
1677 var dom = require("./dom");
1679 exports.addListener = function(elem, type, callback) {
1680     if (elem.addEventListener) {
1681         return elem.addEventListener(type, callback, false);
1682     }
1683     if (elem.attachEvent) {
1684         var wrapper = function() {
1685             callback(window.event);
1686         };
1687         callback._wrapper = wrapper;
1688         elem.attachEvent("on" + type, wrapper);
1689     }
1692 exports.removeListener = function(elem, type, callback) {
1693     if (elem.removeEventListener) {
1694         return elem.removeEventListener(type, callback, false);
1695     }
1696     if (elem.detachEvent) {
1697         elem.detachEvent("on" + type, callback._wrapper || callback);
1698     }
1700 exports.stopEvent = function(e) {
1701     exports.stopPropagation(e);
1702     exports.preventDefault(e);
1703     return false;
1706 exports.stopPropagation = function(e) {
1707     if (e.stopPropagation)
1708         e.stopPropagation();
1709     else
1710         e.cancelBubble = true;
1713 exports.preventDefault = function(e) {
1714     if (e.preventDefault)
1715         e.preventDefault();
1716     else
1717         e.returnValue = false;
1719 exports.getButton = function(e) {
1720     if (e.type == "dblclick")
1721         return 0;
1722     if (e.type == "contextmenu" || (e.ctrlKey && useragent.isMac))
1723         return 2;
1725     // DOM Event
1726     if (e.preventDefault) {
1727         return e.button;
1728     }
1729     // old IE
1730     else {
1731         return {1:0, 2:2, 4:1}[e.button];
1732     }
1735 if (document.documentElement.setCapture) {
1736     exports.capture = function(el, eventHandler, releaseCaptureHandler) {
1737         var called = false;
1738         function onReleaseCapture(e) {
1739             eventHandler(e);
1741             if (!called) {
1742                 called = true;
1743                 releaseCaptureHandler(e);
1744             }
1746             exports.removeListener(el, "mousemove", eventHandler);
1747             exports.removeListener(el, "mouseup", onReleaseCapture);
1748             exports.removeListener(el, "losecapture", onReleaseCapture);
1750             el.releaseCapture();
1751         }
1753         exports.addListener(el, "mousemove", eventHandler);
1754         exports.addListener(el, "mouseup", onReleaseCapture);
1755         exports.addListener(el, "losecapture", onReleaseCapture);
1756         el.setCapture();
1757     };
1759 else {
1760     exports.capture = function(el, eventHandler, releaseCaptureHandler) {
1761         function onMouseUp(e) {
1762             eventHandler && eventHandler(e);
1763             releaseCaptureHandler && releaseCaptureHandler(e);
1765             document.removeEventListener("mousemove", eventHandler, true);
1766             document.removeEventListener("mouseup", onMouseUp, true);
1768             e.stopPropagation();
1769         }
1771         document.addEventListener("mousemove", eventHandler, true);
1772         document.addEventListener("mouseup", onMouseUp, true);
1773     };
1776 exports.addMouseWheelListener = function(el, callback) {
1777     var factor = 8;
1778     var listener = function(e) {
1779         if (e.wheelDelta !== undefined) {
1780             if (e.wheelDeltaX !== undefined) {
1781                 e.wheelX = -e.wheelDeltaX / factor;
1782                 e.wheelY = -e.wheelDeltaY / factor;
1783             } else {
1784                 e.wheelX = 0;
1785                 e.wheelY = -e.wheelDelta / factor;
1786             }
1787         }
1788         else {
1789             if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
1790                 e.wheelX = (e.detail || 0) * 5;
1791                 e.wheelY = 0;
1792             } else {
1793                 e.wheelX = 0;
1794                 e.wheelY = (e.detail || 0) * 5;
1795             }
1796         }
1797         callback(e);
1798     };
1799     exports.addListener(el, "DOMMouseScroll", listener);
1800     exports.addListener(el, "mousewheel", listener);
1803 exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbackName) {
1804     var clicks = 0;
1805     var startX, startY, timer;
1806     var eventNames = {
1807         2: "dblclick",
1808         3: "tripleclick",
1809         4: "quadclick"
1810     };
1812     exports.addListener(el, "mousedown", function(e) {
1813         if (exports.getButton(e) != 0) {
1814             clicks = 0;
1815         } else {
1816             var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
1818             if (!timer || isNewClick)
1819                 clicks = 0;
1821             clicks += 1;
1823             if (timer)
1824                 clearTimeout(timer)
1825             timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
1826         }
1827         if (clicks == 1) {
1828             startX = e.clientX;
1829             startY = e.clientY;
1830         }
1832         eventHandler[callbackName]("mousedown", e);
1834         if (clicks > 4)
1835             clicks = 0;
1836         else if (clicks > 1)
1837             return eventHandler[callbackName](eventNames[clicks], e);
1838     });
1840     if (useragent.isOldIE) {
1841         exports.addListener(el, "dblclick", function(e) {
1842             clicks = 2;
1843             if (timer)
1844                 clearTimeout(timer);
1845             timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
1846             eventHandler[callbackName]("mousedown", e);
1847             eventHandler[callbackName](eventNames[clicks], e);
1848         });
1849     }
1852 function normalizeCommandKeys(callback, e, keyCode) {
1853     var hashId = 0;
1854     if ((useragent.isOpera && !("KeyboardEvent" in window)) && useragent.isMac) {
1855         hashId = 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0)
1856             | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
1857     } else {
1858         hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0)
1859             | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
1860     }
1862     if (keyCode in keys.MODIFIER_KEYS) {
1863         switch (keys.MODIFIER_KEYS[keyCode]) {
1864             case "Alt":
1865                 hashId = 2;
1866                 break;
1867             case "Shift":
1868                 hashId = 4;
1869                 break;
1870             case "Ctrl":
1871                 hashId = 1;
1872                 break;
1873             default:
1874                 hashId = 8;
1875                 break;
1876         }
1877         keyCode = 0;
1878     }
1880     if (hashId & 8 && (keyCode == 91 || keyCode == 93)) {
1881         keyCode = 0;
1882     }
1884     // If there is no hashID and the keyCode is not a function key, then
1885     // we don't call the callback as we don't handle a command key here
1886     // (it's a normal key/character input).
1887     if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
1888         return false;
1889     }
1890     return callback(e, hashId, keyCode);
1893 exports.addCommandKeyListener = function(el, callback) {
1894     var addListener = exports.addListener;
1895     if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
1896         // Old versions of Gecko aka. Firefox < 4.0 didn't repeat the keydown
1897         // event if the user pressed the key for a longer time. Instead, the
1898         // keydown event was fired once and later on only the keypress event.
1899         // To emulate the 'right' keydown behavior, the keyCode of the initial
1900         // keyDown event is stored and in the following keypress events the
1901         // stores keyCode is used to emulate a keyDown event.
1902         var lastKeyDownKeyCode = null;
1903         addListener(el, "keydown", function(e) {
1904             lastKeyDownKeyCode = e.keyCode;
1905         });
1906         addListener(el, "keypress", function(e) {
1907             return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
1908         });
1909     } else {
1910         var lastDown = null;
1912         addListener(el, "keydown", function(e) {
1913             lastDown = e.keyIdentifier || e.keyCode;
1914             return normalizeCommandKeys(callback, e, e.keyCode);
1915         });
1916     }
1919 if (window.postMessage && !useragent.isOldIE) {
1920     var postMessageId = 1;
1921     exports.nextTick = function(callback, win) {
1922         win = win || window;
1923         var messageName = "zero-timeout-message-" + postMessageId;            
1924         exports.addListener(win, "message", function listener(e) {
1925             if (e.data == messageName) {
1926                 exports.stopPropagation(e);
1927                 exports.removeListener(win, "message", listener);
1928                 callback();
1929             }
1930         });
1931         win.postMessage(messageName, "*");
1932     };
1934 else {
1935     exports.nextTick = function(callback, win) {
1936         win = win || window;
1937         window.setTimeout(callback, 0);
1938     };
1943 // Most of the following code is taken from SproutCore with a few changes.
1945 define('ace/lib/keys', ['require', 'exports', 'module' , 'ace/lib/oop'], function(require, exports, module) {
1948 var oop = require("./oop");
1949 var Keys = (function() {
1950     var ret = {
1951         MODIFIER_KEYS: {
1952             16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
1953         },
1955         KEY_MODS: {
1956             "ctrl": 1, "alt": 2, "option" : 2,
1957             "shift": 4, "meta": 8, "command": 8
1958         },
1960         FUNCTION_KEYS : {
1961             8  : "Backspace",
1962             9  : "Tab",
1963             13 : "Return",
1964             19 : "Pause",
1965             27 : "Esc",
1966             32 : "Space",
1967             33 : "PageUp",
1968             34 : "PageDown",
1969             35 : "End",
1970             36 : "Home",
1971             37 : "Left",
1972             38 : "Up",
1973             39 : "Right",
1974             40 : "Down",
1975             44 : "Print",
1976             45 : "Insert",
1977             46 : "Delete",
1978             96 : "Numpad0",
1979             97 : "Numpad1",
1980             98 : "Numpad2",
1981             99 : "Numpad3",
1982             100: "Numpad4",
1983             101: "Numpad5",
1984             102: "Numpad6",
1985             103: "Numpad7",
1986             104: "Numpad8",
1987             105: "Numpad9",
1988             112: "F1",
1989             113: "F2",
1990             114: "F3",
1991             115: "F4",
1992             116: "F5",
1993             117: "F6",
1994             118: "F7",
1995             119: "F8",
1996             120: "F9",
1997             121: "F10",
1998             122: "F11",
1999             123: "F12",
2000             144: "Numlock",
2001             145: "Scrolllock"
2002         },
2004         PRINTABLE_KEYS: {
2005            32: ' ',  48: '0',  49: '1',  50: '2',  51: '3',  52: '4', 53:  '5',
2006            54: '6',  55: '7',  56: '8',  57: '9',  59: ';',  61: '=', 65:  'a',
2007            66: 'b',  67: 'c',  68: 'd',  69: 'e',  70: 'f',  71: 'g', 72:  'h',
2008            73: 'i',  74: 'j',  75: 'k',  76: 'l',  77: 'm',  78: 'n', 79:  'o',
2009            80: 'p',  81: 'q',  82: 'r',  83: 's',  84: 't',  85: 'u', 86:  'v',
2010            87: 'w',  88: 'x',  89: 'y',  90: 'z', 107: '+', 109: '-', 110: '.',
2011           188: ',', 190: '.', 191: '/', 192: '`', 219: '[', 220: '\\',
2012           221: ']', 222: '\''
2013         }
2014     };
2016     // A reverse map of FUNCTION_KEYS
2017     for (var i in ret.FUNCTION_KEYS) {
2018         var name = ret.FUNCTION_KEYS[i].toLowerCase();
2019         ret[name] = parseInt(i, 10);
2020     }
2022     // Add the MODIFIER_KEYS, FUNCTION_KEYS and PRINTABLE_KEYS to the KEY
2023     // variables as well.
2024     oop.mixin(ret, ret.MODIFIER_KEYS);
2025     oop.mixin(ret, ret.PRINTABLE_KEYS);
2026     oop.mixin(ret, ret.FUNCTION_KEYS);
2028     // aliases
2029     ret.enter = ret["return"];
2030     ret.escape = ret.esc;
2031     ret.del = ret["delete"];
2032     
2033     // workaround for firefox bug
2034     ret[173] = '-';
2036     return ret;
2037 })();
2038 oop.mixin(exports, Keys);
2040 exports.keyCodeToString = function(keyCode) {
2041     return (Keys[keyCode] || String.fromCharCode(keyCode)).toLowerCase();
2046 define('ace/lib/oop', ['require', 'exports', 'module' ], function(require, exports, module) {
2049 exports.inherits = (function() {
2050     var tempCtor = function() {};
2051     return function(ctor, superCtor) {
2052         tempCtor.prototype = superCtor.prototype;
2053         ctor.super_ = superCtor.prototype;
2054         ctor.prototype = new tempCtor();
2055         ctor.prototype.constructor = ctor;
2056     };
2057 }());
2059 exports.mixin = function(obj, mixin) {
2060     for (var key in mixin) {
2061         obj[key] = mixin[key];
2062     }
2065 exports.implement = function(proto, mixin) {
2066     exports.mixin(proto, mixin);
2071 define('ace/lib/useragent', ['require', 'exports', 'module' ], function(require, exports, module) {
2074 var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
2075 var ua = navigator.userAgent;
2077 // Is the user using a browser that identifies itself as Windows
2078 exports.isWin = (os == "win");
2080 // Is the user using a browser that identifies itself as Mac OS
2081 exports.isMac = (os == "mac");
2083 // Is the user using a browser that identifies itself as Linux
2084 exports.isLinux = (os == "linux");
2086 exports.isIE = 
2087     navigator.appName == "Microsoft Internet Explorer"
2088     && parseFloat(navigator.userAgent.match(/MSIE ([0-9]+[\.0-9]+)/)[1]);
2089     
2090 exports.isOldIE = exports.isIE && exports.isIE < 9;
2092 // Is this Firefox or related?
2093 exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
2095 // oldGecko == rev < 2.0 
2096 exports.isOldGecko = exports.isGecko && parseInt((navigator.userAgent.match(/rv\:(\d+)/)||[])[1], 10) < 4;
2098 // Is this Opera 
2099 exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
2101 // Is the user using a browser that identifies itself as WebKit 
2102 exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
2104 exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
2106 exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
2108 exports.isIPad = ua.indexOf("iPad") >= 0;
2110 exports.isTouchPad = ua.indexOf("TouchPad") >= 0;
2111 exports.OS = {
2112     LINUX: "LINUX",
2113     MAC: "MAC",
2114     WINDOWS: "WINDOWS"
2116 exports.getOS = function() {
2117     if (exports.isMac) {
2118         return exports.OS.MAC;
2119     } else if (exports.isLinux) {
2120         return exports.OS.LINUX;
2121     } else {
2122         return exports.OS.WINDOWS;
2123     }
2128 define('ace/editor', ['require', 'exports', 'module' , 'ace/lib/fixoldbrowsers', 'ace/lib/oop', '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'], function(require, exports, module) {
2131 require("./lib/fixoldbrowsers");
2133 var oop = require("./lib/oop");
2134 var lang = require("./lib/lang");
2135 var useragent = require("./lib/useragent");
2136 var TextInput = require("./keyboard/textinput").TextInput;
2137 var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
2138 var FoldHandler = require("./mouse/fold_handler").FoldHandler;
2139 var KeyBinding = require("./keyboard/keybinding").KeyBinding;
2140 var EditSession = require("./edit_session").EditSession;
2141 var Search = require("./search").Search;
2142 var Range = require("./range").Range;
2143 var EventEmitter = require("./lib/event_emitter").EventEmitter;
2144 var CommandManager = require("./commands/command_manager").CommandManager;
2145 var defaultCommands = require("./commands/default_commands").commands;
2148  * new Editor(renderer, session)
2149  * - renderer (VirtualRenderer): Associated `VirtualRenderer` that draws everything
2150  * - session (EditSession): The `EditSession` to refer to
2152  * Creates a new `Editor` object.
2154  **/
2155 var Editor = function(renderer, session) {
2156     var container = renderer.getContainerElement();
2157     this.container = container;
2158     this.renderer = renderer;
2160     this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
2161     this.textInput  = new TextInput(renderer.getTextAreaContainer(), this);
2162     this.renderer.textarea = this.textInput.getElement();
2163     this.keyBinding = new KeyBinding(this);
2165     // TODO detect touch event support
2166     this.$mouseHandler = new MouseHandler(this);
2167     new FoldHandler(this);
2169     this.$blockScrolling = 0;
2170     this.$search = new Search().set({
2171         wrap: true
2172     });
2174     this.setSession(session || new EditSession(""));
2177 (function(){
2179     oop.implement(this, EventEmitter);
2180     this.setKeyboardHandler = function(keyboardHandler) {
2181         this.keyBinding.setKeyboardHandler(keyboardHandler);
2182     };
2183     this.getKeyboardHandler = function() {
2184         return this.keyBinding.getKeyboardHandler();
2185     };
2186     /**
2187      * Editor@changeSession(e) 
2188      * - e (Object): An object with two properties, `oldSession` and `session`, that represent the old and new [[EditSession]]s.
2189      *
2190      * Emitted whenever the [[EditSession]] changes.
2191      **/
2192     this.setSession = function(session) {
2193         if (this.session == session)
2194             return;
2196         if (this.session) {
2197             var oldSession = this.session;
2198             this.session.removeEventListener("change", this.$onDocumentChange);
2199             this.session.removeEventListener("changeMode", this.$onChangeMode);
2200             this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
2201             this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
2202             this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
2203             this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
2204             this.session.removeEventListener("onChangeFold", this.$onChangeFold);
2205             this.session.removeEventListener("changeFrontMarker", this.$onChangeFrontMarker);
2206             this.session.removeEventListener("changeBackMarker", this.$onChangeBackMarker);
2207             this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
2208             this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
2209             this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
2210             this.session.removeEventListener("changeScrollTop", this.$onScrollTopChange);
2211             this.session.removeEventListener("changeLeftTop", this.$onScrollLeftChange);
2213             var selection = this.session.getSelection();
2214             selection.removeEventListener("changeCursor", this.$onCursorChange);
2215             selection.removeEventListener("changeSelection", this.$onSelectionChange);
2216         }
2218         this.session = session;
2220         this.$onDocumentChange = this.onDocumentChange.bind(this);
2221         session.addEventListener("change", this.$onDocumentChange);
2222         this.renderer.setSession(session);
2224         this.$onChangeMode = this.onChangeMode.bind(this);
2225         session.addEventListener("changeMode", this.$onChangeMode);
2227         this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
2228         session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
2230         this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
2231         session.addEventListener("changeTabSize", this.$onChangeTabSize);
2233         this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
2234         session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
2236         this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
2237         session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
2239         this.$onChangeFold = this.onChangeFold.bind(this);
2240         session.addEventListener("changeFold", this.$onChangeFold);
2242         this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
2243         this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
2245         this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
2246         this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
2248         this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
2249         this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
2251         this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
2252         this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
2254         this.$onCursorChange = this.onCursorChange.bind(this);
2255         this.session.addEventListener("changeOverwrite", this.$onCursorChange);
2257         this.$onScrollTopChange = this.onScrollTopChange.bind(this);
2258         this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
2260         this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
2261         this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
2263         this.selection = session.getSelection();
2264         this.selection.addEventListener("changeCursor", this.$onCursorChange);
2266         this.$onSelectionChange = this.onSelectionChange.bind(this);
2267         this.selection.addEventListener("changeSelection", this.$onSelectionChange);
2269         this.onChangeMode();
2271         this.$blockScrolling += 1;
2272         this.onCursorChange();
2273         this.$blockScrolling -= 1;
2275         this.onScrollTopChange();
2276         this.onScrollLeftChange();
2277         this.onSelectionChange();
2278         this.onChangeFrontMarker();
2279         this.onChangeBackMarker();
2280         this.onChangeBreakpoint();
2281         this.onChangeAnnotation();
2282         this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
2283         this.renderer.updateFull();
2285         this._emit("changeSession", {
2286             session: session,
2287             oldSession: oldSession
2288         });
2289     };
2290     this.getSession = function() {
2291         return this.session;
2292     };
2293     this.setValue = function(val, cursorPos) {
2294         this.session.doc.setValue(val);
2296         if (!cursorPos)
2297             this.selectAll();
2298         else if (cursorPos == 1)
2299             this.navigateFileEnd();
2300         else if (cursorPos == -1)
2301             this.navigateFileStart();
2303         return val;
2304     };
2305     this.getValue = function() {
2306         return this.session.getValue();
2307     };
2308     this.getSelection = function() {
2309         return this.selection;
2310     };
2311     this.resize = function(force) {
2312         this.renderer.onResize(force);
2313     };
2314     this.setTheme = function(theme) {
2315         this.renderer.setTheme(theme);
2316     };
2317     this.getTheme = function() {
2318         return this.renderer.getTheme();
2319     };
2320     this.setStyle = function(style) {
2321         this.renderer.setStyle(style);
2322     };
2323     this.unsetStyle = function(style) {
2324         this.renderer.unsetStyle(style);
2325     };
2326     this.setFontSize = function(size) {
2327         this.container.style.fontSize = size;
2328         this.renderer.updateFontSize();
2329     };
2330     this.$highlightBrackets = function() {
2331         if (this.session.$bracketHighlight) {
2332             this.session.removeMarker(this.session.$bracketHighlight);
2333             this.session.$bracketHighlight = null;
2334         }
2336         if (this.$highlightPending) {
2337             return;
2338         }
2340         // perform highlight async to not block the browser during navigation
2341         var self = this;
2342         this.$highlightPending = true;
2343         setTimeout(function() {
2344             self.$highlightPending = false;
2346             var pos = self.session.findMatchingBracket(self.getCursorPosition());
2347             if (pos) {
2348                 var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
2349                 self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
2350             }
2351         }, 10);
2352     };
2353     this.focus = function() {
2354         // Safari needs the timeout
2355         // iOS and Firefox need it called immediately
2356         // to be on the save side we do both
2357         var _self = this;
2358         setTimeout(function() {
2359             _self.textInput.focus();
2360         });
2361         this.textInput.focus();
2362     };
2363     this.isFocused = function() {
2364         return this.textInput.isFocused();
2365     };
2366     this.blur = function() {
2367         this.textInput.blur();
2368     };
2369     this.onFocus = function() {
2370         if (this.$isFocused)
2371             return;
2372         this.$isFocused = true;
2373         this.renderer.showCursor();
2374         this.renderer.visualizeFocus();
2375         this._emit("focus");
2376     };
2377     this.onBlur = function() {
2378         if (!this.$isFocused)
2379             return;
2380         this.$isFocused = false;
2381         this.renderer.hideCursor();
2382         this.renderer.visualizeBlur();
2383         this._emit("blur");
2384     };
2386     this.$cursorChange = function() {
2387         this.renderer.updateCursor();
2388     };
2389     this.onDocumentChange = function(e) {
2390         var delta = e.data;
2391         var range = delta.range;
2392         var lastRow;
2394         if (range.start.row == range.end.row && delta.action != "insertLines" && delta.action != "removeLines")
2395             lastRow = range.end.row;
2396         else
2397             lastRow = Infinity;
2398         this.renderer.updateLines(range.start.row, lastRow);
2400         this._emit("change", e);
2402         // update cursor because tab characters can influence the cursor position
2403         this.$cursorChange();
2404     };
2406     this.onTokenizerUpdate = function(e) {
2407         var rows = e.data;
2408         this.renderer.updateLines(rows.first, rows.last);
2409     };
2412     this.onScrollTopChange = function() {
2413         this.renderer.scrollToY(this.session.getScrollTop());
2414     };
2415     
2416     this.onScrollLeftChange = function() {
2417         this.renderer.scrollToX(this.session.getScrollLeft());
2418     };
2419     this.onCursorChange = function() {
2420         this.$cursorChange();
2422         if (!this.$blockScrolling) {
2423             this.renderer.scrollCursorIntoView();
2424         }
2426         this.$highlightBrackets();
2427         this.$updateHighlightActiveLine();
2428         this._emit("changeSelection");
2429     };
2430     this.$updateHighlightActiveLine = function() {
2431         var session = this.getSession();
2433         if (session.$highlightLineMarker)
2434             session.removeMarker(session.$highlightLineMarker);
2436         session.$highlightLineMarker = null;
2438         if (this.$highlightActiveLine) {
2439             var cursor = this.getCursorPosition();
2440             var foldLine = this.session.getFoldLine(cursor.row);
2442             if ((this.getSelectionStyle() != "line" || !this.selection.isMultiLine())) {
2443                 var range;
2444                 if (foldLine) {
2445                     range = new Range(foldLine.start.row, 0, foldLine.end.row + 1, 0);
2446                 } else {
2447                     range = new Range(cursor.row, 0, cursor.row+1, 0);
2448                 }
2449                 session.$highlightLineMarker = session.addMarker(range, "ace_active_line", "background");
2450             }
2451         }
2452     };
2455     this.onSelectionChange = function(e) {
2456         var session = this.session;
2458         if (session.$selectionMarker) {
2459             session.removeMarker(session.$selectionMarker);
2460         }
2461         session.$selectionMarker = null;
2463         if (!this.selection.isEmpty()) {
2464             var range = this.selection.getRange();
2465             var style = this.getSelectionStyle();
2466             session.$selectionMarker = session.addMarker(range, "ace_selection", style);
2467         } else {
2468             this.$updateHighlightActiveLine();
2469         }
2471         var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
2472         this.session.highlight(re);
2473         
2474         this._emit("changeSelection");
2475     };
2477     this.$getSelectionHighLightRegexp = function() {
2478         var session = this.session;
2480         var selection = this.getSelectionRange();
2481         if (selection.isEmpty() || selection.isMultiLine())
2482             return;
2484         var startOuter = selection.start.column - 1;
2485         var endOuter = selection.end.column + 1;
2486         var line = session.getLine(selection.start.row);
2487         var lineCols = line.length;
2488         var needle = line.substring(Math.max(startOuter, 0),
2489                                     Math.min(endOuter, lineCols));
2491         // Make sure the outer characters are not part of the word.
2492         if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
2493             (endOuter <= lineCols && /[\w\d]$/.test(needle)))
2494             return;
2496         needle = line.substring(selection.start.column, selection.end.column);
2497         if (!/^[\w\d]+$/.test(needle))
2498             return;
2500         var re = this.$search.$assembleRegExp({
2501             wholeWord: true,
2502             caseSensitive: true,
2503             needle: needle
2504         });
2506         return re;
2507     };
2510     this.onChangeFrontMarker = function() {
2511         this.renderer.updateFrontMarkers();
2512     };
2514     this.onChangeBackMarker = function() {
2515         this.renderer.updateBackMarkers();
2516     };
2519     this.onChangeBreakpoint = function() {
2520         this.renderer.updateBreakpoints();
2521     };
2523     this.onChangeAnnotation = function() {
2524         this.renderer.setAnnotations(this.session.getAnnotations());
2525     };
2528     this.onChangeMode = function() {
2529         this.renderer.updateText();
2530     };
2533     this.onChangeWrapLimit = function() {
2534         this.renderer.updateFull();
2535     };
2537     this.onChangeWrapMode = function() {
2538         this.renderer.onResize(true);
2539     };
2542     this.onChangeFold = function() {
2543         // Update the active line marker as due to folding changes the current
2544         // line range on the screen might have changed.
2545         this.$updateHighlightActiveLine();
2546         // TODO: This might be too much updating. Okay for now.
2547         this.renderer.updateFull();
2548     };
2549     /**
2550      * Editor@copy(text)
2551      * - text (String): The copied text
2552      *
2553      * Emitted when text is copied.
2554      **/
2555     this.getCopyText = function() {
2556         var text = "";
2557         if (!this.selection.isEmpty())
2558             text = this.session.getTextRange(this.getSelectionRange());
2560         this._emit("copy", text);
2561         return text;
2562     };
2563     this.onCopy = function() {
2564         this.commands.exec("copy", this);
2565     };
2566     this.onCut = function() {
2567         this.commands.exec("cut", this);
2568     };
2569     /**
2570      * Editor@paste(text)
2571      * - text (String): The pasted text
2572      *
2573      * Emitted when text is pasted.
2574      **/
2575     this.onPaste = function(text) {
2576         // todo this should change when paste becomes a command
2577         if (this.$readOnly) 
2578             return;
2579         this._emit("paste", text);
2580         this.insert(text);
2581     };
2582     this.insert = function(text) {
2583         var session = this.session;
2584         var mode = session.getMode();
2586         var cursor = this.getCursorPosition();
2588         if (this.getBehavioursEnabled()) {
2589             // Get a transform if the current mode wants one.
2590             var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
2591             if (transform)
2592                 text = transform.text;
2593         }
2595         text = text.replace("\t", this.session.getTabString());
2597         // remove selected text
2598         if (!this.selection.isEmpty()) {
2599             cursor = this.session.remove(this.getSelectionRange());
2600             this.clearSelection();
2601         }
2602         else if (this.session.getOverwrite()) {
2603             var range = new Range.fromPoints(cursor, cursor);
2604             range.end.column += text.length;
2605             this.session.remove(range);
2606         }
2608         this.clearSelection();
2610         var start = cursor.column;
2611         var lineState = session.getState(cursor.row);
2612         var shouldOutdent = mode.checkOutdent(lineState, session.getLine(cursor.row), text);
2613         var line = session.getLine(cursor.row);
2614         var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
2615         var end = session.insert(cursor, text);
2617         if (transform && transform.selection) {
2618             if (transform.selection.length == 2) { // Transform relative to the current column
2619                 this.selection.setSelectionRange(
2620                     new Range(cursor.row, start + transform.selection[0],
2621                               cursor.row, start + transform.selection[1]));
2622             } else { // Transform relative to the current row.
2623                 this.selection.setSelectionRange(
2624                     new Range(cursor.row + transform.selection[0],
2625                               transform.selection[1],
2626                               cursor.row + transform.selection[2],
2627                               transform.selection[3]));
2628             }
2629         }
2631         var lineState = session.getState(cursor.row);
2633         // TODO disabled multiline auto indent
2634         // possibly doing the indent before inserting the text
2635         // if (cursor.row !== end.row) {
2636         if (session.getDocument().isNewLine(text)) {
2637             this.moveCursorTo(cursor.row+1, 0);
2639             var size = session.getTabSize();
2640             var minIndent = Number.MAX_VALUE;
2642             for (var row = cursor.row + 1; row <= end.row; ++row) {
2643                 var indent = 0;
2645                 line = session.getLine(row);
2646                 for (var i = 0; i < line.length; ++i)
2647                     if (line.charAt(i) == '\t')
2648                         indent += size;
2649                     else if (line.charAt(i) == ' ')
2650                         indent += 1;
2651                     else
2652                         break;
2653                 if (/[^\s]/.test(line))
2654                     minIndent = Math.min(indent, minIndent);
2655             }
2657             for (var row = cursor.row + 1; row <= end.row; ++row) {
2658                 var outdent = minIndent;
2660                 line = session.getLine(row);
2661                 for (var i = 0; i < line.length && outdent > 0; ++i)
2662                     if (line.charAt(i) == '\t')
2663                         outdent -= size;
2664                     else if (line.charAt(i) == ' ')
2665                         outdent -= 1;
2666                 session.remove(new Range(row, 0, row, i));
2667             }
2668             session.indentRows(cursor.row + 1, end.row, lineIndent);
2669         }
2670         if (shouldOutdent)
2671             mode.autoOutdent(lineState, session, cursor.row);
2672     };
2674     this.onTextInput = function(text) {
2675         this.keyBinding.onTextInput(text);
2676     };
2678     this.onCommandKey = function(e, hashId, keyCode) {
2679         this.keyBinding.onCommandKey(e, hashId, keyCode);
2680     };
2681     this.setOverwrite = function(overwrite) {
2682         this.session.setOverwrite(overwrite);
2683     };
2684     this.getOverwrite = function() {
2685         return this.session.getOverwrite();
2686     };
2687     this.toggleOverwrite = function() {
2688         this.session.toggleOverwrite();
2689     };
2690     this.setScrollSpeed = function(speed) {
2691         this.$mouseHandler.setScrollSpeed(speed);
2692     };
2693     this.getScrollSpeed = function() {
2694         return this.$mouseHandler.getScrollSpeed();
2695     };
2696     this.setDragDelay = function(dragDelay) {
2697         this.$mouseHandler.setDragDelay(dragDelay);
2698     };
2699     this.getDragDelay = function() {
2700         return this.$mouseHandler.getDragDelay();
2701     };
2703     this.$selectionStyle = "line";
2704     /**
2705      * Editor@changeSelectionStyle(data) 
2706      * - data (Object): Contains one property, `data`, which indicates the new selection style
2707      *
2708      * Emitted when the selection style changes, via [[Editor.setSelectionStyle]].
2709      * 
2710      **/
2711     this.setSelectionStyle = function(style) {
2712         if (this.$selectionStyle == style) return;
2714         this.$selectionStyle = style;
2715         this.onSelectionChange();
2716         this._emit("changeSelectionStyle", {data: style});
2717     };
2718     this.getSelectionStyle = function() {
2719         return this.$selectionStyle;
2720     };
2722     this.$highlightActiveLine = true;
2723     this.setHighlightActiveLine = function(shouldHighlight) {
2724         if (this.$highlightActiveLine == shouldHighlight)
2725             return;
2727         this.$highlightActiveLine = shouldHighlight;
2728         this.$updateHighlightActiveLine();
2729     };
2730     this.getHighlightActiveLine = function() {
2731         return this.$highlightActiveLine;
2732     };
2734     this.$highlightGutterLine = true;
2735     this.setHighlightGutterLine = function(shouldHighlight) {
2736         if (this.$highlightGutterLine == shouldHighlight)
2737             return;
2739         this.renderer.setHighlightGutterLine(shouldHighlight);
2740         this.$highlightGutterLine = shouldHighlight;
2741     };
2743     this.getHighlightGutterLine = function() {
2744         return this.$highlightGutterLine;
2745     };
2747     this.$highlightSelectedWord = true;
2748     this.setHighlightSelectedWord = function(shouldHighlight) {
2749         if (this.$highlightSelectedWord == shouldHighlight)
2750             return;
2752         this.$highlightSelectedWord = shouldHighlight;
2753         this.$onSelectionChange();
2754     };
2755     this.getHighlightSelectedWord = function() {
2756         return this.$highlightSelectedWord;
2757     };
2759     this.setAnimatedScroll = function(shouldAnimate){
2760         this.renderer.setAnimatedScroll(shouldAnimate);
2761     };
2763     this.getAnimatedScroll = function(){
2764         return this.renderer.getAnimatedScroll();
2765     };
2766     this.setShowInvisibles = function(showInvisibles) {
2767         this.renderer.setShowInvisibles(showInvisibles);
2768     };
2769     this.getShowInvisibles = function() {
2770         return this.renderer.getShowInvisibles();
2771     };
2773     this.setDisplayIndentGuides = function(display) {
2774         this.renderer.setDisplayIndentGuides(display);
2775     };
2777     this.getDisplayIndentGuides = function() {
2778         return this.renderer.getDisplayIndentGuides();
2779     };
2780     this.setShowPrintMargin = function(showPrintMargin) {
2781         this.renderer.setShowPrintMargin(showPrintMargin);
2782     };
2783     this.getShowPrintMargin = function() {
2784         return this.renderer.getShowPrintMargin();
2785     };
2786     this.setPrintMarginColumn = function(showPrintMargin) {
2787         this.renderer.setPrintMarginColumn(showPrintMargin);
2788     };
2789     this.getPrintMarginColumn = function() {
2790         return this.renderer.getPrintMarginColumn();
2791     };
2793     this.$readOnly = false;
2794     this.setReadOnly = function(readOnly) {
2795         this.$readOnly = readOnly;
2796     };
2797     this.getReadOnly = function() {
2798         return this.$readOnly;
2799     };
2801     this.$modeBehaviours = true;
2802     this.setBehavioursEnabled = function (enabled) {
2803         this.$modeBehaviours = enabled;
2804     };
2805     this.getBehavioursEnabled = function () {
2806         return this.$modeBehaviours;
2807     };
2808     this.setShowFoldWidgets = function(show) {
2809         var gutter = this.renderer.$gutterLayer;
2810         if (gutter.getShowFoldWidgets() == show)
2811             return;
2813         this.renderer.$gutterLayer.setShowFoldWidgets(show);
2814         this.$showFoldWidgets = show;
2815         this.renderer.updateFull();
2816     };
2817     this.getShowFoldWidgets = function() {
2818         return this.renderer.$gutterLayer.getShowFoldWidgets();
2819     };
2821     this.setFadeFoldWidgets = function(show) {
2822         this.renderer.setFadeFoldWidgets(show);
2823     };
2825     this.getFadeFoldWidgets = function() {
2826         return this.renderer.getFadeFoldWidgets();
2827     };
2828     this.remove = function(dir) {
2829         if (this.selection.isEmpty()){
2830             if (dir == "left")
2831                 this.selection.selectLeft();
2832             else
2833                 this.selection.selectRight();
2834         }
2836         var range = this.getSelectionRange();
2837         if (this.getBehavioursEnabled()) {
2838             var session = this.session;
2839             var state = session.getState(range.start.row);
2840             var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
2841             if (new_range)
2842                 range = new_range;
2843         }
2845         this.session.remove(range);
2846         this.clearSelection();
2847     };
2848     this.removeWordRight = function() {
2849         if (this.selection.isEmpty())
2850             this.selection.selectWordRight();
2852         this.session.remove(this.getSelectionRange());
2853         this.clearSelection();
2854     };
2855     this.removeWordLeft = function() {
2856         if (this.selection.isEmpty())
2857             this.selection.selectWordLeft();
2859         this.session.remove(this.getSelectionRange());
2860         this.clearSelection();
2861     };
2862     this.removeToLineStart = function() {
2863         if (this.selection.isEmpty())
2864             this.selection.selectLineStart();
2866         this.session.remove(this.getSelectionRange());
2867         this.clearSelection();
2868     };
2869     this.removeToLineEnd = function() {
2870         if (this.selection.isEmpty())
2871             this.selection.selectLineEnd();
2873         var range = this.getSelectionRange();
2874         if (range.start.column == range.end.column && range.start.row == range.end.row) {
2875             range.end.column = 0;
2876             range.end.row++;
2877         }
2879         this.session.remove(range);
2880         this.clearSelection();
2881     };
2882     this.splitLine = function() {
2883         if (!this.selection.isEmpty()) {
2884             this.session.remove(this.getSelectionRange());
2885             this.clearSelection();
2886         }
2888         var cursor = this.getCursorPosition();
2889         this.insert("\n");
2890         this.moveCursorToPosition(cursor);
2891     };
2892     this.transposeLetters = function() {
2893         if (!this.selection.isEmpty()) {
2894             return;
2895         }
2897         var cursor = this.getCursorPosition();
2898         var column = cursor.column;
2899         if (column === 0)
2900             return;
2902         var line = this.session.getLine(cursor.row);
2903         var swap, range;
2904         if (column < line.length) {
2905             swap = line.charAt(column) + line.charAt(column-1);
2906             range = new Range(cursor.row, column-1, cursor.row, column+1);
2907         }
2908         else {
2909             swap = line.charAt(column-1) + line.charAt(column-2);
2910             range = new Range(cursor.row, column-2, cursor.row, column);
2911         }
2912         this.session.replace(range, swap);
2913     };
2914     this.toLowerCase = function() {
2915         var originalRange = this.getSelectionRange();
2916         if (this.selection.isEmpty()) {
2917             this.selection.selectWord();
2918         }
2920         var range = this.getSelectionRange();
2921         var text = this.session.getTextRange(range);
2922         this.session.replace(range, text.toLowerCase());
2923         this.selection.setSelectionRange(originalRange);
2924     };
2925     this.toUpperCase = function() {
2926         var originalRange = this.getSelectionRange();
2927         if (this.selection.isEmpty()) {
2928             this.selection.selectWord();
2929         }
2931         var range = this.getSelectionRange();
2932         var text = this.session.getTextRange(range);
2933         this.session.replace(range, text.toUpperCase());
2934         this.selection.setSelectionRange(originalRange);
2935     };
2936     this.indent = function() {
2937         var session = this.session;
2938         var range = this.getSelectionRange();
2940         if (range.start.row < range.end.row || range.start.column < range.end.column) {
2941             var rows = this.$getSelectedRows();
2942             session.indentRows(rows.first, rows.last, "\t");
2943         } else {
2944             var indentString;
2946             if (this.session.getUseSoftTabs()) {
2947                 var size        = session.getTabSize(),
2948                     position    = this.getCursorPosition(),
2949                     column      = session.documentToScreenColumn(position.row, position.column),
2950                     count       = (size - column % size);
2952                 indentString = lang.stringRepeat(" ", count);
2953             } else
2954                 indentString = "\t";
2955             return this.insert(indentString);
2956         }
2957     };
2958     this.blockOutdent = function() {
2959         var selection = this.session.getSelection();
2960         this.session.outdentRows(selection.getRange());
2961     };
2962     this.toggleCommentLines = function() {
2963         var state = this.session.getState(this.getCursorPosition().row);
2964         var rows = this.$getSelectedRows();
2965         this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
2966     };
2967     this.removeLines = function() {
2968         var rows = this.$getSelectedRows();
2969         var range;
2970         if (rows.first === 0 || rows.last+1 < this.session.getLength())
2971             range = new Range(rows.first, 0, rows.last+1, 0);
2972         else
2973             range = new Range(
2974                 rows.first-1, this.session.getLine(rows.first-1).length,
2975                 rows.last, this.session.getLine(rows.last).length
2976             );
2977         this.session.remove(range);
2978         this.clearSelection();
2979     };
2981     this.duplicateSelection = function() {
2982         var sel = this.selection;
2983                 var doc = this.session;
2984                 var range = sel.getRange();
2985                 if (range.isEmpty()) {
2986                         var row = range.start.row;
2987                         doc.duplicateLines(row, row);
2988                 } else {
2989                         var reverse = sel.isBackwards()
2990                         var point = sel.isBackwards() ? range.start : range.end;
2991                         var endPoint = doc.insert(point, doc.getTextRange(range), false);
2992                         range.start = point;
2993                         range.end = endPoint;
2994                         
2995                         sel.setSelectionRange(range, reverse)
2996                 }
2997     };
2998     this.moveLinesDown = function() {
2999         this.$moveLines(function(firstRow, lastRow) {
3000             return this.session.moveLinesDown(firstRow, lastRow);
3001         });
3002     };
3003     this.moveLinesUp = function() {
3004         this.$moveLines(function(firstRow, lastRow) {
3005             return this.session.moveLinesUp(firstRow, lastRow);
3006         });
3007     };
3008     this.moveText = function(range, toPosition) {
3009         if (this.$readOnly)
3010             return null;
3012         return this.session.moveText(range, toPosition);
3013     };
3014     this.copyLinesUp = function() {
3015         this.$moveLines(function(firstRow, lastRow) {
3016             this.session.duplicateLines(firstRow, lastRow);
3017             return 0;
3018         });
3019     };
3020     this.copyLinesDown = function() {
3021         this.$moveLines(function(firstRow, lastRow) {
3022             return this.session.duplicateLines(firstRow, lastRow);
3023         });
3024     };
3025     this.$moveLines = function(mover) {
3026         var rows = this.$getSelectedRows();
3027         var selection = this.selection;
3028         if (!selection.isMultiLine()) {
3029             var range = selection.getRange();
3030             var reverse = selection.isBackwards();
3031         }
3033         var linesMoved = mover.call(this, rows.first, rows.last);
3035         if (range) {
3036             range.start.row += linesMoved;
3037             range.end.row += linesMoved;
3038             selection.setSelectionRange(range, reverse);
3039         }
3040         else {
3041             selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
3042             selection.$moveSelection(function() {
3043                 selection.moveCursorTo(rows.first+linesMoved, 0);
3044             });
3045         }
3046     };
3047     this.$getSelectedRows = function() {
3048         var range = this.getSelectionRange().collapseRows();
3050         return {
3051             first: range.start.row,
3052             last: range.end.row
3053         };
3054     };
3056     this.onCompositionStart = function(text) {
3057         this.renderer.showComposition(this.getCursorPosition());
3058     };
3060     this.onCompositionUpdate = function(text) {
3061         this.renderer.setCompositionText(text);
3062     };
3064     this.onCompositionEnd = function() {
3065         this.renderer.hideComposition();
3066     };
3067     this.getFirstVisibleRow = function() {
3068         return this.renderer.getFirstVisibleRow();
3069     };
3070     this.getLastVisibleRow = function() {
3071         return this.renderer.getLastVisibleRow();
3072     };
3073     this.isRowVisible = function(row) {
3074         return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
3075     };
3076     this.isRowFullyVisible = function(row) {
3077         return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
3078     };
3079     this.$getVisibleRowCount = function() {
3080         return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
3081     };
3083     this.$moveByPage = function(dir, select) {
3084         var renderer = this.renderer;
3085         var config = this.renderer.layerConfig;
3086         var rows = dir * Math.floor(config.height / config.lineHeight);
3088         this.$blockScrolling++;
3089         if (select == true) {
3090             this.selection.$moveSelection(function(){
3091                 this.moveCursorBy(rows, 0);
3092             });
3093         } else if (select == false) {
3094             this.selection.moveCursorBy(rows, 0);
3095             this.selection.clearSelection();
3096         }
3097         this.$blockScrolling--;
3099         var scrollTop = renderer.scrollTop;
3101         renderer.scrollBy(0, rows * config.lineHeight);
3102         if (select != null)
3103             renderer.scrollCursorIntoView(null, 0.5);
3105         renderer.animateScrolling(scrollTop);
3106     };
3107     this.selectPageDown = function() {
3108         this.$moveByPage(1, true);
3109     };
3110     this.selectPageUp = function() {
3111         this.$moveByPage(-1, true);
3112     };
3113     this.gotoPageDown = function() {
3114        this.$moveByPage(1, false);
3115     };
3116     this.gotoPageUp = function() {
3117         this.$moveByPage(-1, false);
3118     };
3119     this.scrollPageDown = function() {
3120         this.$moveByPage(1);
3121     };
3122     this.scrollPageUp = function() {
3123         this.$moveByPage(-1);
3124     };
3125     this.scrollToRow = function(row) {
3126         this.renderer.scrollToRow(row);
3127     };
3128     this.scrollToLine = function(line, center, animate, callback) {
3129         this.renderer.scrollToLine(line, center, animate, callback);
3130     };
3131     this.centerSelection = function() {
3132         var range = this.getSelectionRange();
3133         var pos = {
3134             row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
3135             column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
3136         }
3137         this.renderer.alignCursor(pos, 0.5);
3138     };
3139     this.getCursorPosition = function() {
3140         return this.selection.getCursor();
3141     };
3142     this.getCursorPositionScreen = function() {
3143         return this.session.documentToScreenPosition(this.getCursorPosition());
3144     };
3145     this.getSelectionRange = function() {
3146         return this.selection.getRange();
3147     };
3148     this.selectAll = function() {
3149         this.$blockScrolling += 1;
3150         this.selection.selectAll();
3151         this.$blockScrolling -= 1;
3152     };
3153     this.clearSelection = function() {
3154         this.selection.clearSelection();
3155     };
3156     this.moveCursorTo = function(row, column) {
3157         this.selection.moveCursorTo(row, column);
3158     };
3159     this.moveCursorToPosition = function(pos) {
3160         this.selection.moveCursorToPosition(pos);
3161     };
3162     this.jumpToMatching = function(select) {
3163         var cursor = this.getCursorPosition();
3165         var range = this.session.getBracketRange(cursor);
3166         if (!range) {
3167             range = this.find({
3168                 needle: /[{}()\[\]]/g,
3169                 preventScroll:true,
3170                 start: {row: cursor.row, column: cursor.column - 1}
3171             });
3172             if (!range)
3173                 return;
3174             var pos = range.start;
3175             if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
3176                 range = this.session.getBracketRange(pos);
3177         }
3178         
3179         pos = range && range.cursor || pos;
3180         if (pos) {
3181             if (select) {
3182                 if (range && range.isEqual(this.getSelectionRange()))
3183                     this.clearSelection();
3184                 else
3185                     this.selection.selectTo(pos.row, pos.column);
3186             } else {
3187                 this.clearSelection();
3188                 this.moveCursorTo(pos.row, pos.column);
3189             }
3190         }
3191     };
3192     this.gotoLine = function(lineNumber, column, animate) {
3193         this.selection.clearSelection();
3194         this.session.unfold({row: lineNumber - 1, column: column || 0});
3196         this.$blockScrolling += 1;
3197         this.moveCursorTo(lineNumber - 1, column || 0);
3198         this.$blockScrolling -= 1;
3200         if (!this.isRowFullyVisible(lineNumber - 1))
3201             this.scrollToLine(lineNumber - 1, true, animate);
3202     };
3203     this.navigateTo = function(row, column) {
3204         this.clearSelection();
3205         this.moveCursorTo(row, column);
3206     };
3207     this.navigateUp = function(times) {
3208         this.selection.clearSelection();
3209         times = times || 1;
3210         this.selection.moveCursorBy(-times, 0);
3211     };
3212     this.navigateDown = function(times) {
3213         this.selection.clearSelection();
3214         times = times || 1;
3215         this.selection.moveCursorBy(times, 0);
3216     };
3217     this.navigateLeft = function(times) {
3218         if (!this.selection.isEmpty()) {
3219             var selectionStart = this.getSelectionRange().start;
3220             this.moveCursorToPosition(selectionStart);
3221         }
3222         else {
3223             times = times || 1;
3224             while (times--) {
3225                 this.selection.moveCursorLeft();
3226             }
3227         }
3228         this.clearSelection();
3229     };
3230     this.navigateRight = function(times) {
3231         if (!this.selection.isEmpty()) {
3232             var selectionEnd = this.getSelectionRange().end;
3233             this.moveCursorToPosition(selectionEnd);
3234         }
3235         else {
3236             times = times || 1;
3237             while (times--) {
3238                 this.selection.moveCursorRight();
3239             }
3240         }
3241         this.clearSelection();
3242     };
3243     this.navigateLineStart = function() {
3244         this.selection.moveCursorLineStart();
3245         this.clearSelection();
3246     };
3247     this.navigateLineEnd = function() {
3248         this.selection.moveCursorLineEnd();
3249         this.clearSelection();
3250     };
3251     this.navigateFileEnd = function() {
3252         var scrollTop = this.renderer.scrollTop;
3253         this.selection.moveCursorFileEnd();
3254         this.clearSelection();
3255         this.renderer.animateScrolling(scrollTop);
3256     };
3257     this.navigateFileStart = function() {
3258         var scrollTop = this.renderer.scrollTop;
3259         this.selection.moveCursorFileStart();
3260         this.clearSelection();
3261         this.renderer.animateScrolling(scrollTop);
3262     };
3263     this.navigateWordRight = function() {
3264         this.selection.moveCursorWordRight();
3265         this.clearSelection();
3266     };
3267     this.navigateWordLeft = function() {
3268         this.selection.moveCursorWordLeft();
3269         this.clearSelection();
3270     };
3271     this.replace = function(replacement, options) {
3272         if (options)
3273             this.$search.set(options);
3275         var range = this.$search.find(this.session);
3276         var replaced = 0;
3277         if (!range)
3278             return replaced;
3280         if (this.$tryReplace(range, replacement)) {
3281             replaced = 1;
3282         }
3283         if (range !== null) {
3284             this.selection.setSelectionRange(range);
3285             this.renderer.scrollSelectionIntoView(range.start, range.end);
3286         }
3288         return replaced;
3289     };
3290     this.replaceAll = function(replacement, options) {
3291         if (options) {
3292             this.$search.set(options);
3293         }
3295         var ranges = this.$search.findAll(this.session);
3296         var replaced = 0;
3297         if (!ranges.length)
3298             return replaced;
3300         this.$blockScrolling += 1;
3302         var selection = this.getSelectionRange();
3303         this.clearSelection();
3304         this.selection.moveCursorTo(0, 0);
3306         for (var i = ranges.length - 1; i >= 0; --i) {
3307             if(this.$tryReplace(ranges[i], replacement)) {
3308                 replaced++;
3309             }
3310         }
3312         this.selection.setSelectionRange(selection);
3313         this.$blockScrolling -= 1;
3315         return replaced;
3316     };
3318     this.$tryReplace = function(range, replacement) {
3319         var input = this.session.getTextRange(range);
3320         replacement = this.$search.replace(input, replacement);
3321         if (replacement !== null) {
3322             range.end = this.session.replace(range, replacement);
3323             return range;
3324         } else {
3325             return null;
3326         }
3327     };
3328     this.getLastSearchOptions = function() {
3329         return this.$search.getOptions();
3330     };
3331     this.find = function(needle, options, animate) {
3332         if (!options)
3333             options = {};
3335         if (typeof needle == "string" || needle instanceof RegExp)
3336             options.needle = needle;
3337         else if (typeof needle == "object")
3338             oop.mixin(options, needle);
3340         var range = this.selection.getRange();
3341         if (options.needle == null) {
3342             needle = this.session.getTextRange(range)
3343                 || this.$search.$options.needle;
3344             if (!needle) {
3345                 range = this.session.getWordRange(range.start.row, range.start.column);
3346                 needle = this.session.getTextRange(range);
3347             }
3348             this.$search.set({needle: needle});
3349         }
3351         this.$search.set(options);
3352         if (!options.start)
3353             this.$search.set({start: range});
3355         var newRange = this.$search.find(this.session);
3356         if (options.preventScroll)
3357             return newRange;
3358         if (newRange) {
3359             this.revealRange(newRange, animate);
3360             return newRange;
3361         }
3362         // clear selection if nothing is found
3363         if (options.backwards)
3364             range.start = range.end;
3365         else
3366             range.end = range.start;
3367         this.selection.setRange(range);
3368     };
3369     this.findNext = function(options, animate) {
3370         this.find({skipCurrent: true, backwards: false}, options, animate);
3371     };
3372     this.findPrevious = function(options, animate) {
3373         this.find(options, {skipCurrent: true, backwards: true}, animate);
3374     };
3376     this.revealRange = function(range, animate) {
3377         this.$blockScrolling += 1;
3378         this.session.unfold(range);
3379         this.selection.setSelectionRange(range);
3380         this.$blockScrolling -= 1;
3382         var scrollTop = this.renderer.scrollTop;
3383         this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
3384         if (animate != false)
3385             this.renderer.animateScrolling(scrollTop);
3386     };
3387     this.undo = function() {
3388         this.$blockScrolling++;
3389         this.session.getUndoManager().undo();
3390         this.$blockScrolling--;
3391         this.renderer.scrollCursorIntoView(null, 0.5);
3392     };
3393     this.redo = function() {
3394         this.$blockScrolling++;
3395         this.session.getUndoManager().redo();
3396         this.$blockScrolling--;
3397         this.renderer.scrollCursorIntoView(null, 0.5);
3398     };
3399     this.destroy = function() {
3400         this.renderer.destroy();
3401     };
3403 }).call(Editor.prototype);
3406 exports.Editor = Editor;
3409 define('ace/lib/lang', ['require', 'exports', 'module' ], function(require, exports, module) {
3412 exports.stringReverse = function(string) {
3413     return string.split("").reverse().join("");
3416 exports.stringRepeat = function (string, count) {
3417      return new Array(count + 1).join(string);
3420 var trimBeginRegexp = /^\s\s*/;
3421 var trimEndRegexp = /\s\s*$/;
3423 exports.stringTrimLeft = function (string) {
3424     return string.replace(trimBeginRegexp, '');
3427 exports.stringTrimRight = function (string) {
3428     return string.replace(trimEndRegexp, '');
3431 exports.copyObject = function(obj) {
3432     var copy = {};
3433     for (var key in obj) {
3434         copy[key] = obj[key];
3435     }
3436     return copy;
3439 exports.copyArray = function(array){
3440     var copy = [];
3441     for (var i=0, l=array.length; i<l; i++) {
3442         if (array[i] && typeof array[i] == "object")
3443             copy[i] = this.copyObject( array[i] );
3444         else 
3445             copy[i] = array[i];
3446     }
3447     return copy;
3450 exports.deepCopy = function (obj) {
3451     if (typeof obj != "object") {
3452         return obj;
3453     }
3454     
3455     var copy = obj.constructor();
3456     for (var key in obj) {
3457         if (typeof obj[key] == "object") {
3458             copy[key] = this.deepCopy(obj[key]);
3459         } else {
3460             copy[key] = obj[key];
3461         }
3462     }
3463     return copy;
3466 exports.arrayToMap = function(arr) {
3467     var map = {};
3468     for (var i=0; i<arr.length; i++) {
3469         map[arr[i]] = 1;
3470     }
3471     return map;
3475 exports.createMap = function(props) {
3476     var map = Object.create(null);
3477     for (var i in props) {
3478         map[i] = props[i];
3479     }
3480     return map;
3482 exports.arrayRemove = function(array, value) {
3483   for (var i = 0; i <= array.length; i++) {
3484     if (value === array[i]) {
3485       array.splice(i, 1);
3486     }
3487   }
3490 exports.escapeRegExp = function(str) {
3491     return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
3494 exports.getMatchOffsets = function(string, regExp) {
3495     var matches = [];
3497     string.replace(regExp, function(str) {
3498         matches.push({
3499             offset: arguments[arguments.length-2],
3500             length: str.length
3501         });
3502     });
3504     return matches;
3508 exports.deferredCall = function(fcn) {
3510     var timer = null;
3511     var callback = function() {
3512         timer = null;
3513         fcn();
3514     };
3516     var deferred = function(timeout) {
3517         deferred.cancel();
3518         timer = setTimeout(callback, timeout || 0);
3519         return deferred;
3520     };
3522     deferred.schedule = deferred;
3524     deferred.call = function() {
3525         this.cancel();
3526         fcn();
3527         return deferred;
3528     };
3530     deferred.cancel = function() {
3531         clearTimeout(timer);
3532         timer = null;
3533         return deferred;
3534     };
3536     return deferred;
3541 define('ace/keyboard/textinput', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/lib/useragent', 'ace/lib/dom'], function(require, exports, module) {
3544 var event = require("../lib/event");
3545 var useragent = require("../lib/useragent");
3546 var dom = require("../lib/dom");
3548 var TextInput = function(parentNode, host) {
3549     var text = dom.createElement("textarea");
3550     if (useragent.isTouchPad)
3551         text.setAttribute("x-palm-disable-auto-cap", true);
3553     text.setAttribute("wrap", "off");
3555     text.style.top = "-2em";
3556     parentNode.insertBefore(text, parentNode.firstChild);
3558     var PLACEHOLDER = useragent.isIE ? "\x01" : "\x00";
3559     reset(true);
3560     if (isFocused())
3561         host.onFocus();
3563     var inCompostion = false;
3564     var copied = false;
3565     var pasted = false;
3566     var tempStyle = '';
3568     function reset(full) {
3569         try {
3570             if (full) {
3571                 text.value = PLACEHOLDER;
3572                 text.selectionStart = 0;
3573                 text.selectionEnd = 1;
3574             } else 
3575                 text.select();
3576         } catch (e) {}
3577     }
3579     function sendText(valueToSend) {
3580         if (!copied) {
3581             var value = valueToSend || text.value;
3582             if (value) {
3583                 if (value.length > 1) {
3584                     if (value.charAt(0) == PLACEHOLDER)
3585                         value = value.substr(1);
3586                     else if (value.charAt(value.length - 1) == PLACEHOLDER)
3587                         value = value.slice(0, -1);
3588                 }
3590                 if (value && value != PLACEHOLDER) {
3591                     if (pasted)
3592                         host.onPaste(value);
3593                     else
3594                         host.onTextInput(value);
3595                 }
3596             }
3597         }
3599         copied = false;
3600         pasted = false;
3602         // Safari doesn't fire copy events if no text is selected
3603         reset(true);
3604     }
3606     var onTextInput = function(e) {
3607         if (!inCompostion)
3608             sendText(e.data);
3609         setTimeout(function () {
3610             if (!inCompostion)
3611                 reset(true);
3612         }, 0);
3613     };
3615     var onPropertyChange = function(e) {
3616         setTimeout(function() {
3617             if (!inCompostion)
3618                 if(text.value != "") {
3619                     sendText();
3620                 }
3621         }, 0);
3622     };
3624     var onCompositionStart = function(e) {
3625         inCompostion = true;
3626         host.onCompositionStart();
3627         setTimeout(onCompositionUpdate, 0);
3628     };
3630     var onCompositionUpdate = function() {
3631         if (!inCompostion) return;
3632         host.onCompositionUpdate(text.value);
3633     };
3635     var onCompositionEnd = function(e) {
3636         inCompostion = false;
3637         host.onCompositionEnd();
3638     };
3640     var onCopy = function(e) {
3641         copied = true;
3642         var copyText = host.getCopyText();
3643         if(copyText)
3644             text.value = copyText;
3645         else
3646             e.preventDefault();
3647         reset();
3648         setTimeout(function () {
3649             sendText();
3650         }, 0);
3651     };
3653     var onCut = function(e) {
3654         copied = true;
3655         var copyText = host.getCopyText();
3656         if(copyText) {
3657             text.value = copyText;
3658             host.onCut();
3659         } else
3660             e.preventDefault();
3661         reset();
3662         setTimeout(function () {
3663             sendText();
3664         }, 0);
3665     };
3667     event.addCommandKeyListener(text, host.onCommandKey.bind(host));
3668     event.addListener(text, "input", onTextInput);
3669     
3670     if (useragent.isOldIE) {
3671         var keytable = { 13:1, 27:1 };
3672         event.addListener(text, "keyup", function (e) {
3673             if (inCompostion && (!text.value || keytable[e.keyCode]))
3674                 setTimeout(onCompositionEnd, 0);
3675             if ((text.value.charCodeAt(0)|0) < 129) {
3676                 return;
3677             }
3678             inCompostion ? onCompositionUpdate() : onCompositionStart();
3679         });
3680         
3681         event.addListener(text, "propertychange", function() {
3682             if (text.value != PLACEHOLDER)
3683                 setTimeout(sendText, 0);
3684         });
3685     }
3687     event.addListener(text, "paste", function(e) {
3688         // Mark that the next input text comes from past.
3689         pasted = true;
3690         // Some browsers support the event.clipboardData API. Use this to get
3691         // the pasted content which increases speed if pasting a lot of lines.
3692         if (e.clipboardData && e.clipboardData.getData) {
3693             sendText(e.clipboardData.getData("text/plain"));
3694             e.preventDefault();
3695         } 
3696         else {
3697             // If a browser doesn't support any of the things above, use the regular
3698             // method to detect the pasted input.
3699             onPropertyChange();
3700         }
3701     });
3703     if ("onbeforecopy" in text && typeof clipboardData !== "undefined") {
3704         event.addListener(text, "beforecopy", function(e) {
3705             if (tempStyle)
3706                 return; // without this text is copied when contextmenu is shown
3707             var copyText = host.getCopyText();
3708             if (copyText)
3709                 clipboardData.setData("Text", copyText);
3710             else
3711                 e.preventDefault();
3712         });
3713         event.addListener(parentNode, "keydown", function(e) {
3714             if (e.ctrlKey && e.keyCode == 88) {
3715                 var copyText = host.getCopyText();
3716                 if (copyText) {
3717                     clipboardData.setData("Text", copyText);
3718                     host.onCut();
3719                 }
3720                 event.preventDefault(e);
3721             }
3722         });
3723         event.addListener(text, "cut", onCut); // for ie9 context menu
3724     }
3725     else if (useragent.isOpera && !("KeyboardEvent" in window)) {
3726         event.addListener(parentNode, "keydown", function(e) {
3727             if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
3728                 return;
3730             if ((e.keyCode == 88 || e.keyCode == 67)) {
3731                 var copyText = host.getCopyText();
3732                 if (copyText) {
3733                     text.value = copyText;
3734                     text.select();
3735                     if (e.keyCode == 88)
3736                         host.onCut();
3737                 }
3738             }
3739         });
3740     }
3741     else {
3742         event.addListener(text, "copy", onCopy);
3743         event.addListener(text, "cut", onCut);
3744     }
3746     event.addListener(text, "compositionstart", onCompositionStart);
3747     if (useragent.isGecko) {
3748         event.addListener(text, "text", onCompositionUpdate);
3749     }
3750     if (useragent.isWebKit) {
3751         event.addListener(text, "keyup", onCompositionUpdate);
3752     }
3753     event.addListener(text, "compositionend", onCompositionEnd);
3755     event.addListener(text, "blur", function() {
3756         host.onBlur();
3757     });
3759     event.addListener(text, "focus", function() {
3760         host.onFocus();
3761         reset();
3762     });
3764     this.focus = function() {
3765         reset();
3766         text.focus();
3767     };
3769     this.blur = function() {
3770         text.blur();
3771     };
3773     function isFocused() {
3774         return document.activeElement === text;
3775     }
3776     this.isFocused = isFocused;
3778     this.getElement = function() {
3779         return text;
3780     };
3782     this.onContextMenu = function(e) {
3783         if (!tempStyle)
3784             tempStyle = text.style.cssText;
3786         text.style.cssText =
3787             "position:fixed; z-index:100000;" + 
3788             (useragent.isIE ? "background:rgba(0, 0, 0, 0.03); opacity:0.1;" : "") + //"background:rgba(250, 0, 0, 0.3); opacity:1;" +
3789             "left:" + (e.clientX - 2) + "px; top:" + (e.clientY - 2) + "px;";
3791         if (host.selection.isEmpty())
3792             text.value = "";
3793         else
3794             reset(true);
3796         if (e.type != "mousedown")
3797             return;
3799         if (host.renderer.$keepTextAreaAtCursor)
3800             host.renderer.$keepTextAreaAtCursor = null;
3802         // on windows context menu is opened after mouseup
3803         if (useragent.isWin && (useragent.isGecko || useragent.isIE))
3804             event.capture(host.container, function(e) {
3805                 text.style.left = e.clientX - 2 + "px";
3806                 text.style.top = e.clientY - 2 + "px";
3807             }, onContextMenuClose);
3808     };
3810     function onContextMenuClose() {
3811         setTimeout(function () {
3812             if (tempStyle) {
3813                 text.style.cssText = tempStyle;
3814                 tempStyle = '';
3815             }
3816             sendText();
3817             if (host.renderer.$keepTextAreaAtCursor == null) {
3818                 host.renderer.$keepTextAreaAtCursor = true;
3819                 host.renderer.$moveTextAreaToCursor();
3820             }
3821         }, 0);
3822     };
3823     this.onContextMenuClose = onContextMenuClose;
3825     // firefox fires contextmenu event after opening it
3826     if (!useragent.isGecko)
3827         event.addListener(text, "contextmenu", function(e) {
3828             host.textInput.onContextMenu(e);
3829             onContextMenuClose()
3830         });
3833 exports.TextInput = TextInput;
3836 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'], function(require, exports, module) {
3839 var event = require("../lib/event");
3840 var useragent = require("../lib/useragent");
3841 var DefaultHandlers = require("./default_handlers").DefaultHandlers;
3842 var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
3843 var MouseEvent = require("./mouse_event").MouseEvent;
3844 var DragdropHandler = require("./dragdrop").DragdropHandler;
3846 var MouseHandler = function(editor) {
3847     this.editor = editor;
3849     new DefaultHandlers(this);
3850     new DefaultGutterHandler(this);
3851     new DragdropHandler(this);
3853     event.addListener(editor.container, "mousedown", function(e) {
3854         editor.focus();
3855         return event.preventDefault(e);
3856     });
3858     var mouseTarget = editor.renderer.getMouseEventTarget();
3859     event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
3860     event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
3861     event.addMultiMouseDownListener(mouseTarget, [300, 300, 250], this, "onMouseEvent");
3862     event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
3864     var gutterEl = editor.renderer.$gutter;
3865     event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
3866     event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
3867     event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
3868     event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
3871 (function() {
3873     this.$scrollSpeed = 1;
3874     this.setScrollSpeed = function(speed) {
3875         this.$scrollSpeed = speed;
3876     };
3878     this.getScrollSpeed = function() {
3879         return this.$scrollSpeed;
3880     };
3882     this.onMouseEvent = function(name, e) {
3883         this.editor._emit(name, new MouseEvent(e, this.editor));
3884     };
3886     this.$dragDelay = 250;
3887     this.setDragDelay = function(dragDelay) {
3888         this.$dragDelay = dragDelay;
3889     };
3891     this.getDragDelay = function() {
3892         return this.$dragDelay;
3893     };
3895     this.onMouseMove = function(name, e) {
3896         // optimization, because mousemove doesn't have a default handler.
3897         var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
3898         if (!listeners || !listeners.length)
3899             return;
3901         this.editor._emit(name, new MouseEvent(e, this.editor));
3902     };
3904     this.onMouseWheel = function(name, e) {
3905         var mouseEvent = new MouseEvent(e, this.editor);
3906         mouseEvent.speed = this.$scrollSpeed * 2;
3907         mouseEvent.wheelX = e.wheelX;
3908         mouseEvent.wheelY = e.wheelY;
3910         this.editor._emit(name, mouseEvent);
3911     };
3913     this.setState = function(state) {
3914         this.state = state;
3915     };
3917     this.captureMouse = function(ev, state) {
3918         if (state)
3919             this.setState(state);
3921         this.x = ev.x;
3922         this.y = ev.y;
3924         // do not move textarea during selection
3925         var renderer = this.editor.renderer;
3926         if (renderer.$keepTextAreaAtCursor)
3927             renderer.$keepTextAreaAtCursor = null;
3929         var self = this;
3930         var onMouseMove = function(e) {
3931             self.x = e.clientX;
3932             self.y = e.clientY;
3933         };
3935         var onCaptureEnd = function(e) {
3936             clearInterval(timerId);
3937             self[self.state + "End"] && self[self.state + "End"](e);
3938             self.$clickSelection = null;
3939             if (renderer.$keepTextAreaAtCursor == null) {
3940                 renderer.$keepTextAreaAtCursor = true;
3941                 renderer.$moveTextAreaToCursor();
3942             }
3943         };
3945         var onCaptureInterval = function() {
3946             self[self.state] && self[self.state]();
3947         }
3948         
3949         if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
3950             setTimeout(function() {
3951                 onCaptureInterval();
3952                 onCaptureEnd(ev.domEvent);
3953             });
3954             return;
3955         }
3957         event.capture(this.editor.container, onMouseMove, onCaptureEnd);
3958         var timerId = setInterval(onCaptureInterval, 20);
3959     };
3960 }).call(MouseHandler.prototype);
3962 exports.MouseHandler = MouseHandler;
3965 define('ace/mouse/default_handlers', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/useragent'], function(require, exports, module) {
3968 var dom = require("../lib/dom");
3969 var useragent = require("../lib/useragent");
3971 var DRAG_OFFSET = 5; // pixels
3973 function DefaultHandlers(mouseHandler) {
3974     mouseHandler.$clickSelection = null;
3976     var editor = mouseHandler.editor;
3977     editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
3978     editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
3979     editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
3980     editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
3981     editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
3983     var exports = ["select", "startSelect", "drag", "dragEnd", "dragWait",
3984         "dragWaitEnd", "startDrag", "focusWait"];
3986     exports.forEach(function(x) {
3987         mouseHandler[x] = this[x];
3988     }, this);
3990     mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
3991     mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
3993     mouseHandler.$focusWaitTimout = 250;
3996 (function() {
3998     this.onMouseDown = function(ev) {
3999         var inSelection = ev.inSelection();
4000         var pos = ev.getDocumentPosition();
4001         this.mousedownEvent = ev;
4002         var editor = this.editor;
4004         var button = ev.getButton();
4005         if (button !== 0) {
4006             var selectionRange = editor.getSelectionRange();
4007             var selectionEmpty = selectionRange.isEmpty();
4009             if (selectionEmpty) {
4010                 editor.moveCursorToPosition(pos);
4011                 editor.selection.clearSelection();
4012             }
4014             // 2: contextmenu, 1: linux paste
4015             editor.textInput.onContextMenu(ev.domEvent);
4016             return; // stopping event here breaks contextmenu on ff mac
4017         }
4019         // if this click caused the editor to be focused should not clear the
4020         // selection
4021         if (inSelection && !editor.isFocused()) {
4022             editor.focus();
4023             if (this.$focusWaitTimout && !this.$clickSelection) {
4024                 this.setState("focusWait");
4025                 this.captureMouse(ev);
4026                 return ev.preventDefault();
4027             }
4028         }
4030         if (!inSelection || this.$clickSelection || ev.getShiftKey()) {
4031             // Directly pick STATE_SELECT, since the user is not clicking inside
4032             // a selection.
4033             this.startSelect(pos);
4034         } else if (inSelection) {
4035             this.mousedownEvent.time = (new Date()).getTime();
4036             this.setState("dragWait");
4037         }
4039         this.captureMouse(ev);
4040         return ev.preventDefault();
4041     };
4043     this.startSelect = function(pos) {
4044         pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
4045         if (this.mousedownEvent.getShiftKey()) {
4046             this.editor.selection.selectToPosition(pos);
4047         }
4048         else if (!this.$clickSelection) {
4049             this.editor.moveCursorToPosition(pos);
4050             this.editor.selection.clearSelection();
4051         }
4052         this.setState("select");
4053     };
4055     this.select = function() {
4056         var anchor, editor = this.editor;
4057         var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
4059         if (this.$clickSelection) {
4060             var cmp = this.$clickSelection.comparePoint(cursor);
4062             if (cmp == -1) {
4063                 anchor = this.$clickSelection.end;
4064             } else if (cmp == 1) {
4065                 anchor = this.$clickSelection.start;
4066             } else {
4067                 var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
4068                 cursor = orientedRange.cursor;
4069                 anchor = orientedRange.anchor;
4070             }
4071             editor.selection.setSelectionAnchor(anchor.row, anchor.column);
4072         }
4073         editor.selection.selectToPosition(cursor);
4075         editor.renderer.scrollCursorIntoView();
4076     };
4078     this.extendSelectionBy = function(unitName) {
4079         var anchor, editor = this.editor;
4080         var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
4081         var range = editor.selection[unitName](cursor.row, cursor.column);
4083         if (this.$clickSelection) {
4084             var cmpStart = this.$clickSelection.comparePoint(range.start);
4085             var cmpEnd = this.$clickSelection.comparePoint(range.end);
4087             if (cmpStart == -1 && cmpEnd <= 0) {
4088                 anchor = this.$clickSelection.end;
4089                 if (range.end.row != cursor.row || range.end.column != cursor.column)
4090                     cursor = range.start;
4091             } else if (cmpEnd == 1 && cmpStart >= 0) {
4092                 anchor = this.$clickSelection.start;
4093                 if (range.start.row != cursor.row || range.start.column != cursor.column)
4094                     cursor = range.end;
4095             } else if (cmpStart == -1 && cmpEnd == 1) {
4096                 cursor = range.end;
4097                 anchor = range.start;
4098             } else {
4099                 var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
4100                 cursor = orientedRange.cursor;
4101                 anchor = orientedRange.anchor;
4102             }
4103             editor.selection.setSelectionAnchor(anchor.row, anchor.column);
4104         }
4105         editor.selection.selectToPosition(cursor);
4107         editor.renderer.scrollCursorIntoView();
4108     };
4110     this.startDrag = function() {
4111         var editor = this.editor;
4112         this.setState("drag");
4113         this.dragRange = editor.getSelectionRange();
4114         var style = editor.getSelectionStyle();
4115         this.dragSelectionMarker = editor.session.addMarker(this.dragRange, "ace_selection", style);
4116         editor.clearSelection();
4117         dom.addCssClass(editor.container, "ace_dragging");
4118         if (!this.$dragKeybinding) {
4119             this.$dragKeybinding = {
4120                 handleKeyboard: function(data, hashId, keyString, keyCode) {
4121                     if (keyString == "esc")
4122                         return {command: this.command};
4123                 },
4124                 command: {
4125                     exec: function(editor) {
4126                         var self = editor.$mouseHandler;
4127                         self.dragCursor = null;
4128                         self.dragEnd();
4129                         self.startSelect();
4130                     }
4131                 }
4132             }
4133         }
4135         editor.keyBinding.addKeyboardHandler(this.$dragKeybinding);
4136     };
4138     this.focusWait = function() {
4139         var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
4140         var time = (new Date()).getTime();
4142         if (distance > DRAG_OFFSET ||time - this.mousedownEvent.time > this.$focusWaitTimout)
4143             this.startSelect();
4144     };
4146     this.dragWait = function(e) {
4147         var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
4148         var time = (new Date()).getTime();
4149         var editor = this.editor;
4151         if (distance > DRAG_OFFSET) {
4152             this.startSelect(this.mousedownEvent.getDocumentPosition());
4153         } else if (time - this.mousedownEvent.time > editor.getDragDelay()) {
4154             this.startDrag();
4155         }
4156     };
4158     this.dragWaitEnd = function(e) {
4159         this.mousedownEvent.domEvent = e;
4160         this.startSelect();
4161     };
4163     this.drag = function() {
4164         var editor = this.editor;
4165         this.dragCursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
4166         editor.moveCursorToPosition(this.dragCursor);
4167         editor.renderer.scrollCursorIntoView();
4168     };
4170     this.dragEnd = function(e) {
4171         var editor = this.editor;
4172         var dragCursor = this.dragCursor;
4173         var dragRange = this.dragRange;
4174         dom.removeCssClass(editor.container, "ace_dragging");
4175         editor.session.removeMarker(this.dragSelectionMarker);
4176         editor.keyBinding.removeKeyboardHandler(this.$dragKeybinding);
4178         if (!dragCursor)
4179             return;
4181         editor.clearSelection();
4182         if (e && (e.ctrlKey || e.altKey)) {
4183             var session = editor.session;
4184             var newRange = dragRange;
4185             newRange.end = session.insert(dragCursor, session.getTextRange(dragRange));
4186             newRange.start = dragCursor;
4187         } else if (dragRange.contains(dragCursor.row, dragCursor.column)) {
4188             return;
4189         } else {
4190             var newRange = editor.moveText(dragRange, dragCursor);
4191         }
4193         if (!newRange)
4194             return;
4196         editor.selection.setSelectionRange(newRange);
4197     };
4199     this.onDoubleClick = function(ev) {
4200         var pos = ev.getDocumentPosition();
4201         var editor = this.editor;
4202         var session = editor.session;
4204         var range = session.getBracketRange(pos);
4205         if (range) {
4206             if (range.isEmpty()) {
4207                 range.start.column--;
4208                 range.end.column++;
4209             }
4210             this.$clickSelection = range;
4211             this.setState("select");
4212             return;
4213         }
4215         this.$clickSelection = editor.selection.getWordRange(pos.row, pos.column);
4216         this.setState("selectByWords");
4217     };
4219     this.onTripleClick = function(ev) {
4220         var pos = ev.getDocumentPosition();
4221         var editor = this.editor;
4223         this.setState("selectByLines");
4224         this.$clickSelection = editor.selection.getLineRange(pos.row);
4225     };
4227     this.onQuadClick = function(ev) {
4228         var editor = this.editor;
4230         editor.selectAll();
4231         this.$clickSelection = editor.getSelectionRange();
4232         this.setState("null");
4233     };
4235     this.onMouseWheel = function(ev) {
4236         if (ev.getShiftKey() || ev.getAccelKey()){
4237             return;
4238         }
4239         var editor = this.editor;
4240         var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
4241         if (isScrolable) {
4242             this.$passScrollEvent = false;
4243         } else {
4244             if (this.$passScrollEvent)
4245                 return;
4247             if (!this.$scrollStopTimeout) {
4248                 var self = this;
4249                 this.$scrollStopTimeout = setTimeout(function() {
4250                     self.$passScrollEvent = true;
4251                     self.$scrollStopTimeout = null;
4252                 }, 200);
4253             }
4254         }
4256         editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
4257         return ev.preventDefault();
4258     };
4260 }).call(DefaultHandlers.prototype);
4262 exports.DefaultHandlers = DefaultHandlers;
4264 function calcDistance(ax, ay, bx, by) {
4265     return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
4268 function calcRangeOrientation(range, cursor) {
4269     if (range.start.row == range.end.row)
4270         var cmp = 2 * cursor.column - range.start.column - range.end.column;
4271     else
4272         var cmp = 2 * cursor.row - range.start.row - range.end.row;
4274     if (cmp < 0)
4275         return {cursor: range.start, anchor: range.end};
4276     else
4277         return {cursor: range.end, anchor: range.start};
4282 define('ace/mouse/default_gutter_handler', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/event'], function(require, exports, module) {
4284 var dom = require("../lib/dom");
4285 var event = require("../lib/event");
4287 function GutterHandler(mouseHandler) {
4288     var editor = mouseHandler.editor;
4289     var gutter = editor.renderer.$gutterLayer;
4291     mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
4292         if (!editor.isFocused())
4293             return;
4294         var gutterRegion = gutter.getRegion(e);
4296         if (gutterRegion)
4297             return;
4299         var row = e.getDocumentPosition().row;
4300         var selection = editor.session.selection;
4302         if (e.getShiftKey())
4303             selection.selectTo(row, 0);
4304         else
4305             mouseHandler.$clickSelection = editor.selection.getLineRange(row);
4307         mouseHandler.captureMouse(e, "selectByLines");
4308         return e.preventDefault();
4309     });
4312     var tooltipTimeout, mouseEvent, tooltip, tooltipAnnotation;
4313     function createTooltip() {
4314         tooltip = dom.createElement("div");
4315         tooltip.className = "ace_gutter_tooltip";
4316         tooltip.style.maxWidth = "500px";
4317         tooltip.style.display = "none";
4318         editor.container.appendChild(tooltip);
4319     }
4321     function showTooltip() {
4322         if (!tooltip) {
4323             createTooltip();
4324         }
4325         var row = mouseEvent.getDocumentPosition().row;
4326         var annotation = gutter.$annotations[row];
4327         if (!annotation)
4328             return hideTooltip();
4330         var maxRow = editor.session.getLength();
4331         if (row == maxRow) {
4332             var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
4333             var pos = mouseEvent.$pos;
4334             if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
4335                 return hideTooltip();
4336         }
4338         if (tooltipAnnotation == annotation)
4339             return;
4340         tooltipAnnotation = annotation.text.join("\n");
4342         tooltip.style.display = "block";
4343         tooltip.innerHTML = tooltipAnnotation;
4344         editor.on("mousewheel", hideTooltip);
4346         moveTooltip(mouseEvent);
4347     }
4349     function hideTooltip() {
4350         if (tooltipTimeout)
4351             tooltipTimeout = clearTimeout(tooltipTimeout);
4352         if (tooltipAnnotation) {
4353             tooltip.style.display = "none";
4354             tooltipAnnotation = null;
4355             editor.removeEventListener("mousewheel", hideTooltip);
4356         }
4357     }
4359     function moveTooltip(e) {
4360         var rect = editor.renderer.$gutter.getBoundingClientRect();
4361         tooltip.style.left = e.x - rect.left + 15 + "px";
4362         if (e.y + 3 * editor.renderer.lineHeight + 15 < rect.bottom) {
4363             tooltip.style.bottom =  "";
4364             tooltip.style.top =  e.y - rect.top + 15 + "px";
4365         } else {
4366             tooltip.style.top =  "";
4367             tooltip.style.bottom = rect.bottom - e.y + 5 + "px";
4368         }
4369     }
4371     mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
4372         var target = e.domEvent.target || e.domEvent.srcElement;
4373         if (dom.hasCssClass(target, "ace_fold-widget"))
4374             return hideTooltip();
4376         if (tooltipAnnotation)
4377             moveTooltip(e);
4379         mouseEvent = e;
4380         if (tooltipTimeout)
4381             return;
4382         tooltipTimeout = setTimeout(function() {
4383             tooltipTimeout = null;
4384             if (mouseEvent)
4385                 showTooltip();
4386             else
4387                 hideTooltip();
4388         }, 50);
4389     });
4391     event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
4392         mouseEvent = null;
4393         if (!tooltipAnnotation || tooltipTimeout)
4394             return;
4396         tooltipTimeout = setTimeout(function() {
4397             tooltipTimeout = null;
4398             hideTooltip();
4399         }, 50);
4400     });
4404 exports.GutterHandler = GutterHandler;
4408 define('ace/mouse/mouse_event', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/lib/useragent'], function(require, exports, module) {
4411 var event = require("../lib/event");
4412 var useragent = require("../lib/useragent");
4413 var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
4414     this.domEvent = domEvent;
4415     this.editor = editor;
4416     
4417     this.x = this.clientX = domEvent.clientX;
4418     this.y = this.clientY = domEvent.clientY;
4420     this.$pos = null;
4421     this.$inSelection = null;
4422     
4423     this.propagationStopped = false;
4424     this.defaultPrevented = false;
4427 (function() {  
4428     
4429     this.stopPropagation = function() {
4430         event.stopPropagation(this.domEvent);
4431         this.propagationStopped = true;
4432     };
4433     
4434     this.preventDefault = function() {
4435         event.preventDefault(this.domEvent);
4436         this.defaultPrevented = true;
4437     };
4438     
4439     this.stop = function() {
4440         this.stopPropagation();
4441         this.preventDefault();
4442     };
4443     this.getDocumentPosition = function() {
4444         if (this.$pos)
4445             return this.$pos;
4446         
4447         this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
4448         return this.$pos;
4449     };
4450     this.inSelection = function() {
4451         if (this.$inSelection !== null)
4452             return this.$inSelection;
4453             
4454         var editor = this.editor;
4455         
4456         if (editor.getReadOnly()) {
4457             this.$inSelection = false;
4458         }
4459         else {
4460             var selectionRange = editor.getSelectionRange();
4461             if (selectionRange.isEmpty())
4462                 this.$inSelection = false;
4463             else {
4464                 var pos = this.getDocumentPosition();
4465                 this.$inSelection = selectionRange.contains(pos.row, pos.column);
4466             }
4467         }
4468         return this.$inSelection;
4469     };
4470     this.getButton = function() {
4471         return event.getButton(this.domEvent);
4472     };
4473     this.getShiftKey = function() {
4474         return this.domEvent.shiftKey;
4475     };
4476     
4477     this.getAccelKey = useragent.isMac
4478         ? function() { return this.domEvent.metaKey; }
4479         : function() { return this.domEvent.ctrlKey; };
4480     
4481 }).call(MouseEvent.prototype);
4485 define('ace/mouse/dragdrop', ['require', 'exports', 'module' , 'ace/lib/event'], function(require, exports, module) {
4488 var event = require("../lib/event");
4490 var DragdropHandler = function(mouseHandler) {
4491     var editor = mouseHandler.editor;
4492     var dragSelectionMarker, x, y;
4493     var timerId, range, isBackwards;
4494     var dragCursor, counter = 0;
4496     var mouseTarget = editor.container;
4497     event.addListener(mouseTarget, "dragenter", function(e) {
4498         counter++;
4499         if (!dragSelectionMarker) {
4500             range = editor.getSelectionRange();
4501             isBackwards = editor.selection.isBackwards();
4502             var style = editor.getSelectionStyle();
4503             dragSelectionMarker = editor.session.addMarker(range, "ace_selection", style);
4504             editor.clearSelection();
4505             clearInterval(timerId);
4506             timerId = setInterval(onDragInterval, 20);
4507         }
4508         return event.preventDefault(e);
4509     });
4511     event.addListener(mouseTarget, "dragover", function(e) {
4512         x = e.clientX;
4513         y = e.clientY;
4514         return event.preventDefault(e);
4515     });
4516     
4517     var onDragInterval =  function() {
4518         dragCursor = editor.renderer.screenToTextCoordinates(x, y);
4519         editor.moveCursorToPosition(dragCursor);
4520         editor.renderer.scrollCursorIntoView();
4521     };
4522     
4523     event.addListener(mouseTarget, "dragleave", function(e) {
4524         counter--;
4525         if (counter > 0)
4526             return;
4527         console.log(e.type, counter,e.target);
4528         clearInterval(timerId);
4529         editor.session.removeMarker(dragSelectionMarker);
4530         dragSelectionMarker = null;
4531         editor.selection.setSelectionRange(range, isBackwards);
4532         return event.preventDefault(e);
4533     });
4534     
4535     event.addListener(mouseTarget, "drop", function(e) {
4536         console.log(e.type, counter,e.target);
4537         counter = 0;
4538         clearInterval(timerId);
4539         editor.session.removeMarker(dragSelectionMarker);
4540         dragSelectionMarker = null;
4542         range.end = editor.session.insert(dragCursor, e.dataTransfer.getData('Text'));
4543         range.start = dragCursor;
4544         editor.focus();
4545         editor.selection.setSelectionRange(range);
4546         return event.preventDefault(e);
4547     });
4551 exports.DragdropHandler = DragdropHandler;
4554 define('ace/mouse/fold_handler', ['require', 'exports', 'module' ], function(require, exports, module) {
4557 function FoldHandler(editor) {
4558     
4559     editor.on("click", function(e) {
4560         var position = e.getDocumentPosition();
4561         var session = editor.session;
4562         
4563         // If the user clicked on a fold, then expand it.
4564         var fold = session.getFoldAt(position.row, position.column, 1);
4565         if (fold) {
4566             if (e.getAccelKey())
4567                 session.removeFold(fold);
4568             else
4569                 session.expandFold(fold);
4570                 
4571             e.stop();
4572         }
4573     });
4574     
4575     editor.on("gutterclick", function(e) {
4576         var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
4578         if (gutterRegion == "foldWidgets") {
4579             var row = e.getDocumentPosition().row;
4580             var session = editor.session;
4581             if (session.foldWidgets && session.foldWidgets[row])
4582                 editor.session.onFoldWidgetClick(row, e);
4583             e.stop();
4584         }
4585     });
4588 exports.FoldHandler = FoldHandler;
4592 define('ace/keyboard/keybinding', ['require', 'exports', 'module' , 'ace/lib/keys', 'ace/lib/event'], function(require, exports, module) {
4595 var keyUtil  = require("../lib/keys");
4596 var event = require("../lib/event");
4598 var KeyBinding = function(editor) {
4599     this.$editor = editor;
4600     this.$data = { };
4601     this.$handlers = [];
4602     this.setDefaultHandler(editor.commands);
4605 (function() {
4606     this.setDefaultHandler = function(kb) {
4607         this.removeKeyboardHandler(this.$defaultHandler);
4608         this.$defaultHandler = kb;
4609         this.addKeyboardHandler(kb, 0);
4610         this.$data = {editor: this.$editor};
4611     };
4613     this.setKeyboardHandler = function(kb) {
4614         if (this.$handlers[this.$handlers.length - 1] == kb)
4615             return;
4617         while (this.$handlers[1])
4618             this.removeKeyboardHandler(this.$handlers[1]);
4620         this.addKeyboardHandler(kb, 1);
4621     };
4623     this.addKeyboardHandler = function(kb, pos) {
4624         if (!kb)
4625             return;
4626         var i = this.$handlers.indexOf(kb);
4627         if (i != -1)
4628             this.$handlers.splice(i, 1);
4630         if (pos == undefined)
4631             this.$handlers.push(kb);
4632         else
4633             this.$handlers.splice(pos, 0, kb);
4635         if (i == -1 && kb.attach)
4636             kb.attach(this.$editor);
4637     };
4639     this.removeKeyboardHandler = function(kb) {
4640         var i = this.$handlers.indexOf(kb);
4641         if (i == -1)
4642             return false;
4643         this.$handlers.splice(i, 1);
4644         kb.detach && kb.detach(this.$editor);
4645         return true;
4646     };
4648     this.getKeyboardHandler = function() {
4649         return this.$handlers[this.$handlers.length - 1];
4650     };
4652     this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
4653         var toExecute;
4654         for (var i = this.$handlers.length; i--;) {
4655             toExecute = this.$handlers[i].handleKeyboard(
4656                 this.$data, hashId, keyString, keyCode, e
4657             );
4658             if (toExecute && toExecute.command)
4659                 break;
4660         }
4662         if (!toExecute || !toExecute.command)
4663             return false;
4665         var success = false;
4666         var commands = this.$editor.commands;
4668         // allow keyboardHandler to consume keys
4669         if (toExecute.command != "null")
4670             success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
4671         else
4672             success = toExecute.passEvent != true;
4674         // do not stop input events to not break repeating
4675         if (success && e && hashId != -1)
4676             event.stopEvent(e);
4678         return success;
4679     };
4681     this.onCommandKey = function(e, hashId, keyCode) {
4682         var keyString = keyUtil.keyCodeToString(keyCode);
4683         this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
4684     };
4686     this.onTextInput = function(text) {
4687         var success = this.$callKeyboardHandlers(-1, text);
4688         if (!success)
4689             this.$editor.commands.exec("insertstring", this.$editor, text);
4690     };
4692 }).call(KeyBinding.prototype);
4694 exports.KeyBinding = KeyBinding;
4697 define('ace/edit_session', ['require', 'exports', 'module' , 'ace/config', 'ace/lib/oop', 'ace/lib/lang', 'ace/lib/net', '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) {
4700 var config = require("./config");
4701 var oop = require("./lib/oop");
4702 var lang = require("./lib/lang");
4703 var net = require("./lib/net");
4704 var EventEmitter = require("./lib/event_emitter").EventEmitter;
4705 var Selection = require("./selection").Selection;
4706 var TextMode = require("./mode/text").Mode;
4707 var Range = require("./range").Range;
4708 var Document = require("./document").Document;
4709 var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
4710 var SearchHighlight = require("./search_highlight").SearchHighlight;
4712 // events 
4714  * EditSession@change(e)
4715  * - e (Object): An object containing a `delta` of information about the change.
4717  * Emitted when the document changes.
4718  **/
4720  * EditSession@changeTabSize()
4722  * Emitted when the tab size changes, via [[EditSession.setTabSize]].
4723  **/
4725  * EditSession@changeOverwrite()
4727  * Emitted when the ability to overwrite text changes, via [[EditSession.setOverwrite]].
4728  **/
4730  * EditSession@changeBreakpoint()
4732  * Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change.
4733  **/
4735  * EditSession@changeFrontMarker()
4737  * Emitted when a front marker changes.
4738  **/
4740  * EditSession@changeBackMarker()
4742  * Emitted when a back marker changes.
4743  **/
4745  * EditSession@changeAnnotation()
4747  * Emitted when an annotation changes, like through [[EditSession.setAnnotations]].
4748  **/
4750  * EditSession@tokenizerUpdate(e)
4751  * - e (Object): An object containing one property, `"data"`, that contains information about the changing rows
4753  * Emitted when a background tokenizer asynchronously processes new rows.
4755  **/
4756 /** hide
4757  * EditSession@loadMode(e)
4758  * 
4761  **/
4762 /** 
4763  * EditSession@changeMode()
4764  * 
4765  * Emitted when the current mode changes.
4767  **/
4768 /** 
4769  * EditSession@changeWrapMode()
4770  * 
4771  * Emitted when the wrap mode changes.
4773  **/
4774 /** 
4775  * EditSession@changeWrapLimit()
4776  * 
4777  * Emitted when the wrapping limit changes.
4779  **/
4781  * EditSession@changeFold(e)
4783  * Emitted when a code fold is added or removed.
4785  **/
4786  /**
4787  * EditSession@changeScrollTop(scrollTop) 
4788  * - scrollTop (Number): The new scroll top value
4790  * Emitted when the scroll top changes.
4791  **/
4793  * EditSession@changeScrollLeft(scrollLeft) 
4794  * - scrollLeft (Number): The new scroll left value
4796  * Emitted when the scroll left changes.
4797  **/
4798      
4799      
4801  * new EditSession(text, mode)
4802  * - text (Document | String): If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text
4803  * - mode (TextMode): The inital language mode to use for the document
4805  * Sets up a new `EditSession` and associates it with the given `Document` and `TextMode`.
4807  **/
4809 var EditSession = function(text, mode) {
4810     this.$modified = true;
4811     this.$breakpoints = [];
4812     this.$decorations = [];
4813     this.$frontMarkers = {};
4814     this.$backMarkers = {};
4815     this.$markerId = 1;
4816     this.$resetRowCache(0);
4817     this.$wrapData = [];
4818     this.$foldData = [];
4819     this.$rowLengthCache = [];
4820     this.$undoSelect = true;
4821     this.$foldData.toString = function() {
4822         var str = "";
4823         this.forEach(function(foldLine) {
4824             str += "\n" + foldLine.toString();
4825         });
4826         return str;
4827     }
4829     if (typeof text == "object" && text.getLine) {
4830         this.setDocument(text);
4831     } else {
4832         this.setDocument(new Document(text));
4833     }
4835     this.selection = new Selection(this);
4836     this.setMode(mode);
4840 (function() {
4842     oop.implement(this, EventEmitter);
4843     this.setDocument = function(doc) {
4844         if (this.doc)
4845             throw new Error("Document is already set");
4847         this.doc = doc;
4848         doc.on("change", this.onChange.bind(this));
4849         this.on("changeFold", this.onChangeFold.bind(this));
4851         if (this.bgTokenizer) {
4852             this.bgTokenizer.setDocument(this.getDocument());
4853             this.bgTokenizer.start(0);
4854         }
4855     };
4856     this.getDocument = function() {
4857         return this.doc;
4858     };
4859     this.$resetRowCache = function(docRow) {
4860         if (!docRow) {
4861             this.$docRowCache = [];
4862             this.$screenRowCache = [];
4863             return;
4864         }
4866         var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
4867         var l = this.$docRowCache.length;
4868         this.$docRowCache.splice(i, l);
4869         this.$screenRowCache.splice(i, l);
4871     };
4873     this.$getRowCacheIndex = function(cacheArray, val) {
4874         var low = 0;
4875         var hi = cacheArray.length - 1;
4877         while (low <= hi) {
4878             var mid = (low + hi) >> 1;
4879             var c = cacheArray[mid];
4881             if (val > c)
4882                 low = mid + 1;
4883             else if (val < c)
4884                 hi = mid - 1;
4885             else
4886                 return mid;
4887         }
4889         return low && low -1;
4890     };
4892     this.onChangeFold = function(e) {
4893         var fold = e.data;
4894         this.$resetRowCache(fold.start.row);
4895     };
4897     this.onChange = function(e) {
4898         var delta = e.data;
4899         this.$modified = true;
4901         this.$resetRowCache(delta.range.start.row);
4903         var removedFolds = this.$updateInternalDataOnChange(e);
4904         if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
4905             this.$deltasDoc.push(delta);
4906             if (removedFolds && removedFolds.length != 0) {
4907                 this.$deltasFold.push({
4908                     action: "removeFolds",
4909                     folds:  removedFolds
4910                 });
4911             }
4913             this.$informUndoManager.schedule();
4914         }
4916         this.bgTokenizer.$updateOnChange(delta);
4917         this._emit("change", e);
4918     };
4919     this.setValue = function(text) {
4920         this.doc.setValue(text);
4921         this.selection.moveCursorTo(0, 0);
4922         this.selection.clearSelection();
4924         this.$resetRowCache(0);
4925         this.$deltas = [];
4926         this.$deltasDoc = [];
4927         this.$deltasFold = [];
4928         this.getUndoManager().reset();
4929     };
4930     /** alias of: EditSession.getValue
4931     * EditSession.toString() -> String
4932     *
4933     * Returns the current [[Document `Document`]] as a string.
4934     *
4935     **/
4936     this.getValue =
4937     this.toString = function() {
4938         return this.doc.getValue();
4939     };
4940     this.getSelection = function() {
4941         return this.selection;
4942     };
4943     this.getState = function(row) {
4944         return this.bgTokenizer.getState(row);
4945     };
4946     this.getTokens = function(row) {
4947         return this.bgTokenizer.getTokens(row);
4948     };
4949     this.getTokenAt = function(row, column) {
4950         var tokens = this.bgTokenizer.getTokens(row);
4951         var token, c = 0;
4952         if (column == null) {
4953             i = tokens.length - 1;
4954             c = this.getLine(row).length;
4955         } else {
4956             for (var i = 0; i < tokens.length; i++) {
4957                 c += tokens[i].value.length;
4958                 if (c >= column)
4959                     break;
4960             }
4961         }
4962         token = tokens[i];
4963         if (!token)
4964             return null;
4965         token.index = i;
4966         token.start = c - token.value.length;
4967         return token;
4968     };
4970     this.highlight = function(re) {
4971         if (!this.$searchHighlight) {
4972             var highlight = new SearchHighlight(null, "ace_selected_word", "text");
4973             this.$searchHighlight = this.addDynamicMarker(highlight);
4974         }
4975         this.$searchHighlight.setRegexp(re);
4976     }
4977     /**
4978     * EditSession.setUndoManager(undoManager)
4979     * - undoManager (UndoManager): The new undo manager
4980     *
4981     * Sets the undo manager.
4982     **/
4983     this.setUndoManager = function(undoManager) {
4984         this.$undoManager = undoManager;
4985         this.$deltas = [];
4986         this.$deltasDoc = [];
4987         this.$deltasFold = [];
4989         if (this.$informUndoManager)
4990             this.$informUndoManager.cancel();
4992         if (undoManager) {
4993             var self = this;
4994             this.$syncInformUndoManager = function() {
4995                 self.$informUndoManager.cancel();
4997                 if (self.$deltasFold.length) {
4998                     self.$deltas.push({
4999                         group: "fold",
5000                         deltas: self.$deltasFold
5001                     });
5002                     self.$deltasFold = [];
5003                 }
5005                 if (self.$deltasDoc.length) {
5006                     self.$deltas.push({
5007                         group: "doc",
5008                         deltas: self.$deltasDoc
5009                     });
5010                     self.$deltasDoc = [];
5011                 }
5013                 if (self.$deltas.length > 0) {
5014                     undoManager.execute({
5015                         action: "aceupdate",
5016                         args: [self.$deltas, self]
5017                     });
5018                 }
5020                 self.$deltas = [];
5021             }
5022             this.$informUndoManager =
5023                 lang.deferredCall(this.$syncInformUndoManager);
5024         }
5025     };
5027     this.$defaultUndoManager = {
5028         undo: function() {},
5029         redo: function() {},
5030         reset: function() {}
5031     };
5032     this.getUndoManager = function() {
5033         return this.$undoManager || this.$defaultUndoManager;
5034     },
5036     /**
5037     * EditSession.getTabString() -> String
5038     *
5039     * Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by [[EditSession.getTabSize `getTabSize()`]]); otherwise it's simply `'\t'`.
5040     **/
5041     this.getTabString = function() {
5042         if (this.getUseSoftTabs()) {
5043             return lang.stringRepeat(" ", this.getTabSize());
5044         } else {
5045             return "\t";
5046         }
5047     };
5049     this.$useSoftTabs = true;
5050     this.setUseSoftTabs = function(useSoftTabs) {
5051         if (this.$useSoftTabs === useSoftTabs) return;
5053         this.$useSoftTabs = useSoftTabs;
5054     };
5055     this.getUseSoftTabs = function() {
5056         return this.$useSoftTabs;
5057     };
5059     this.$tabSize = 4;
5060     this.setTabSize = function(tabSize) {
5061         if (isNaN(tabSize) || this.$tabSize === tabSize) return;
5063         this.$modified = true;
5064         this.$rowLengthCache = [];
5065         this.$tabSize = tabSize;
5066         this._emit("changeTabSize");
5067     };
5068     this.getTabSize = function() {
5069         return this.$tabSize;
5070     };
5071     this.isTabStop = function(position) {
5072         return this.$useSoftTabs && (position.column % this.$tabSize == 0);
5073     };
5075     this.$overwrite = false;
5076     this.setOverwrite = function(overwrite) {
5077         if (this.$overwrite == overwrite) return;
5079         this.$overwrite = overwrite;
5080         this._emit("changeOverwrite");
5081     };
5082     this.getOverwrite = function() {
5083         return this.$overwrite;
5084     };
5085     this.toggleOverwrite = function() {
5086         this.setOverwrite(!this.$overwrite);
5087     };
5088     this.addGutterDecoration = function(row, className) {
5089         if (!this.$decorations[row])
5090             this.$decorations[row] = "";
5091         this.$decorations[row] += " " + className;
5092         this._emit("changeBreakpoint", {});
5093     };
5094     this.removeGutterDecoration = function(row, className) {
5095         this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
5096         this._emit("changeBreakpoint", {});
5097     };
5098     this.getBreakpoints = function() {
5099         return this.$breakpoints;
5100     };
5101     this.setBreakpoints = function(rows) {
5102         this.$breakpoints = [];
5103         for (var i=0; i<rows.length; i++) {
5104             this.$breakpoints[rows[i]] = "ace_breakpoint";
5105         }
5106         this._emit("changeBreakpoint", {});
5107     };
5108     this.clearBreakpoints = function() {
5109         this.$breakpoints = [];
5110         this._emit("changeBreakpoint", {});
5111     };
5112     this.setBreakpoint = function(row, className) {
5113         if (className === undefined)
5114             className = "ace_breakpoint";
5115         if (className)
5116             this.$breakpoints[row] = className;
5117         else
5118             delete this.$breakpoints[row];
5119         this._emit("changeBreakpoint", {});
5120     };
5121     this.clearBreakpoint = function(row) {
5122         delete this.$breakpoints[row];
5123         this._emit("changeBreakpoint", {});
5124     };
5125     this.addMarker = function(range, clazz, type, inFront) {
5126         var id = this.$markerId++;
5128         var marker = {
5129             range : range,
5130             type : type || "line",
5131             renderer: typeof type == "function" ? type : null,
5132             clazz : clazz,
5133             inFront: !!inFront,
5134             id: id
5135         }
5137         if (inFront) {
5138             this.$frontMarkers[id] = marker;
5139             this._emit("changeFrontMarker")
5140         } else {
5141             this.$backMarkers[id] = marker;
5142             this._emit("changeBackMarker")
5143         }
5145         return id;
5146     };
5147     this.addDynamicMarker = function(marker, inFront) {
5148         if (!marker.update)
5149             return;
5150         var id = this.$markerId++;
5151         marker.id = id;
5152         marker.inFront = !!inFront;
5154         if (inFront) {
5155             this.$frontMarkers[id] = marker;
5156             this._emit("changeFrontMarker")
5157         } else {
5158             this.$backMarkers[id] = marker;
5159             this._emit("changeBackMarker")
5160         }
5162         return marker;
5163     };
5164     this.removeMarker = function(markerId) {
5165         var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
5166         if (!marker)
5167             return;
5169         var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
5170         if (marker) {
5171             delete (markers[markerId]);
5172             this._emit(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
5173         }
5174     };
5175     this.getMarkers = function(inFront) {
5176         return inFront ? this.$frontMarkers : this.$backMarkers;
5177     };
5178     /**
5179     * EditSession.setAnnotations(annotations)
5180     * - annotations (Array): A list of annotations
5181     *
5182     * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event.
5183     **/
5184     this.setAnnotations = function(annotations) {
5185         this.$annotations = {};
5186         for (var i=0; i<annotations.length; i++) {
5187             var annotation = annotations[i];
5188             var row = annotation.row;
5189             if (this.$annotations[row])
5190                 this.$annotations[row].push(annotation);
5191             else
5192                 this.$annotations[row] = [annotation];
5193         }
5194         this._emit("changeAnnotation", {});
5195     };
5196     this.getAnnotations = function() {
5197         return this.$annotations || {};
5198     };
5199     this.clearAnnotations = function() {
5200         this.$annotations = {};
5201         this._emit("changeAnnotation", {});
5202     };
5203     this.$detectNewLine = function(text) {
5204         var match = text.match(/^.*?(\r?\n)/m);
5205         if (match) {
5206             this.$autoNewLine = match[1];
5207         } else {
5208             this.$autoNewLine = "\n";
5209         }
5210     };
5211     this.getWordRange = function(row, column) {
5212         var line = this.getLine(row);
5214         var inToken = false;
5215         if (column > 0)
5216             inToken = !!line.charAt(column - 1).match(this.tokenRe);
5218         if (!inToken)
5219             inToken = !!line.charAt(column).match(this.tokenRe);
5220         
5221         if (inToken)
5222             var re = this.tokenRe;
5223         else if (/^\s+$/.test(line.slice(column-1, column+1)))
5224             var re = /\s/;
5225         else
5226             var re = this.nonTokenRe;
5228         var start = column;
5229         if (start > 0) {
5230             do {
5231                 start--;
5232             }
5233             while (start >= 0 && line.charAt(start).match(re));
5234             start++;
5235         }
5237         var end = column;
5238         while (end < line.length && line.charAt(end).match(re)) {
5239             end++;
5240         }
5242         return new Range(row, start, row, end);
5243     };
5244     this.getAWordRange = function(row, column) {
5245         var wordRange = this.getWordRange(row, column);
5246         var line = this.getLine(wordRange.end.row);
5248         while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
5249             wordRange.end.column += 1;
5250         }
5251         return wordRange;
5252     };
5253     this.setNewLineMode = function(newLineMode) {
5254         this.doc.setNewLineMode(newLineMode);
5255     };
5256     this.getNewLineMode = function() {
5257         return this.doc.getNewLineMode();
5258     };
5260     this.$useWorker = true;
5261     this.setUseWorker = function(useWorker) {
5262         if (this.$useWorker == useWorker)
5263             return;
5265         this.$useWorker = useWorker;
5267         this.$stopWorker();
5268         if (useWorker)
5269             this.$startWorker();
5270     };
5271     this.getUseWorker = function() {
5272         return this.$useWorker;
5273     };
5274     this.onReloadTokenizer = function(e) {
5275         var rows = e.data;
5276         this.bgTokenizer.start(rows.first);
5277         this._emit("tokenizerUpdate", e);
5278     };
5280     this.$modes = {};
5281     this._loadMode = function(mode, callback) {
5282         if (!this.$modes["null"])
5283             this.$modes["null"] = this.$modes["ace/mode/text"] = new TextMode();
5285         if (this.$modes[mode])
5286             return callback(this.$modes[mode]);
5288         var _self = this;
5289         var module;
5290         try {
5291             module = require(mode);
5292         } catch (e) {};
5293         // sometimes require returns empty object (this bug is present in requirejs 2 as well)
5294         if (module && module.Mode)
5295             return done(module);
5297         // set mode to text until loading is finished
5298         if (!this.$mode)
5299             this.$setModePlaceholder();
5301         fetch(mode, function() {
5302             require([mode], done);
5303         });
5305         function done(module) {
5306             if (_self.$modes[mode])
5307                 return callback(_self.$modes[mode]);
5309             _self.$modes[mode] = new module.Mode();
5310             _self.$modes[mode].$id = mode;
5311             _self._emit("loadmode", {
5312                 name: mode,
5313                 mode: _self.$modes[mode]
5314             });
5315             callback(_self.$modes[mode]);
5316         }
5318         function fetch(name, callback) {
5319             if (!config.get("packaged"))
5320                 return callback();
5322             net.loadScript(config.moduleUrl(name, "mode"), callback);
5323         }
5324     };
5326     this.$setModePlaceholder = function() {
5327         this.$mode = this.$modes["null"];
5328         var tokenizer = this.$mode.getTokenizer();
5330         if (!this.bgTokenizer) {
5331             this.bgTokenizer = new BackgroundTokenizer(tokenizer);
5332             var _self = this;
5333             this.bgTokenizer.addEventListener("update", function(e) {
5334                 _self._emit("tokenizerUpdate", e);
5335             });
5336         } else {
5337             this.bgTokenizer.setTokenizer(tokenizer);
5338         }
5339         this.bgTokenizer.setDocument(this.getDocument());
5341         this.tokenRe = this.$mode.tokenRe;
5342         this.nonTokenRe = this.$mode.nonTokenRe;
5343     };
5344     this.$mode = null;
5345     this.$modeId = null;
5346     this.setMode = function(mode) {
5347         mode = mode || "null";
5348         // load on demand
5349         if (typeof mode === "string") {
5350             if (this.$modeId == mode)
5351                 return;
5353             this.$modeId = mode;
5354             var _self = this;
5355             this._loadMode(mode, function(module) {
5356                 if (_self.$modeId !== mode)
5357                     return;
5359                 _self.setMode(module);
5360             });
5361             return;
5362         }
5364         if (this.$mode === mode) return;
5365         this.$mode = mode;
5366         this.$modeId = mode.$id;
5368         this.$stopWorker();
5370         if (this.$useWorker)
5371             this.$startWorker();
5373         var tokenizer = mode.getTokenizer();
5375         if(tokenizer.addEventListener !== undefined) {
5376             var onReloadTokenizer = this.onReloadTokenizer.bind(this);
5377             tokenizer.addEventListener("update", onReloadTokenizer);
5378         }
5380         if (!this.bgTokenizer) {
5381             this.bgTokenizer = new BackgroundTokenizer(tokenizer);
5382             var _self = this;
5383             this.bgTokenizer.addEventListener("update", function(e) {
5384                 _self._emit("tokenizerUpdate", e);
5385             });
5386         } else {
5387             this.bgTokenizer.setTokenizer(tokenizer);
5388         }
5390         this.bgTokenizer.setDocument(this.getDocument());
5391         this.bgTokenizer.start(0);
5393         this.tokenRe = mode.tokenRe;
5394         this.nonTokenRe = mode.nonTokenRe;
5396         this.$setFolding(mode.foldingRules);
5398         this._emit("changeMode");
5399     };
5400     this.$stopWorker = function() {
5401         if (this.$worker)
5402             this.$worker.terminate();
5404         this.$worker = null;
5405     };
5406     this.$startWorker = function() {
5407         if (typeof Worker !== "undefined" && !require.noWorker) {
5408             try {
5409                 this.$worker = this.$mode.createWorker(this);
5410             } catch (e) {
5411                 console.log("Could not load worker");
5412                 console.log(e);
5413                 this.$worker = null;
5414             }
5415         }
5416         else
5417             this.$worker = null;
5418     };
5419     this.getMode = function() {
5420         return this.$mode;
5421     };
5423     this.$scrollTop = 0;
5424     this.setScrollTop = function(scrollTop) {
5425         scrollTop = Math.round(Math.max(0, scrollTop));
5426         if (this.$scrollTop === scrollTop)
5427             return;
5429         this.$scrollTop = scrollTop;
5430         this._emit("changeScrollTop", scrollTop);
5431     };
5432     this.getScrollTop = function() {
5433         return this.$scrollTop;
5434     };
5436     this.$scrollLeft = 0;
5437     this.setScrollLeft = function(scrollLeft) {
5438         scrollLeft = Math.round(Math.max(0, scrollLeft));
5439         if (this.$scrollLeft === scrollLeft)
5440             return;
5442         this.$scrollLeft = scrollLeft;
5443         this._emit("changeScrollLeft", scrollLeft);
5444     };
5445     this.getScrollLeft = function() {
5446         return this.$scrollLeft;
5447     };
5448     this.getScreenWidth = function() {
5449         this.$computeWidth();
5450         return this.screenWidth;
5451     };
5453     this.$computeWidth = function(force) {
5454         if (this.$modified || force) {
5455             this.$modified = false;
5457             if (this.$useWrapMode)
5458                 return this.screenWidth = this.$wrapLimit;
5460             var lines = this.doc.getAllLines();
5461             var cache = this.$rowLengthCache;
5462             var longestScreenLine = 0;
5463             var foldIndex = 0;
5464             var foldLine = this.$foldData[foldIndex];
5465             var foldStart = foldLine ? foldLine.start.row : Infinity;
5466             var len = lines.length;
5468             for (var i = 0; i < len; i++) {
5469                 if (i > foldStart) {
5470                     i = foldLine.end.row + 1;
5471                     if (i >= len)
5472                         break;
5473                     foldLine = this.$foldData[foldIndex++];
5474                     foldStart = foldLine ? foldLine.start.row : Infinity;
5475                 }
5477                 if (cache[i] == null)
5478                     cache[i] = this.$getStringScreenWidth(lines[i])[0];
5480                 if (cache[i] > longestScreenLine)
5481                     longestScreenLine = cache[i];
5482             }
5483             this.screenWidth = longestScreenLine;
5484         }
5485     };
5486     this.getLine = function(row) {
5487         return this.doc.getLine(row);
5488     };
5489     this.getLines = function(firstRow, lastRow) {
5490         return this.doc.getLines(firstRow, lastRow);
5491     };
5492     this.getLength = function() {
5493         return this.doc.getLength();
5494     };
5495     this.getTextRange = function(range) {
5496         return this.doc.getTextRange(range || this.selection.getRange());
5497     };
5498     this.insert = function(position, text) {
5499         return this.doc.insert(position, text);
5500     };
5501     this.remove = function(range) {
5502         return this.doc.remove(range);
5503     };
5504     this.undoChanges = function(deltas, dontSelect) {
5505         if (!deltas.length)
5506             return;
5508         this.$fromUndo = true;
5509         var lastUndoRange = null;
5510         for (var i = deltas.length - 1; i != -1; i--) {
5511             var delta = deltas[i];
5512             if (delta.group == "doc") {
5513                 this.doc.revertDeltas(delta.deltas);
5514                 lastUndoRange =
5515                     this.$getUndoSelection(delta.deltas, true, lastUndoRange);
5516             } else {
5517                 delta.deltas.forEach(function(foldDelta) {
5518                     this.addFolds(foldDelta.folds);
5519                 }, this);
5520             }
5521         }
5522         this.$fromUndo = false;
5523         lastUndoRange &&
5524             this.$undoSelect &&
5525             !dontSelect &&
5526             this.selection.setSelectionRange(lastUndoRange);
5527         return lastUndoRange;
5528     };
5529     this.redoChanges = function(deltas, dontSelect) {
5530         if (!deltas.length)
5531             return;
5533         this.$fromUndo = true;
5534         var lastUndoRange = null;
5535         for (var i = 0; i < deltas.length; i++) {
5536             var delta = deltas[i];
5537             if (delta.group == "doc") {
5538                 this.doc.applyDeltas(delta.deltas);
5539                 lastUndoRange =
5540                     this.$getUndoSelection(delta.deltas, false, lastUndoRange);
5541             }
5542         }
5543         this.$fromUndo = false;
5544         lastUndoRange &&
5545             this.$undoSelect &&
5546             !dontSelect &&
5547             this.selection.setSelectionRange(lastUndoRange);
5548         return lastUndoRange;
5549     };
5550     this.setUndoSelect = function(enable) {
5551         this.$undoSelect = enable;
5552     };
5553     this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
5554         function isInsert(delta) {
5555             var insert =
5556                 delta.action == "insertText" || delta.action == "insertLines";
5557             return isUndo ? !insert : insert;
5558         }
5560         var delta = deltas[0];
5561         var range, point;
5562         var lastDeltaIsInsert = false;
5563         if (isInsert(delta)) {
5564             range = delta.range.clone();
5565             lastDeltaIsInsert = true;
5566         } else {
5567             range = Range.fromPoints(delta.range.start, delta.range.start);
5568             lastDeltaIsInsert = false;
5569         }
5571         for (var i = 1; i < deltas.length; i++) {
5572             delta = deltas[i];
5573             if (isInsert(delta)) {
5574                 point = delta.range.start;
5575                 if (range.compare(point.row, point.column) == -1) {
5576                     range.setStart(delta.range.start);
5577                 }
5578                 point = delta.range.end;
5579                 if (range.compare(point.row, point.column) == 1) {
5580                     range.setEnd(delta.range.end);
5581                 }
5582                 lastDeltaIsInsert = true;
5583             } else {
5584                 point = delta.range.start;
5585                 if (range.compare(point.row, point.column) == -1) {
5586                     range =
5587                         Range.fromPoints(delta.range.start, delta.range.start);
5588                 }
5589                 lastDeltaIsInsert = false;
5590             }
5591         }
5593         // Check if this range and the last undo range has something in common.
5594         // If true, merge the ranges.
5595         if (lastUndoRange != null) {
5596             var cmp = lastUndoRange.compareRange(range);
5597             if (cmp == 1) {
5598                 range.setStart(lastUndoRange.start);
5599             } else if (cmp == -1) {
5600                 range.setEnd(lastUndoRange.end);
5601             }
5602         }
5604         return range;
5605     },
5607     /** related to: Document.replace
5608     * EditSession.replace(range, text) -> Object
5609     * - range (Range): A specified Range to replace
5610     * - text (String): The new text to use as a replacement
5611     * + (Object): Returns an object containing the final row and column, like this:<br/>
5612     * ```{row: endRow, column: 0}```<br/>
5613     * If the text and range are empty, this function returns an object containing the current `range.start` value.<br/>
5614     * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value.
5615     *
5616     * Replaces a range in the document with the new `text`.
5617     *
5618     *
5619     *
5620     **/
5621     this.replace = function(range, text) {
5622         return this.doc.replace(range, text);
5623     };
5624     this.moveText = function(fromRange, toPosition) {
5625         var text = this.getTextRange(fromRange);
5626         this.remove(fromRange);
5628         var toRow = toPosition.row;
5629         var toColumn = toPosition.column;
5631         // Make sure to update the insert location, when text is removed in
5632         // front of the chosen point of insertion.
5633         if (!fromRange.isMultiLine() && fromRange.start.row == toRow &&
5634             fromRange.end.column < toColumn)
5635             toColumn -= text.length;
5637         if (fromRange.isMultiLine() && fromRange.end.row < toRow) {
5638             var lines = this.doc.$split(text);
5639             toRow -= lines.length - 1;
5640         }
5642         var endRow = toRow + fromRange.end.row - fromRange.start.row;
5643         var endColumn = fromRange.isMultiLine() ?
5644                         fromRange.end.column :
5645                         toColumn + fromRange.end.column - fromRange.start.column;
5647         var toRange = new Range(toRow, toColumn, endRow, endColumn);
5649         this.insert(toRange.start, text);
5651         return toRange;
5652     };
5653     this.indentRows = function(startRow, endRow, indentString) {
5654         indentString = indentString.replace(/\t/g, this.getTabString());
5655         for (var row=startRow; row<=endRow; row++)
5656             this.insert({row: row, column:0}, indentString);
5657     };
5658     this.outdentRows = function (range) {
5659         var rowRange = range.collapseRows();
5660         var deleteRange = new Range(0, 0, 0, 0);
5661         var size = this.getTabSize();
5663         for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
5664             var line = this.getLine(i);
5666             deleteRange.start.row = i;
5667             deleteRange.end.row = i;
5668             for (var j = 0; j < size; ++j)
5669                 if (line.charAt(j) != ' ')
5670                     break;
5671             if (j < size && line.charAt(j) == '\t') {
5672                 deleteRange.start.column = j;
5673                 deleteRange.end.column = j + 1;
5674             } else {
5675                 deleteRange.start.column = 0;
5676                 deleteRange.end.column = j;
5677             }
5678             this.remove(deleteRange);
5679         }
5680     };
5681     this.moveLinesUp = function(firstRow, lastRow) {
5682         if (firstRow <= 0) return 0;
5684         var removed = this.doc.removeLines(firstRow, lastRow);
5685         this.doc.insertLines(firstRow - 1, removed);
5686         return -1;
5687     };
5688     this.moveLinesDown = function(firstRow, lastRow) {
5689         if (lastRow >= this.doc.getLength()-1) return 0;
5691         var removed = this.doc.removeLines(firstRow, lastRow);
5692         this.doc.insertLines(firstRow+1, removed);
5693         return 1;
5694     };
5695     this.duplicateLines = function(firstRow, lastRow) {
5696         var firstRow = this.$clipRowToDocument(firstRow);
5697         var lastRow = this.$clipRowToDocument(lastRow);
5699         var lines = this.getLines(firstRow, lastRow);
5700         this.doc.insertLines(firstRow, lines);
5702         var addedRows = lastRow - firstRow + 1;
5703         return addedRows;
5704     };
5707     this.$clipRowToDocument = function(row) {
5708         return Math.max(0, Math.min(row, this.doc.getLength()-1));
5709     };
5711     this.$clipColumnToRow = function(row, column) {
5712         if (column < 0)
5713             return 0;
5714         return Math.min(this.doc.getLine(row).length, column);
5715     };
5718     this.$clipPositionToDocument = function(row, column) {
5719         column = Math.max(0, column);
5721         if (row < 0) {
5722             row = 0;
5723             column = 0;
5724         } else {
5725             var len = this.doc.getLength();
5726             if (row >= len) {
5727                 row = len - 1;
5728                 column = this.doc.getLine(len-1).length;
5729             } else {
5730                 column = Math.min(this.doc.getLine(row).length, column);
5731             }
5732         }
5734         return {
5735             row: row,
5736             column: column
5737         };
5738     };
5740     this.$clipRangeToDocument = function(range) {
5741         if (range.start.row < 0) {
5742             range.start.row = 0;
5743             range.start.column = 0;
5744         } else {
5745             range.start.column = this.$clipColumnToRow(
5746                 range.start.row,
5747                 range.start.column
5748             );
5749         }
5751         var len = this.doc.getLength() - 1;
5752         if (range.end.row > len) {
5753             range.end.row = len;
5754             range.end.column = this.doc.getLine(len).length;
5755         } else {
5756             range.end.column = this.$clipColumnToRow(
5757                 range.end.row,
5758                 range.end.column
5759             );
5760         }
5761         return range;
5762     };
5764     // WRAPMODE
5765     this.$wrapLimit = 80;
5766     this.$useWrapMode = false;
5767     this.$wrapLimitRange = {
5768         min : null,
5769         max : null
5770     };
5771     this.setUseWrapMode = function(useWrapMode) {
5772         if (useWrapMode != this.$useWrapMode) {
5773             this.$useWrapMode = useWrapMode;
5774             this.$modified = true;
5775             this.$resetRowCache(0);
5777             // If wrapMode is activaed, the wrapData array has to be initialized.
5778             if (useWrapMode) {
5779                 var len = this.getLength();
5780                 this.$wrapData = [];
5781                 for (var i = 0; i < len; i++) {
5782                     this.$wrapData.push([]);
5783                 }
5784                 this.$updateWrapData(0, len - 1);
5785             }
5787             this._emit("changeWrapMode");
5788         }
5789     };
5790     this.getUseWrapMode = function() {
5791         return this.$useWrapMode;
5792     };
5794     // Allow the wrap limit to move freely between min and max. Either
5795     // parameter can be null to allow the wrap limit to be unconstrained
5796     // in that direction. Or set both parameters to the same number to pin
5797     // the limit to that value.
5798     /**
5799     * EditSession.setWrapLimitRange(min, max)
5800     * - min (Number): The minimum wrap value (the left side wrap)
5801     * - max (Number): The maximum wrap value (the right side wrap)
5802     *
5803     * Sets the boundaries of wrap. Either value can be `null` to have an unconstrained wrap, or, they can be the same number to pin the limit. If the wrap limits for `min` or `max` are different, this method also emits the `'changeWrapMode'` event.
5804     **/
5805     this.setWrapLimitRange = function(min, max) {
5806         if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
5807             this.$wrapLimitRange.min = min;
5808             this.$wrapLimitRange.max = max;
5809             this.$modified = true;
5810             // This will force a recalculation of the wrap limit
5811             this._emit("changeWrapMode");
5812         }
5813     };
5814     this.adjustWrapLimit = function(desiredLimit) {
5815         var wrapLimit = this.$constrainWrapLimit(desiredLimit);
5816         if (wrapLimit != this.$wrapLimit && wrapLimit > 0) {
5817             this.$wrapLimit = wrapLimit;
5818             this.$modified = true;
5819             if (this.$useWrapMode) {
5820                 this.$updateWrapData(0, this.getLength() - 1);
5821                 this.$resetRowCache(0);
5822                 this._emit("changeWrapLimit");
5823             }
5824             return true;
5825         }
5826         return false;
5827     };
5828     this.$constrainWrapLimit = function(wrapLimit) {
5829         var min = this.$wrapLimitRange.min;
5830         if (min)
5831             wrapLimit = Math.max(min, wrapLimit);
5833         var max = this.$wrapLimitRange.max;
5834         if (max)
5835             wrapLimit = Math.min(max, wrapLimit);
5837         // What would a limit of 0 even mean?
5838         return Math.max(1, wrapLimit);
5839     };
5840     this.getWrapLimit = function() {
5841         return this.$wrapLimit;
5842     };
5843     this.getWrapLimitRange = function() {
5844         // Avoid unexpected mutation by returning a copy
5845         return {
5846             min : this.$wrapLimitRange.min,
5847             max : this.$wrapLimitRange.max
5848         };
5849     };
5850     this.$updateInternalDataOnChange = function(e) {
5851         var useWrapMode = this.$useWrapMode;
5852         var len;
5853         var action = e.data.action;
5854         var firstRow = e.data.range.start.row;
5855         var lastRow = e.data.range.end.row;
5856         var start = e.data.range.start;
5857         var end = e.data.range.end;
5858         var removedFolds = null;
5860         if (action.indexOf("Lines") != -1) {
5861             if (action == "insertLines") {
5862                 lastRow = firstRow + (e.data.lines.length);
5863             } else {
5864                 lastRow = firstRow;
5865             }
5866             len = e.data.lines ? e.data.lines.length : lastRow - firstRow;
5867         } else {
5868             len = lastRow - firstRow;
5869         }
5871         if (len != 0) {
5872             if (action.indexOf("remove") != -1) {
5873                 this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
5875                 var foldLines = this.$foldData;
5876                 removedFolds = this.getFoldsInRange(e.data.range);
5877                 this.removeFolds(removedFolds);
5879                 var foldLine = this.getFoldLine(end.row);
5880                 var idx = 0;
5881                 if (foldLine) {
5882                     foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
5883                     foldLine.shiftRow(-len);
5885                     var foldLineBefore = this.getFoldLine(firstRow);
5886                     if (foldLineBefore && foldLineBefore !== foldLine) {
5887                         foldLineBefore.merge(foldLine);
5888                         foldLine = foldLineBefore;
5889                     }
5890                     idx = foldLines.indexOf(foldLine) + 1;
5891                 }
5893                 for (idx; idx < foldLines.length; idx++) {
5894                     var foldLine = foldLines[idx];
5895                     if (foldLine.start.row >= end.row) {
5896                         foldLine.shiftRow(-len);
5897                     }
5898                 }
5900                 lastRow = firstRow;
5901             } else {
5902                 var args;
5903                 if (useWrapMode) {
5904                     args = [firstRow, 0];
5905                     for (var i = 0; i < len; i++) args.push([]);
5906                     this.$wrapData.splice.apply(this.$wrapData, args);
5907                 } else {
5908                     args = Array(len);
5909                     args.unshift(firstRow, 0);
5910                     this.$rowLengthCache.splice.apply(this.$rowLengthCache, args);
5911                 }
5913                 // If some new line is added inside of a foldLine, then split
5914                 // the fold line up.
5915                 var foldLines = this.$foldData;
5916                 var foldLine = this.getFoldLine(firstRow);
5917                 var idx = 0;
5918                 if (foldLine) {
5919                     var cmp = foldLine.range.compareInside(start.row, start.column)
5920                     // Inside of the foldLine range. Need to split stuff up.
5921                     if (cmp == 0) {
5922                         foldLine = foldLine.split(start.row, start.column);
5923                         foldLine.shiftRow(len);
5924                         foldLine.addRemoveChars(
5925                             lastRow, 0, end.column - start.column);
5926                     } else
5927                     // Infront of the foldLine but same row. Need to shift column.
5928                     if (cmp == -1) {
5929                         foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
5930                         foldLine.shiftRow(len);
5931                     }
5932                     // Nothing to do if the insert is after the foldLine.
5933                     idx = foldLines.indexOf(foldLine) + 1;
5934                 }
5936                 for (idx; idx < foldLines.length; idx++) {
5937                     var foldLine = foldLines[idx];
5938                     if (foldLine.start.row >= firstRow) {
5939                         foldLine.shiftRow(len);
5940                     }
5941                 }
5942             }
5943         } else {
5944             // Realign folds. E.g. if you add some new chars before a fold, the
5945             // fold should "move" to the right.
5946             len = Math.abs(e.data.range.start.column - e.data.range.end.column);
5947             if (action.indexOf("remove") != -1) {
5948                 // Get all the folds in the change range and remove them.
5949                 removedFolds = this.getFoldsInRange(e.data.range);
5950                 this.removeFolds(removedFolds);
5952                 len = -len;
5953             }
5954             var foldLine = this.getFoldLine(firstRow);
5955             if (foldLine) {
5956                 foldLine.addRemoveChars(firstRow, start.column, len);
5957             }
5958         }
5960         if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
5961             console.error("doc.getLength() and $wrapData.length have to be the same!");
5962         }
5964         if (useWrapMode)
5965             this.$updateWrapData(firstRow, lastRow);
5966         else
5967             this.$updateRowLengthCache(firstRow, lastRow);
5969         return removedFolds;
5970     };
5972     this.$updateRowLengthCache = function(firstRow, lastRow, b) {
5973         this.$rowLengthCache[firstRow] = null;
5974         this.$rowLengthCache[lastRow] = null;
5975     };
5976     this.$updateWrapData = function(firstRow, lastRow) {
5977         var lines = this.doc.getAllLines();
5978         var tabSize = this.getTabSize();
5979         var wrapData = this.$wrapData;
5980         var wrapLimit = this.$wrapLimit;
5981         var tokens;
5982         var foldLine;
5984         var row = firstRow;
5985         lastRow = Math.min(lastRow, lines.length - 1);
5986         while (row <= lastRow) {
5987             foldLine = this.getFoldLine(row, foldLine);
5988             if (!foldLine) {
5989                 tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row]));
5990                 wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
5991                 row ++;
5992             } else {
5993                 tokens = [];
5994                 foldLine.walk(
5995                     function(placeholder, row, column, lastColumn) {
5996                         var walkTokens;
5997                         if (placeholder) {
5998                             walkTokens = this.$getDisplayTokens(
5999                                             placeholder, tokens.length);
6000                             walkTokens[0] = PLACEHOLDER_START;
6001                             for (var i = 1; i < walkTokens.length; i++) {
6002                                 walkTokens[i] = PLACEHOLDER_BODY;
6003                             }
6004                         } else {
6005                             walkTokens = this.$getDisplayTokens(
6006                                 lines[row].substring(lastColumn, column),
6007                                 tokens.length);
6008                         }
6009                         tokens = tokens.concat(walkTokens);
6010                     }.bind(this),
6011                     foldLine.end.row,
6012                     lines[foldLine.end.row].length + 1
6013                 );
6014                 // Remove spaces/tabs from the back of the token array.
6015                 while (tokens.length != 0 && tokens[tokens.length - 1] >= SPACE)
6016                     tokens.pop();
6018                 wrapData[foldLine.start.row]
6019                     = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
6020                 row = foldLine.end.row + 1;
6021             }
6022         }
6023     };
6025     // "Tokens"
6026     var CHAR = 1,
6027         CHAR_EXT = 2,
6028         PLACEHOLDER_START = 3,
6029         PLACEHOLDER_BODY =  4,
6030         PUNCTUATION = 9,
6031         SPACE = 10,
6032         TAB = 11,
6033         TAB_SPACE = 12;
6034     this.$computeWrapSplits = function(tokens, wrapLimit) {
6035         if (tokens.length == 0) {
6036             return [];
6037         }
6039         var splits = [];
6040         var displayLength = tokens.length;
6041         var lastSplit = 0, lastDocSplit = 0;
6043         function addSplit(screenPos) {
6044             var displayed = tokens.slice(lastSplit, screenPos);
6046             // The document size is the current size - the extra width for tabs
6047             // and multipleWidth characters.
6048             var len = displayed.length;
6049             displayed.join("").
6050                 // Get all the TAB_SPACEs.
6051                 replace(/12/g, function() {
6052                     len -= 1;
6053                 }).
6054                 // Get all the CHAR_EXT/multipleWidth characters.
6055                 replace(/2/g, function() {
6056                     len -= 1;
6057                 });
6059             lastDocSplit += len;
6060             splits.push(lastDocSplit);
6061             lastSplit = screenPos;
6062         }
6064         while (displayLength - lastSplit > wrapLimit) {
6065             // This is, where the split should be.
6066             var split = lastSplit + wrapLimit;
6068             // If there is a space or tab at this split position, then making
6069             // a split is simple.
6070             if (tokens[split] >= SPACE) {
6071                 // Include all following spaces + tabs in this split as well.
6072                 while (tokens[split] >= SPACE) {
6073                     split ++;
6074                 }
6075                 addSplit(split);
6076                 continue;
6077             }
6079             // === ELSE ===
6080             // Check if split is inside of a placeholder. Placeholder are
6081             // not splitable. Therefore, seek the beginning of the placeholder
6082             // and try to place the split beofre the placeholder's start.
6083             if (tokens[split] == PLACEHOLDER_START
6084                 || tokens[split] == PLACEHOLDER_BODY)
6085             {
6086                 // Seek the start of the placeholder and do the split
6087                 // before the placeholder. By definition there always
6088                 // a PLACEHOLDER_START between split and lastSplit.
6089                 for (split; split != lastSplit - 1; split--) {
6090                     if (tokens[split] == PLACEHOLDER_START) {
6091                         // split++; << No incremental here as we want to
6092                         //  have the position before the Placeholder.
6093                         break;
6094                     }
6095                 }
6097                 // If the PLACEHOLDER_START is not the index of the
6098                 // last split, then we can do the split
6099                 if (split > lastSplit) {
6100                     addSplit(split);
6101                     continue;
6102                 }
6104                 // If the PLACEHOLDER_START IS the index of the last
6105                 // split, then we have to place the split after the
6106                 // placeholder. So, let's seek for the end of the placeholder.
6107                 split = lastSplit + wrapLimit;
6108                 for (split; split < tokens.length; split++) {
6109                     if (tokens[split] != PLACEHOLDER_BODY)
6110                     {
6111                         break;
6112                     }
6113                 }
6115                 // If spilt == tokens.length, then the placeholder is the last
6116                 // thing in the line and adding a new split doesn't make sense.
6117                 if (split == tokens.length) {
6118                     break;  // Breaks the while-loop.
6119                 }
6121                 // Finally, add the split...
6122                 addSplit(split);
6123                 continue;
6124             }
6126             // === ELSE ===
6127             // Search for the first non space/tab/placeholder/punctuation token backwards.
6128             var minSplit = Math.max(split - 10, lastSplit - 1);
6129             while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
6130                 split --;
6131             }
6132             while (split > minSplit && tokens[split] == PUNCTUATION) {
6133                 split --;
6134             }
6135             // If we found one, then add the split.
6136             if (split > minSplit) {
6137                 addSplit(++split);
6138                 continue;
6139             }
6141             // === ELSE ===
6142             split = lastSplit + wrapLimit;
6143             // The split is inside of a CHAR or CHAR_EXT token and no space
6144             // around -> force a split.
6145             addSplit(split);
6146         }
6147         return splits;
6148     };
6149     this.$getDisplayTokens = function(str, offset) {
6150         var arr = [];
6151         var tabSize;
6152         offset = offset || 0;
6154         for (var i = 0; i < str.length; i++) {
6155             var c = str.charCodeAt(i);
6156             // Tab
6157             if (c == 9) {
6158                 tabSize = this.getScreenTabSize(arr.length + offset);
6159                 arr.push(TAB);
6160                 for (var n = 1; n < tabSize; n++) {
6161                     arr.push(TAB_SPACE);
6162                 }
6163             }
6164             // Space
6165             else if (c == 32) {
6166                 arr.push(SPACE);
6167             } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
6168                 arr.push(PUNCTUATION);
6169             }
6170             // full width characters
6171             else if (c >= 0x1100 && isFullWidth(c)) {
6172                 arr.push(CHAR, CHAR_EXT);
6173             } else {
6174                 arr.push(CHAR);
6175             }
6176         }
6177         return arr;
6178     };
6179     this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
6180         if (maxScreenColumn == 0)
6181             return [0, 0];
6182         if (maxScreenColumn == null)
6183             maxScreenColumn = Infinity;
6184         screenColumn = screenColumn || 0;
6186         var c, column;
6187         for (column = 0; column < str.length; column++) {
6188             c = str.charCodeAt(column);
6189             // tab
6190             if (c == 9) {
6191                 screenColumn += this.getScreenTabSize(screenColumn);
6192             }
6193             // full width characters
6194             else if (c >= 0x1100 && isFullWidth(c)) {
6195                 screenColumn += 2;
6196             } else {
6197                 screenColumn += 1;
6198             }
6199             if (screenColumn > maxScreenColumn) {
6200                 break;
6201             }
6202         }
6204         return [screenColumn, column];
6205     };
6206     this.getRowLength = function(row) {
6207         if (!this.$useWrapMode || !this.$wrapData[row]) {
6208             return 1;
6209         } else {
6210             return this.$wrapData[row].length + 1;
6211         }
6212     };
6213     this.getScreenLastRowColumn = function(screenRow) {
6214         var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
6215         return this.documentToScreenColumn(pos.row, pos.column);
6216     };
6217     this.getDocumentLastRowColumn = function(docRow, docColumn) {
6218         var screenRow = this.documentToScreenRow(docRow, docColumn);
6219         return this.getScreenLastRowColumn(screenRow);
6220     };
6221     this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
6222         var screenRow = this.documentToScreenRow(docRow, docColumn);
6223         return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
6224     };
6225     this.getRowSplitData = function(row) {
6226         if (!this.$useWrapMode) {
6227             return undefined;
6228         } else {
6229             return this.$wrapData[row];
6230         }
6231     };
6232     this.getScreenTabSize = function(screenColumn) {
6233         return this.$tabSize - screenColumn % this.$tabSize;
6234     };
6235     this.screenToDocumentRow = function(screenRow, screenColumn) {
6236         return this.screenToDocumentPosition(screenRow, screenColumn).row;
6237     };
6238     this.screenToDocumentColumn = function(screenRow, screenColumn) {
6239         return this.screenToDocumentPosition(screenRow, screenColumn).column;
6240     };
6241     this.screenToDocumentPosition = function(screenRow, screenColumn) {
6242         if (screenRow < 0)
6243             return {row: 0, column: 0};
6245         var line;
6246         var docRow = 0;
6247         var docColumn = 0;
6248         var column;
6249         var row = 0;
6250         var rowLength = 0;
6252         var rowCache = this.$screenRowCache;
6253         var i = this.$getRowCacheIndex(rowCache, screenRow);
6254         if (0 < i && i < rowCache.length) {
6255             var row = rowCache[i];
6256             var docRow = this.$docRowCache[i];
6257             var doCache = screenRow > row || (screenRow == row && i == rowCache.length - 1);
6258         } else {
6259             var doCache = i != 0 || !rowCache.length;
6260         }
6262         var maxRow = this.getLength() - 1;
6263         var foldLine = this.getNextFoldLine(docRow);
6264         var foldStart = foldLine ? foldLine.start.row : Infinity;
6266         while (row <= screenRow) {
6267             rowLength = this.getRowLength(docRow);
6268             if (row + rowLength - 1 >= screenRow || docRow >= maxRow) {
6269                 break;
6270             } else {
6271                 row += rowLength;
6272                 docRow++;
6273                 if (docRow > foldStart) {
6274                     docRow = foldLine.end.row+1;
6275                     foldLine = this.getNextFoldLine(docRow, foldLine);
6276                     foldStart = foldLine ? foldLine.start.row : Infinity;
6277                 }
6278             }
6279             if (doCache) {
6280                 this.$docRowCache.push(docRow);
6281                 this.$screenRowCache.push(row);
6282             }
6283         }
6285         if (foldLine && foldLine.start.row <= docRow) {
6286             line = this.getFoldDisplayLine(foldLine);
6287             docRow = foldLine.start.row;
6288         } else if (row + rowLength <= screenRow || docRow > maxRow) {
6289             // clip at the end of the document
6290             return {
6291                 row: maxRow,
6292                 column: this.getLine(maxRow).length
6293             }
6294         } else {
6295             line = this.getLine(docRow);
6296             foldLine = null;
6297         }
6299         if (this.$useWrapMode) {
6300             var splits = this.$wrapData[docRow];
6301             if (splits) {
6302                 column = splits[screenRow - row];
6303                 if(screenRow > row && splits.length) {
6304                     docColumn = splits[screenRow - row - 1] || splits[splits.length - 1];
6305                     line = line.substring(docColumn);
6306                 }
6307             }
6308         }
6310         docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
6312         // We remove one character at the end so that the docColumn
6313         // position returned is not associated to the next row on the screen.
6314         if (this.$useWrapMode && docColumn >= column)
6315             docColumn = column - 1;
6317         if (foldLine)
6318             return foldLine.idxToPosition(docColumn);
6320         return {row: docRow, column: docColumn};
6321     };
6322     this.documentToScreenPosition = function(docRow, docColumn) {
6323         // Normalize the passed in arguments.
6324         if (typeof docColumn === "undefined")
6325             var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
6326         else
6327             pos = this.$clipPositionToDocument(docRow, docColumn);
6329         docRow = pos.row;
6330         docColumn = pos.column;
6332         var screenRow = 0;
6333         var foldStartRow = null;
6334         var fold = null;
6336         // Clamp the docRow position in case it's inside of a folded block.
6337         fold = this.getFoldAt(docRow, docColumn, 1);
6338         if (fold) {
6339             docRow = fold.start.row;
6340             docColumn = fold.start.column;
6341         }
6343         var rowEnd, row = 0;
6346         var rowCache = this.$docRowCache;
6347         var i = this.$getRowCacheIndex(rowCache, docRow);
6348         if (0 < i && i < rowCache.length) {
6349             var row = rowCache[i];
6350             var screenRow = this.$screenRowCache[i];
6351             var doCache = docRow > row || (docRow == row && i == rowCache.length - 1);
6352         } else {
6353             var doCache = i != 0 || !rowCache.length;
6354         }
6356         var foldLine = this.getNextFoldLine(row);
6357         var foldStart = foldLine ?foldLine.start.row :Infinity;
6359         while (row < docRow) {
6360             if (row >= foldStart) {
6361                 rowEnd = foldLine.end.row + 1;
6362                 if (rowEnd > docRow)
6363                     break;
6364                 foldLine = this.getNextFoldLine(rowEnd, foldLine);
6365                 foldStart = foldLine ?foldLine.start.row :Infinity;
6366             }
6367             else {
6368                 rowEnd = row + 1;
6369             }
6371             screenRow += this.getRowLength(row);
6372             row = rowEnd;
6374             if (doCache) {
6375                 this.$docRowCache.push(row);
6376                 this.$screenRowCache.push(screenRow);
6377             }
6378         }
6380         // Calculate the text line that is displayed in docRow on the screen.
6381         var textLine = "";
6382         // Check if the final row we want to reach is inside of a fold.
6383         if (foldLine && row >= foldStart) {
6384             textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
6385             foldStartRow = foldLine.start.row;
6386         } else {
6387             textLine = this.getLine(docRow).substring(0, docColumn);
6388             foldStartRow = docRow;
6389         }
6390         // Clamp textLine if in wrapMode.
6391         if (this.$useWrapMode) {
6392             var wrapRow = this.$wrapData[foldStartRow];
6393             var screenRowOffset = 0;
6394             while (textLine.length >= wrapRow[screenRowOffset]) {
6395                 screenRow ++;
6396                 screenRowOffset++;
6397             }
6398             textLine = textLine.substring(
6399                 wrapRow[screenRowOffset - 1] || 0, textLine.length
6400             );
6401         }
6403         return {
6404             row: screenRow,
6405             column: this.$getStringScreenWidth(textLine)[0]
6406         };
6407     };
6408     this.documentToScreenColumn = function(row, docColumn) {
6409         return this.documentToScreenPosition(row, docColumn).column;
6410     };
6411     this.documentToScreenRow = function(docRow, docColumn) {
6412         return this.documentToScreenPosition(docRow, docColumn).row;
6413     };
6414     this.getScreenLength = function() {
6415         var screenRows = 0;
6416         var fold = null;
6417         if (!this.$useWrapMode) {
6418             screenRows = this.getLength();
6420             // Remove the folded lines again.
6421             var foldData = this.$foldData;
6422             for (var i = 0; i < foldData.length; i++) {
6423                 fold = foldData[i];
6424                 screenRows -= fold.end.row - fold.start.row;
6425             }
6426         } else {
6427             var lastRow = this.$wrapData.length;
6428             var row = 0, i = 0;
6429             var fold = this.$foldData[i++];
6430             var foldStart = fold ? fold.start.row :Infinity;
6432             while (row < lastRow) {
6433                 screenRows += this.$wrapData[row].length + 1;
6434                 row ++;
6435                 if (row > foldStart) {
6436                     row = fold.end.row+1;
6437                     fold = this.$foldData[i++];
6438                     foldStart = fold ?fold.start.row :Infinity;
6439                 }
6440             }
6441         }
6443         return screenRows;
6444     }
6446     // For every keystroke this gets called once per char in the whole doc!!
6447     // Wouldn't hurt to make it a bit faster for c >= 0x1100
6448     function isFullWidth(c) {
6449         if (c < 0x1100)
6450             return false;
6451         return c >= 0x1100 && c <= 0x115F ||
6452                c >= 0x11A3 && c <= 0x11A7 ||
6453                c >= 0x11FA && c <= 0x11FF ||
6454                c >= 0x2329 && c <= 0x232A ||
6455                c >= 0x2E80 && c <= 0x2E99 ||
6456                c >= 0x2E9B && c <= 0x2EF3 ||
6457                c >= 0x2F00 && c <= 0x2FD5 ||
6458                c >= 0x2FF0 && c <= 0x2FFB ||
6459                c >= 0x3000 && c <= 0x303E ||
6460                c >= 0x3041 && c <= 0x3096 ||
6461                c >= 0x3099 && c <= 0x30FF ||
6462                c >= 0x3105 && c <= 0x312D ||
6463                c >= 0x3131 && c <= 0x318E ||
6464                c >= 0x3190 && c <= 0x31BA ||
6465                c >= 0x31C0 && c <= 0x31E3 ||
6466                c >= 0x31F0 && c <= 0x321E ||
6467                c >= 0x3220 && c <= 0x3247 ||
6468                c >= 0x3250 && c <= 0x32FE ||
6469                c >= 0x3300 && c <= 0x4DBF ||
6470                c >= 0x4E00 && c <= 0xA48C ||
6471                c >= 0xA490 && c <= 0xA4C6 ||
6472                c >= 0xA960 && c <= 0xA97C ||
6473                c >= 0xAC00 && c <= 0xD7A3 ||
6474                c >= 0xD7B0 && c <= 0xD7C6 ||
6475                c >= 0xD7CB && c <= 0xD7FB ||
6476                c >= 0xF900 && c <= 0xFAFF ||
6477                c >= 0xFE10 && c <= 0xFE19 ||
6478                c >= 0xFE30 && c <= 0xFE52 ||
6479                c >= 0xFE54 && c <= 0xFE66 ||
6480                c >= 0xFE68 && c <= 0xFE6B ||
6481                c >= 0xFF01 && c <= 0xFF60 ||
6482                c >= 0xFFE0 && c <= 0xFFE6;
6483     };
6485 }).call(EditSession.prototype);
6487 require("./edit_session/folding").Folding.call(EditSession.prototype);
6488 require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
6490 exports.EditSession = EditSession;
6493 define('ace/config', ['require', 'exports', 'module' , 'ace/lib/lang'], function(require, exports, module) {
6494 "no use strict";
6496 var lang = require("./lib/lang");
6498 var global = (function() {
6499     return this;
6500 })();
6502 var options = {
6503     packaged: false,
6504     workerPath: "",
6505     modePath: "",
6506     themePath: "",
6507     suffix: ".js",
6508     $moduleUrls: {}
6511 exports.get = function(key) {
6512     if (!options.hasOwnProperty(key))
6513         throw new Error("Unknown config key: " + key);
6515     return options[key];
6518 exports.set = function(key, value) {
6519     if (!options.hasOwnProperty(key))
6520         throw new Error("Unknown config key: " + key);
6522     options[key] = value;
6525 exports.all = function() {
6526     return lang.copyObject(options);
6529 exports.moduleUrl = function(name, component) {
6530     if (options.$moduleUrls[name])
6531         return options.$moduleUrls[name];
6533     var parts = name.split("/");
6534     component = component || parts[parts.length - 2] || "";
6535     var base = parts[parts.length - 1].replace(component, "").replace(/(^[\-_])|([\-_]$)/, "");
6537     if (!base && parts.length > 1)
6538         base = parts[parts.length - 2];
6539     return this.get(component + "Path") + "/" + component + "-" + base + this.get("suffix");
6542 exports.setModuleUrl = function(name, subst) {
6543     return options.$moduleUrls[name] = subst;
6546 exports.init = function() {
6547     options.packaged = require.packaged || module.packaged || (global.define && define.packaged);
6549     if (!global.document)
6550         return "";
6552     var scriptOptions = {};
6553     var scriptUrl = "";
6555     var scripts = document.getElementsByTagName("script");
6556     for (var i=0; i<scripts.length; i++) {
6557         var script = scripts[i];
6559         var src = script.src || script.getAttribute("src");
6560         if (!src) {
6561             continue;
6562         }
6564         var attributes = script.attributes;
6565         for (var j=0, l=attributes.length; j < l; j++) {
6566             var attr = attributes[j];
6567             if (attr.name.indexOf("data-ace-") === 0) {
6568                 scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
6569             }
6570         }
6572         var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
6573         if (m)
6574             scriptUrl = m[1];
6575     }
6577     if (scriptUrl) {
6578         scriptOptions.base = scriptOptions.base || scriptUrl;
6579         scriptOptions.packaged = true;
6580     }
6582     scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
6583     scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
6584     scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
6585     delete scriptOptions.base;
6587     for (var key in scriptOptions)
6588         if (typeof scriptOptions[key] !== "undefined")
6589             exports.set(key, scriptOptions[key]);
6592 function deHyphenate(str) {
6593     return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
6597 define('ace/lib/net', ['require', 'exports', 'module' , 'ace/lib/useragent'], function(require, exports, module) {
6600 var useragent = require("./useragent");
6602 exports.get = function (url, callback) {
6603     var xhr = exports.createXhr();
6604     xhr.open('GET', url, true);
6605     xhr.onreadystatechange = function (evt) {
6606         //Do not explicitly handle errors, those should be
6607         //visible via console output in the browser.
6608         if (xhr.readyState === 4) {
6609             callback(xhr.responseText);
6610         }
6611     };
6612     xhr.send(null);
6615 var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
6617 exports.createXhr = function() {
6618     //Would love to dump the ActiveX crap in here. Need IE 6 to die first.
6619     var xhr, i, progId;
6620     if (typeof XMLHttpRequest !== "undefined") {
6621         return new XMLHttpRequest();
6622     } else {
6623         for (i = 0; i < 3; i++) {
6624             progId = progIds[i];
6625             try {
6626                 xhr = new ActiveXObject(progId);
6627             } catch (e) {}
6629             if (xhr) {
6630                 progIds = [progId];  // so faster next time
6631                 break;
6632             }
6633         }
6634     }
6636     if (!xhr) {
6637         throw new Error("createXhr(): XMLHttpRequest not available");
6638     }
6640     return xhr;
6643 exports.loadScript = function(path, callback) {
6644     var head = document.getElementsByTagName('head')[0];
6645     var s = document.createElement('script');
6647     s.src = path;
6648     head.appendChild(s);
6650     if (useragent.isOldIE)
6651         s.onreadystatechange = function () {
6652             this.readyState == 'loaded' && callback();
6653         };
6654     else
6655         s.onload = callback;
6660 define('ace/lib/event_emitter', ['require', 'exports', 'module' ], function(require, exports, module) {
6663 var EventEmitter = {};
6665 EventEmitter._emit =
6666 EventEmitter._dispatchEvent = function(eventName, e) {
6667     this._eventRegistry = this._eventRegistry || {};
6668     this._defaultHandlers = this._defaultHandlers || {};
6670     var listeners = this._eventRegistry[eventName] || [];
6671     var defaultHandler = this._defaultHandlers[eventName];
6672     if (!listeners.length && !defaultHandler)
6673         return;
6675     if (typeof e != "object" || !e)
6676         e = {};
6678     if (!e.type)
6679         e.type = eventName;
6680     
6681     if (!e.stopPropagation) {
6682         e.stopPropagation = function() {
6683             this.propagationStopped = true;
6684         };
6685     }
6686     
6687     if (!e.preventDefault) {
6688         e.preventDefault = function() {
6689             this.defaultPrevented = true;
6690         };
6691     }
6693     for (var i=0; i<listeners.length; i++) {
6694         listeners[i](e);
6695         if (e.propagationStopped)
6696             break;
6697     }
6698     
6699     if (defaultHandler && !e.defaultPrevented)
6700         return defaultHandler(e);
6703 EventEmitter.setDefaultHandler = function(eventName, callback) {
6704     this._defaultHandlers = this._defaultHandlers || {};
6705     
6706     if (this._defaultHandlers[eventName])
6707         throw new Error("The default handler for '" + eventName + "' is already set");
6708         
6709     this._defaultHandlers[eventName] = callback;
6712 EventEmitter.on =
6713 EventEmitter.addEventListener = function(eventName, callback) {
6714     this._eventRegistry = this._eventRegistry || {};
6716     var listeners = this._eventRegistry[eventName];
6717     if (!listeners)
6718         listeners = this._eventRegistry[eventName] = [];
6720     if (listeners.indexOf(callback) == -1)
6721         listeners.push(callback);
6724 EventEmitter.removeListener =
6725 EventEmitter.removeEventListener = function(eventName, callback) {
6726     this._eventRegistry = this._eventRegistry || {};
6728     var listeners = this._eventRegistry[eventName];
6729     if (!listeners)
6730         return;
6732     var index = listeners.indexOf(callback);
6733     if (index !== -1)
6734         listeners.splice(index, 1);
6737 EventEmitter.removeAllListeners = function(eventName) {
6738     if (this._eventRegistry) this._eventRegistry[eventName] = [];
6741 exports.EventEmitter = EventEmitter;
6745 define('ace/selection', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/lib/event_emitter', 'ace/range'], function(require, exports, module) {
6748 var oop = require("./lib/oop");
6749 var lang = require("./lib/lang");
6750 var EventEmitter = require("./lib/event_emitter").EventEmitter;
6751 var Range = require("./range").Range;
6754  * new Selection(session)
6755  * - session (EditSession): The session to use
6757  * Creates a new `Selection` object.
6761  * Selection@changeCursor()
6763  * Emitted when the cursor position changes.
6767  * Selection@changeSelection()
6769  * Emitted when the cursor selection changes.
6772 var Selection = function(session) {
6773     this.session = session;
6774     this.doc = session.getDocument();
6776     this.clearSelection();
6777     this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
6778     this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
6780     var self = this;
6781     this.lead.on("change", function(e) {
6782         self._emit("changeCursor");
6783         if (!self.$isEmpty)
6784             self._emit("changeSelection");
6785         if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
6786             self.$desiredColumn = null;
6787     });
6789     this.selectionAnchor.on("change", function() {
6790         if (!self.$isEmpty)
6791             self._emit("changeSelection");
6792     });
6795 (function() {
6797     oop.implement(this, EventEmitter);
6798     this.isEmpty = function() {
6799         return (this.$isEmpty || (
6800             this.anchor.row == this.lead.row &&
6801             this.anchor.column == this.lead.column
6802         ));
6803     };
6804     this.isMultiLine = function() {
6805         if (this.isEmpty()) {
6806             return false;
6807         }
6809         return this.getRange().isMultiLine();
6810     };
6811     this.getCursor = function() {
6812         return this.lead.getPosition();
6813     };
6814     this.setSelectionAnchor = function(row, column) {
6815         this.anchor.setPosition(row, column);
6817         if (this.$isEmpty) {
6818             this.$isEmpty = false;
6819             this._emit("changeSelection");
6820         }
6821     };
6822     this.getSelectionAnchor = function() {
6823         if (this.$isEmpty)
6824             return this.getSelectionLead()
6825         else
6826             return this.anchor.getPosition();
6827     };
6828     this.getSelectionLead = function() {
6829         return this.lead.getPosition();
6830     };
6831     this.shiftSelection = function(columns) {
6832         if (this.$isEmpty) {
6833             this.moveCursorTo(this.lead.row, this.lead.column + columns);
6834             return;
6835         };
6837         var anchor = this.getSelectionAnchor();
6838         var lead = this.getSelectionLead();
6840         var isBackwards = this.isBackwards();
6842         if (!isBackwards || anchor.column !== 0)
6843             this.setSelectionAnchor(anchor.row, anchor.column + columns);
6845         if (isBackwards || lead.column !== 0) {
6846             this.$moveSelection(function() {
6847                 this.moveCursorTo(lead.row, lead.column + columns);
6848             });
6849         }
6850     };
6851     this.isBackwards = function() {
6852         var anchor = this.anchor;
6853         var lead = this.lead;
6854         return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
6855     };
6856     this.getRange = function() {
6857         var anchor = this.anchor;
6858         var lead = this.lead;
6860         if (this.isEmpty())
6861             return Range.fromPoints(lead, lead);
6863         if (this.isBackwards()) {
6864             return Range.fromPoints(lead, anchor);
6865         }
6866         else {
6867             return Range.fromPoints(anchor, lead);
6868         }
6869     };
6870     this.clearSelection = function() {
6871         if (!this.$isEmpty) {
6872             this.$isEmpty = true;
6873             this._emit("changeSelection");
6874         }
6875     };
6876     this.selectAll = function() {
6877         var lastRow = this.doc.getLength() - 1;
6878         this.setSelectionAnchor(0, 0);
6879         this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
6880     };
6881     this.setRange =
6882     this.setSelectionRange = function(range, reverse) {
6883         if (reverse) {
6884             this.setSelectionAnchor(range.end.row, range.end.column);
6885             this.selectTo(range.start.row, range.start.column);
6886         } else {
6887             this.setSelectionAnchor(range.start.row, range.start.column);
6888             this.selectTo(range.end.row, range.end.column);
6889         }
6890         this.$desiredColumn = null;
6891     };
6893     this.$moveSelection = function(mover) {
6894         var lead = this.lead;
6895         if (this.$isEmpty)
6896             this.setSelectionAnchor(lead.row, lead.column);
6898         mover.call(this);
6899     };
6900     this.selectTo = function(row, column) {
6901         this.$moveSelection(function() {
6902             this.moveCursorTo(row, column);
6903         });
6904     };
6905     this.selectToPosition = function(pos) {
6906         this.$moveSelection(function() {
6907             this.moveCursorToPosition(pos);
6908         });
6909     };
6910     this.selectUp = function() {
6911         this.$moveSelection(this.moveCursorUp);
6912     };
6913     this.selectDown = function() {
6914         this.$moveSelection(this.moveCursorDown);
6915     };
6916     this.selectRight = function() {
6917         this.$moveSelection(this.moveCursorRight);
6918     };
6919     this.selectLeft = function() {
6920         this.$moveSelection(this.moveCursorLeft);
6921     };
6922     this.selectLineStart = function() {
6923         this.$moveSelection(this.moveCursorLineStart);
6924     };
6925     this.selectLineEnd = function() {
6926         this.$moveSelection(this.moveCursorLineEnd);
6927     };
6928     this.selectFileEnd = function() {
6929         this.$moveSelection(this.moveCursorFileEnd);
6930     };
6931     this.selectFileStart = function() {
6932         this.$moveSelection(this.moveCursorFileStart);
6933     };
6934     this.selectWordRight = function() {
6935         this.$moveSelection(this.moveCursorWordRight);
6936     };
6937     this.selectWordLeft = function() {
6938         this.$moveSelection(this.moveCursorWordLeft);
6939     };
6940     this.getWordRange = function(row, column) {
6941         if (typeof column == "undefined") {
6942             var cursor = row || this.lead;
6943             row = cursor.row;
6944             column = cursor.column;
6945         }
6946         return this.session.getWordRange(row, column);
6947     };
6949     this.selectWord = function() {
6950         this.setSelectionRange(this.getWordRange());
6951     };
6952     this.selectAWord = function() {
6953         var cursor = this.getCursor();
6954         var range = this.session.getAWordRange(cursor.row, cursor.column);
6955         this.setSelectionRange(range);
6956     };
6958     this.getLineRange = function(row, excludeLastChar) {
6959         var rowStart = typeof row == "number" ? row : this.lead.row;
6960         var rowEnd;
6962         var foldLine = this.session.getFoldLine(rowStart);
6963         if (foldLine) {
6964             rowStart = foldLine.start.row;
6965             rowEnd = foldLine.end.row;
6966         } else {
6967             rowEnd = rowStart;
6968         }
6969         if (excludeLastChar)
6970             return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
6971         else
6972             return new Range(rowStart, 0, rowEnd + 1, 0);
6973     };
6974     this.selectLine = function() {
6975         this.setSelectionRange(this.getLineRange());
6976     };
6977     this.moveCursorUp = function() {
6978         this.moveCursorBy(-1, 0);
6979     };
6980     this.moveCursorDown = function() {
6981         this.moveCursorBy(1, 0);
6982     };
6983     this.moveCursorLeft = function() {
6984         var cursor = this.lead.getPosition(),
6985             fold;
6987         if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
6988             this.moveCursorTo(fold.start.row, fold.start.column);
6989         } else if (cursor.column == 0) {
6990             // cursor is a line (start
6991             if (cursor.row > 0) {
6992                 this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
6993             }
6994         }
6995         else {
6996             var tabSize = this.session.getTabSize();
6997             if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column-tabSize, cursor.column).split(" ").length-1 == tabSize)
6998                 this.moveCursorBy(0, -tabSize);
6999             else
7000                 this.moveCursorBy(0, -1);
7001         }
7002     };
7003     this.moveCursorRight = function() {
7004         var cursor = this.lead.getPosition(),
7005             fold;
7006         if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
7007             this.moveCursorTo(fold.end.row, fold.end.column);
7008         }
7009         else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
7010             if (this.lead.row < this.doc.getLength() - 1) {
7011                 this.moveCursorTo(this.lead.row + 1, 0);
7012             }
7013         }
7014         else {
7015             var tabSize = this.session.getTabSize();
7016             var cursor = this.lead;
7017             if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize)
7018                 this.moveCursorBy(0, tabSize);
7019             else
7020                 this.moveCursorBy(0, 1);
7021         }
7022     };
7023     this.moveCursorLineStart = function() {
7024         var row = this.lead.row;
7025         var column = this.lead.column;
7026         var screenRow = this.session.documentToScreenRow(row, column);
7028         // Determ the doc-position of the first character at the screen line.
7029         var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
7031         // Determ the line
7032         var beforeCursor = this.session.getDisplayLine(
7033             row, null, firstColumnPosition.row,
7034             firstColumnPosition.column
7035         );
7037         var leadingSpace = beforeCursor.match(/^\s*/);
7038         if (leadingSpace[0].length == column) {
7039             this.moveCursorTo(
7040                 firstColumnPosition.row, firstColumnPosition.column
7041             );
7042         }
7043         else {
7044             this.moveCursorTo(
7045                 firstColumnPosition.row,
7046                 firstColumnPosition.column + leadingSpace[0].length
7047             );
7048         }
7049     };
7050     this.moveCursorLineEnd = function() {
7051         var lead = this.lead;
7052         var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
7053         if (this.lead.column == lineEnd.column) {
7054             var line = this.session.getLine(lineEnd.row);
7055             if (lineEnd.column == line.length) {
7056                 var textEnd = line.search(/\s+$/);
7057                 if (textEnd > 0)
7058                     lineEnd.column = textEnd;
7059             }
7060         }
7062         this.moveCursorTo(lineEnd.row, lineEnd.column);
7063     };
7064     this.moveCursorFileEnd = function() {
7065         var row = this.doc.getLength() - 1;
7066         var column = this.doc.getLine(row).length;
7067         this.moveCursorTo(row, column);
7068     };
7069     this.moveCursorFileStart = function() {
7070         this.moveCursorTo(0, 0);
7071     };
7072     this.moveCursorLongWordRight = function() {
7073         var row = this.lead.row;
7074         var column = this.lead.column;
7075         var line = this.doc.getLine(row);
7076         var rightOfCursor = line.substring(column);
7078         var match;
7079         this.session.nonTokenRe.lastIndex = 0;
7080         this.session.tokenRe.lastIndex = 0;
7082         // skip folds
7083         var fold = this.session.getFoldAt(row, column, 1);
7084         if (fold) {
7085             this.moveCursorTo(fold.end.row, fold.end.column);
7086             return;
7087         }
7089         // first skip space
7090         if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
7091             column += this.session.nonTokenRe.lastIndex;
7092             this.session.nonTokenRe.lastIndex = 0;
7093             rightOfCursor = line.substring(column);
7094         }
7096         // if at line end proceed with next line
7097         if (column >= line.length) {
7098             this.moveCursorTo(row, line.length);
7099             this.moveCursorRight();
7100             if (row < this.doc.getLength() - 1)
7101                 this.moveCursorWordRight();
7102             return;
7103         }
7105         // advance to the end of the next token
7106         if (match = this.session.tokenRe.exec(rightOfCursor)) {
7107             column += this.session.tokenRe.lastIndex;
7108             this.session.tokenRe.lastIndex = 0;
7109         }
7111         this.moveCursorTo(row, column);
7112     };
7113     this.moveCursorLongWordLeft = function() {
7114         var row = this.lead.row;
7115         var column = this.lead.column;
7117         // skip folds
7118         var fold;
7119         if (fold = this.session.getFoldAt(row, column, -1)) {
7120             this.moveCursorTo(fold.start.row, fold.start.column);
7121             return;
7122         }
7124         var str = this.session.getFoldStringAt(row, column, -1);
7125         if (str == null) {
7126             str = this.doc.getLine(row).substring(0, column)
7127         }
7129         var leftOfCursor = lang.stringReverse(str);
7130         var match;
7131         this.session.nonTokenRe.lastIndex = 0;
7132         this.session.tokenRe.lastIndex = 0;
7134         // skip whitespace
7135         if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
7136             column -= this.session.nonTokenRe.lastIndex;
7137             leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
7138             this.session.nonTokenRe.lastIndex = 0;
7139         }
7141         // if at begin of the line proceed in line above
7142         if (column <= 0) {
7143             this.moveCursorTo(row, 0);
7144             this.moveCursorLeft();
7145             if (row > 0)
7146                 this.moveCursorWordLeft();
7147             return;
7148         }
7150         // move to the begin of the word
7151         if (match = this.session.tokenRe.exec(leftOfCursor)) {
7152             column -= this.session.tokenRe.lastIndex;
7153             this.session.tokenRe.lastIndex = 0;
7154         }
7156         this.moveCursorTo(row, column);
7157     };
7159     this.$shortWordEndIndex = function(rightOfCursor) {
7160         var match, index = 0, ch;
7161         var whitespaceRe = /\s/;
7162         var tokenRe = this.session.tokenRe;
7164         tokenRe.lastIndex = 0;
7165         if (match = this.session.tokenRe.exec(rightOfCursor)) {
7166             index = this.session.tokenRe.lastIndex;
7167         } else {
7168             while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
7169                 index ++;
7171             if (index <= 1) {
7172                 tokenRe.lastIndex = 0;
7173                  while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
7174                     tokenRe.lastIndex = 0;
7175                     index ++;
7176                     if (whitespaceRe.test(ch)) {
7177                         if (index > 2) {
7178                             index--
7179                             break;
7180                         } else {
7181                             while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
7182                                 index ++;
7183                             if (index > 2)
7184                                 break
7185                         }
7186                     }
7187                 }
7188             }
7189         }
7190         tokenRe.lastIndex = 0;
7192         return index;
7193     };
7195     this.moveCursorShortWordRight = function() {
7196         var row = this.lead.row;
7197         var column = this.lead.column;
7198         var line = this.doc.getLine(row);
7199         var rightOfCursor = line.substring(column);
7201         var fold = this.session.getFoldAt(row, column, 1);
7202         if (fold)
7203             return this.moveCursorTo(fold.end.row, fold.end.column);
7205         if (column == line.length) {
7206             var l = this.doc.getLength();
7207             do {    
7208                 row++;
7209                 rightOfCursor = this.doc.getLine(row)
7210             } while (row < l && /^\s*$/.test(rightOfCursor))
7211             
7212             if (!/^\s+/.test(rightOfCursor))
7213                 rightOfCursor = ""
7214             column = 0;
7215         }
7217         var index = this.$shortWordEndIndex(rightOfCursor);
7219         this.moveCursorTo(row, column + index);
7220     };
7222     this.moveCursorShortWordLeft = function() {
7223         var row = this.lead.row;
7224         var column = this.lead.column;
7226         var fold;
7227         if (fold = this.session.getFoldAt(row, column, -1))
7228             return this.moveCursorTo(fold.start.row, fold.start.column);
7230         var line = this.session.getLine(row).substring(0, column);
7231         if (column == 0) {
7232             do {    
7233                 row--;
7234                 line = this.doc.getLine(row);
7235             } while (row > 0 && /^\s*$/.test(line))
7236             
7237             column = line.length;
7238             if (!/\s+$/.test(line))
7239                 line = ""
7240         }
7242         var leftOfCursor = lang.stringReverse(line);
7243         var index = this.$shortWordEndIndex(leftOfCursor);
7245         return this.moveCursorTo(row, column - index);
7246     };
7248     this.moveCursorWordRight = function() {
7249         if (this.session.$selectLongWords)
7250             this.moveCursorLongWordRight();
7251         else
7252             this.moveCursorShortWordRight();
7253     };
7255     this.moveCursorWordLeft = function() {
7256         if (this.session.$selectLongWords)
7257             this.moveCursorLongWordLeft();
7258         else
7259             this.moveCursorShortWordLeft();
7260     };
7261     this.moveCursorBy = function(rows, chars) {
7262         var screenPos = this.session.documentToScreenPosition(
7263             this.lead.row,
7264             this.lead.column
7265         );
7267         if (chars === 0) {
7268             if (this.$desiredColumn)
7269                 screenPos.column = this.$desiredColumn;
7270             else
7271                 this.$desiredColumn = screenPos.column;
7272         }
7274         var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
7276         // move the cursor and update the desired column
7277         this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
7278     };
7279     this.moveCursorToPosition = function(position) {
7280         this.moveCursorTo(position.row, position.column);
7281     };
7282     this.moveCursorTo = function(row, column, keepDesiredColumn) {
7283         // Ensure the row/column is not inside of a fold.
7284         var fold = this.session.getFoldAt(row, column, 1);
7285         if (fold) {
7286             row = fold.start.row;
7287             column = fold.start.column;
7288         }
7290         this.$keepDesiredColumnOnChange = true;
7291         this.lead.setPosition(row, column);
7292         this.$keepDesiredColumnOnChange = false;
7294         if (!keepDesiredColumn)
7295             this.$desiredColumn = null;
7296     };
7297     this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
7298         var pos = this.session.screenToDocumentPosition(row, column);
7299         this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
7300     };
7302     // remove listeners from document
7303     this.detach = function() {
7304         this.lead.detach();
7305         this.anchor.detach();
7306         this.session = this.doc = null;
7307     }
7309     this.fromOrientedRange = function(range) {
7310         this.setSelectionRange(range, range.cursor == range.start);
7311         this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
7312     }
7314     this.toOrientedRange = function(range) {
7315         var r = this.getRange();
7316         if (range) {
7317             range.start.column = r.start.column;
7318             range.start.row = r.start.row;
7319             range.end.column = r.end.column;
7320             range.end.row = r.end.row;
7321         } else {
7322             range = r;
7323         }
7325         range.cursor = this.isBackwards() ? range.start : range.end;
7326         range.desiredColumn = this.$desiredColumn;
7327         return range;
7328     }
7330 }).call(Selection.prototype);
7332 exports.Selection = Selection;
7335 define('ace/range', ['require', 'exports', 'module' ], function(require, exports, module) {
7339  * class Range
7341  * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogus to a range, as ranges contain a starting row and starting column, and an ending row, and ending column.
7343  **/
7346  * new Range(startRow, startColumn, endRow, endColumn)
7347  * - startRow (Number): The starting row
7348  * - startColumn (Number): The starting column
7349  * - endRow (Number): The ending row
7350  * - endColumn (Number): The ending column
7352  * Creates a new `Range` object with the given starting and ending row and column points.
7354  **/
7355 var Range = function(startRow, startColumn, endRow, endColumn) {
7356     this.start = {
7357         row: startRow,
7358         column: startColumn
7359     };
7361     this.end = {
7362         row: endRow,
7363         column: endColumn
7364     };
7367 (function() {
7368     /**
7369      * Range.isEqual(range) -> Boolean
7370      * - range (Range): A range to check against
7371      *
7372      * Returns `true` if and only if the starting row and column, and ending tow and column, are equivalent to those given by `range`.
7373      *
7374      **/ 
7375     this.isEqual = function(range) {
7376         return this.start.row == range.start.row &&
7377             this.end.row == range.end.row &&
7378             this.start.column == range.start.column &&
7379             this.end.column == range.end.column
7380     }; 
7381     this.toString = function() {
7382         return ("Range: [" + this.start.row + "/" + this.start.column +
7383             "] -> [" + this.end.row + "/" + this.end.column + "]");
7384     }; 
7386     this.contains = function(row, column) {
7387         return this.compare(row, column) == 0;
7388     }; 
7389     this.compareRange = function(range) {
7390         var cmp,
7391             end = range.end,
7392             start = range.start;
7394         cmp = this.compare(end.row, end.column);
7395         if (cmp == 1) {
7396             cmp = this.compare(start.row, start.column);
7397             if (cmp == 1) {
7398                 return 2;
7399             } else if (cmp == 0) {
7400                 return 1;
7401             } else {
7402                 return 0;
7403             }
7404         } else if (cmp == -1) {
7405             return -2;
7406         } else {
7407             cmp = this.compare(start.row, start.column);
7408             if (cmp == -1) {
7409                 return -1;
7410             } else if (cmp == 1) {
7411                 return 42;
7412             } else {
7413                 return 0;
7414             }
7415         }
7416     }
7418     /** related to: Range.compare
7419      * Range.comparePoint(p) -> Number
7420      * - p (Range): A point to compare with
7421      * + (Number): This method returns one of the following numbers:<br/>
7422      * * `0` if the two points are exactly equal<br/>
7423      * * `-1` if `p.row` is less then the calling range<br/>
7424      * * `1` if `p.row` is greater than the calling range<br/>
7425      * <br/>
7426      * If the starting row of the calling range is equal to `p.row`, and:<br/>
7427      * * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
7428      * * Otherwise, it returns -1<br/>
7429      *<br/>
7430      * If the ending row of the calling range is equal to `p.row`, and:<br/>
7431      * * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
7432      * * Otherwise, it returns 1<br/>
7433      *
7434      * Checks the row and column points of `p` with the row and column points of the calling range.
7435      *
7436      * 
7437      *
7438      **/ 
7439     this.comparePoint = function(p) {
7440         return this.compare(p.row, p.column);
7441     }
7443     /** related to: Range.comparePoint
7444      * Range.containsRange(range) -> Boolean
7445      * - range (Range): A range to compare with
7446      *
7447      * Checks the start and end points of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range.
7448      *
7449      **/ 
7450     this.containsRange = function(range) {
7451         return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
7452     }
7454     /**
7455      * Range.intersects(range) -> Boolean
7456      * - range (Range): A range to compare with
7457      *
7458      * Returns `true` if passed in `range` intersects with the one calling this method.
7459      *
7460      **/
7461     this.intersects = function(range) {
7462         var cmp = this.compareRange(range);
7463         return (cmp == -1 || cmp == 0 || cmp == 1);
7464     }
7466     /**
7467      * Range.isEnd(row, column) -> Boolean
7468      * - row (Number): A row point to compare with
7469      * - column (Number): A column point to compare with
7470      *
7471      * Returns `true` if the caller's ending row point is the same as `row`, and if the caller's ending column is the same as `column`.
7472      *
7473      **/
7474     this.isEnd = function(row, column) {
7475         return this.end.row == row && this.end.column == column;
7476     }
7478     /**
7479      * Range.isStart(row, column) -> Boolean
7480      * - row (Number): A row point to compare with
7481      * - column (Number): A column point to compare with
7482      *
7483      * Returns `true` if the caller's starting row point is the same as `row`, and if the caller's starting column is the same as `column`.
7484      *
7485      **/ 
7486     this.isStart = function(row, column) {
7487         return this.start.row == row && this.start.column == column;
7488     }
7490     /**
7491      * Range.setStart(row, column)
7492      * - row (Number): A row point to set
7493      * - column (Number): A column point to set
7494      *
7495      * Sets the starting row and column for the range.
7496      *
7497      **/ 
7498     this.setStart = function(row, column) {
7499         if (typeof row == "object") {
7500             this.start.column = row.column;
7501             this.start.row = row.row;
7502         } else {
7503             this.start.row = row;
7504             this.start.column = column;
7505         }
7506     }
7508     /**
7509      * Range.setEnd(row, column)
7510      * - row (Number): A row point to set
7511      * - column (Number): A column point to set
7512      *
7513      * Sets the starting row and column for the range.
7514      *
7515      **/ 
7516     this.setEnd = function(row, column) {
7517         if (typeof row == "object") {
7518             this.end.column = row.column;
7519             this.end.row = row.row;
7520         } else {
7521             this.end.row = row;
7522             this.end.column = column;
7523         }
7524     }
7526     /** related to: Range.compare
7527      * Range.inside(row, column) -> Boolean
7528      * - row (Number): A row point to compare with
7529      * - column (Number): A column point to compare with
7530      *
7531      * Returns `true` if the `row` and `column` are within the given range.
7532      *
7533      **/ 
7534     this.inside = function(row, column) {
7535         if (this.compare(row, column) == 0) {
7536             if (this.isEnd(row, column) || this.isStart(row, column)) {
7537                 return false;
7538             } else {
7539                 return true;
7540             }
7541         }
7542         return false;
7543     }
7545     /** related to: Range.compare
7546      * Range.insideStart(row, column) -> Boolean
7547      * - row (Number): A row point to compare with
7548      * - column (Number): A column point to compare with
7549      *
7550      * Returns `true` if the `row` and `column` are within the given range's starting points.
7551      *
7552      **/ 
7553     this.insideStart = function(row, column) {
7554         if (this.compare(row, column) == 0) {
7555             if (this.isEnd(row, column)) {
7556                 return false;
7557             } else {
7558                 return true;
7559             }
7560         }
7561         return false;
7562     }
7564     /** related to: Range.compare
7565      * Range.insideEnd(row, column) -> Boolean
7566      * - row (Number): A row point to compare with
7567      * - column (Number): A column point to compare with
7568      *
7569      * Returns `true` if the `row` and `column` are within the given range's ending points.
7570      *
7571      **/ 
7572     this.insideEnd = function(row, column) {
7573         if (this.compare(row, column) == 0) {
7574             if (this.isStart(row, column)) {
7575                 return false;
7576             } else {
7577                 return true;
7578             }
7579         }
7580         return false;
7581     }
7583     /** 
7584      * Range.compare(row, column) -> Number
7585      * - row (Number): A row point to compare with
7586      * - column (Number): A column point to compare with
7587      * + (Number): This method returns one of the following numbers:<br/>
7588      * * `0` if the two points are exactly equal <br/>
7589      * * `-1` if `p.row` is less then the calling range <br/>
7590      * * `1` if `p.row` is greater than the calling range <br/>
7591      *  <br/>
7592      * If the starting row of the calling range is equal to `p.row`, and: <br/>
7593      * * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
7594      * * Otherwise, it returns -1<br/>
7595      * <br/>
7596      * If the ending row of the calling range is equal to `p.row`, and: <br/>
7597      * * `p.column` is less than or equal to the calling range's ending column, this returns `0` <br/>
7598      * * Otherwise, it returns 1
7599      *
7600      * Checks the row and column points with the row and column points of the calling range.
7601      *
7602      *
7603      **/
7604     this.compare = function(row, column) {
7605         if (!this.isMultiLine()) {
7606             if (row === this.start.row) {
7607                 return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
7608             };
7609         }
7611         if (row < this.start.row)
7612             return -1;
7614         if (row > this.end.row)
7615             return 1;
7617         if (this.start.row === row)
7618             return column >= this.start.column ? 0 : -1;
7620         if (this.end.row === row)
7621             return column <= this.end.column ? 0 : 1;
7623         return 0;
7624     };
7625     this.compareStart = function(row, column) {
7626         if (this.start.row == row && this.start.column == column) {
7627             return -1;
7628         } else {
7629             return this.compare(row, column);
7630         }
7631     }
7633     /**
7634      * Range.compareEnd(row, column) -> Number
7635      * - row (Number): A row point to compare with
7636      * - column (Number): A column point to compare with
7637      * + (Number): This method returns one of the following numbers:<br/>
7638      * * `0` if the two points are exactly equal<br/>
7639      * * `-1` if `p.row` is less then the calling range<br/>
7640      * * `1` if `p.row` is greater than the calling range, or if `isEnd` is `true.<br/>
7641      * <br/>
7642      * If the starting row of the calling range is equal to `p.row`, and:<br/>
7643      * * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
7644      * * Otherwise, it returns -1<br/>
7645      *<br/>
7646      * If the ending row of the calling range is equal to `p.row`, and:<br/>
7647      * * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
7648      * * Otherwise, it returns 1
7649      *
7650      * Checks the row and column points with the row and column points of the calling range.
7651      *
7652      *
7653      **/
7654     this.compareEnd = function(row, column) {
7655         if (this.end.row == row && this.end.column == column) {
7656             return 1;
7657         } else {
7658             return this.compare(row, column);
7659         }
7660     }
7662     /** 
7663      * Range.compareInside(row, column) -> Number
7664      * - row (Number): A row point to compare with
7665      * - column (Number): A column point to compare with
7666      * + (Number): This method returns one of the following numbers:<br/>
7667      * * `1` if the ending row of the calling range is equal to `row`, and the ending column of the calling range is equal to `column`<br/>
7668      * * `-1` if the starting row of the calling range is equal to `row`, and the starting column of the calling range is equal to `column`<br/>
7669      * <br/>
7670      * Otherwise, it returns the value after calling [[Range.compare `compare()`]].
7671      *
7672      * Checks the row and column points with the row and column points of the calling range.
7673      *
7674      *
7675      *
7676      **/
7677     this.compareInside = function(row, column) {
7678         if (this.end.row == row && this.end.column == column) {
7679             return 1;
7680         } else if (this.start.row == row && this.start.column == column) {
7681             return -1;
7682         } else {
7683             return this.compare(row, column);
7684         }
7685     }
7687     /** 
7688      * Range.clipRows(firstRow, lastRow) -> Range
7689      * - firstRow (Number): The starting row
7690      * - lastRow (Number): The ending row
7691      *
7692      * Returns the part of the current `Range` that occurs within the boundaries of `firstRow` and `lastRow` as a new `Range` object.
7693      *
7694     **/
7695     this.clipRows = function(firstRow, lastRow) {
7696         if (this.end.row > lastRow) {
7697             var end = {
7698                 row: lastRow+1,
7699                 column: 0
7700             };
7701         }
7703         if (this.start.row > lastRow) {
7704             var start = {
7705                 row: lastRow+1,
7706                 column: 0
7707             };
7708         }
7710         if (this.start.row < firstRow) {
7711             var start = {
7712                 row: firstRow,
7713                 column: 0
7714             };
7715         }
7717         if (this.end.row < firstRow) {
7718             var end = {
7719                 row: firstRow,
7720                 column: 0
7721             };
7722         }
7723         return Range.fromPoints(start || this.start, end || this.end);
7724     };
7725     this.extend = function(row, column) {
7726         var cmp = this.compare(row, column);
7728         if (cmp == 0)
7729             return this;
7730         else if (cmp == -1)
7731             var start = {row: row, column: column};
7732         else
7733             var end = {row: row, column: column};
7735         return Range.fromPoints(start || this.start, end || this.end);
7736     };
7738     this.isEmpty = function() {
7739         return (this.start.row == this.end.row && this.start.column == this.end.column);
7740     };
7741     this.isMultiLine = function() {
7742         return (this.start.row !== this.end.row);
7743     };
7744     this.clone = function() {
7745         return Range.fromPoints(this.start, this.end);
7746     };
7747     this.collapseRows = function() {
7748         if (this.end.column == 0)
7749             return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
7750         else
7751             return new Range(this.start.row, 0, this.end.row, 0)
7752     };
7753     this.toScreenRange = function(session) {
7754         var screenPosStart =
7755             session.documentToScreenPosition(this.start);
7756         var screenPosEnd =
7757             session.documentToScreenPosition(this.end);
7759         return new Range(
7760             screenPosStart.row, screenPosStart.column,
7761             screenPosEnd.row, screenPosEnd.column
7762         );
7763     };
7765 }).call(Range.prototype);
7766 Range.fromPoints = function(start, end) {
7767     return new Range(start.row, start.column, end.row, end.column);
7770 exports.Range = Range;
7773 define('ace/mode/text', ['require', 'exports', 'module' , 'ace/tokenizer', 'ace/mode/text_highlight_rules', 'ace/mode/behaviour', 'ace/unicode'], function(require, exports, module) {
7776 var Tokenizer = require("../tokenizer").Tokenizer;
7777 var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
7778 var Behaviour = require("./behaviour").Behaviour;
7779 var unicode = require("../unicode");
7781 var Mode = function() {
7782     this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
7783     this.$behaviour = new Behaviour();
7786 (function() {
7788     this.tokenRe = new RegExp("^["
7789         + unicode.packages.L
7790         + unicode.packages.Mn + unicode.packages.Mc
7791         + unicode.packages.Nd
7792         + unicode.packages.Pc + "\\$_]+", "g"
7793     );
7794     
7795     this.nonTokenRe = new RegExp("^(?:[^"
7796         + unicode.packages.L
7797         + unicode.packages.Mn + unicode.packages.Mc
7798         + unicode.packages.Nd
7799         + unicode.packages.Pc + "\\$_]|\s])+", "g"
7800     );
7802     this.getTokenizer = function() {
7803         return this.$tokenizer;
7804     };
7806     this.toggleCommentLines = function(state, doc, startRow, endRow) {
7807     };
7809     this.getNextLineIndent = function(state, line, tab) {
7810         return "";
7811     };
7813     this.checkOutdent = function(state, line, input) {
7814         return false;
7815     };
7817     this.autoOutdent = function(state, doc, row) {
7818     };
7820     this.$getIndent = function(line) {
7821         var match = line.match(/^(\s+)/);
7822         if (match) {
7823             return match[1];
7824         }
7826         return "";
7827     };
7828     
7829     this.createWorker = function(session) {
7830         return null;
7831     };
7833     this.createModeDelegates = function (mapping) {
7834         if (!this.$embeds) {
7835             return;
7836         }
7837         this.$modes = {};
7838         for (var i = 0; i < this.$embeds.length; i++) {
7839             if (mapping[this.$embeds[i]]) {
7840                 this.$modes[this.$embeds[i]] = new mapping[this.$embeds[i]]();
7841             }
7842         }
7843         
7844         var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent', 'transformAction'];
7846         for (var i = 0; i < delegations.length; i++) {
7847             (function(scope) {
7848               var functionName = delegations[i];
7849               var defaultHandler = scope[functionName];
7850               scope[delegations[i]] = function() {
7851                   return this.$delegator(functionName, arguments, defaultHandler);
7852               }
7853             } (this));
7854         }
7855     }
7856     
7857     this.$delegator = function(method, args, defaultHandler) {
7858         var state = args[0];
7859         
7860         for (var i = 0; i < this.$embeds.length; i++) {
7861             if (!this.$modes[this.$embeds[i]]) continue;
7862             
7863             var split = state.split(this.$embeds[i]);
7864             if (!split[0] && split[1]) {
7865                 args[0] = split[1];
7866                 var mode = this.$modes[this.$embeds[i]];
7867                 return mode[method].apply(mode, args);
7868             }
7869         }
7870         var ret = defaultHandler.apply(this, args);
7871         return defaultHandler ? ret : undefined;
7872     };
7873     
7874     this.transformAction = function(state, action, editor, session, param) {
7875         if (this.$behaviour) {
7876             var behaviours = this.$behaviour.getBehaviours();
7877             for (var key in behaviours) {
7878                 if (behaviours[key][action]) {
7879                     var ret = behaviours[key][action].apply(this, arguments);
7880                     if (ret) {
7881                         return ret;
7882                     }
7883                 }
7884             }
7885         }
7886     }
7887     
7888 }).call(Mode.prototype);
7890 exports.Mode = Mode;
7893 define('ace/tokenizer', ['require', 'exports', 'module' ], function(require, exports, module) {
7897  * class Tokenizer
7899  * This class takes a set of highlighting rules, and creates a tokenizer out of them. For more information, see [the wiki on extending highlighters](https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#wiki-extendingTheHighlighter).
7901  **/
7904  * new Tokenizer(rules, flag)
7905  * - rules (Object): The highlighting rules
7906  * - flag (String): Any additional regular expression flags to pass (like "i" for case insensitive)
7908  * Constructs a new tokenizer based on the given rules and flags.
7910  **/
7911 var Tokenizer = function(rules, flag) {
7912     flag = flag ? "g" + flag : "g";
7913     this.rules = rules;
7915     this.regExps = {};
7916     this.matchMappings = {};
7917     for ( var key in this.rules) {
7918         var rule = this.rules[key];
7919         var state = rule;
7920         var ruleRegExps = [];
7921         var matchTotal = 0;
7922         var mapping = this.matchMappings[key] = {};
7924         for ( var i = 0; i < state.length; i++) {
7926             if (state[i].regex instanceof RegExp)
7927                 state[i].regex = state[i].regex.toString().slice(1, -1);
7929             // Count number of matching groups. 2 extra groups from the full match
7930             // And the catch-all on the end (used to force a match);
7931             var matchcount = new RegExp("(?:(" + state[i].regex + ")|(.))").exec("a").length - 2;
7933             // Replace any backreferences and offset appropriately.
7934             var adjustedregex = state[i].regex.replace(/\\([0-9]+)/g, function (match, digit) {
7935                 return "\\" + (parseInt(digit, 10) + matchTotal + 1);
7936             });
7938             if (matchcount > 1 && state[i].token.length !== matchcount-1)
7939                 throw new Error("For " + state[i].regex + " the matching groups and length of the token array don't match (rule #" + i + " of state " + key + ")");
7941             mapping[matchTotal] = {
7942                 rule: i,
7943                 len: matchcount
7944             };
7945             matchTotal += matchcount;
7947             ruleRegExps.push(adjustedregex);
7948         }
7950         this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", flag);
7951     }
7954 (function() {
7956     /**
7957     * Tokenizer.getLineTokens() -> Object
7958     *
7959     * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state.
7960     **/
7961     this.getLineTokens = function(line, startState) {
7962         var currentState = startState || "start";
7963         var state = this.rules[currentState];
7964         var mapping = this.matchMappings[currentState];
7965         var re = this.regExps[currentState];
7966         re.lastIndex = 0;
7968         var match, tokens = [];
7970         var lastIndex = 0;
7972         var token = {
7973             type: null,
7974             value: ""
7975         };
7977         while (match = re.exec(line)) {
7978             var type = "text";
7979             var rule = null;
7980             var value = [match[0]];
7982             for (var i = 0; i < match.length-2; i++) {
7983                 if (match[i + 1] === undefined)
7984                     continue;
7986                 rule = state[mapping[i].rule];
7988                 if (mapping[i].len > 1)
7989                     value = match.slice(i+2, i+1+mapping[i].len);
7991                 // compute token type
7992                 if (typeof rule.token == "function")
7993                     type = rule.token.apply(this, value);
7994                 else
7995                     type = rule.token;
7997                 if (rule.next) {
7998                     currentState = rule.next;
7999                     state = this.rules[currentState];
8000                     mapping = this.matchMappings[currentState];
8001                     lastIndex = re.lastIndex;
8003                     re = this.regExps[currentState];
8005                     if (re === undefined) {
8006                          throw new Error("You indicated a state of " + rule.next + " to go to, but it doesn't exist!");
8007                     }
8009                     re.lastIndex = lastIndex;
8010                 }
8011                 break;
8012             }
8014             if (value[0]) {
8015                 if (typeof type == "string") {
8016                     value = [value.join("")];
8017                     type = [type];
8018                 }
8019                 for (var i = 0; i < value.length; i++) {
8020                     if (!value[i])
8021                         continue;
8023                     if ((!rule || rule.merge || type[i] === "text") && token.type === type[i]) {
8024                         token.value += value[i];
8025                     } else {
8026                         if (token.type)
8027                             tokens.push(token);
8029                         token = {
8030                             type: type[i],
8031                             value: value[i]
8032                         };
8033                     }
8034                 }
8035             }
8037             if (lastIndex == line.length)
8038                 break;
8040             lastIndex = re.lastIndex;
8041         }
8043         if (token.type)
8044             tokens.push(token);
8046         return {
8047             tokens : tokens,
8048             state : currentState
8049         };
8050     };
8052 }).call(Tokenizer.prototype);
8054 exports.Tokenizer = Tokenizer;
8057 define('ace/mode/text_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/lang'], function(require, exports, module) {
8060 var lang = require("../lib/lang");
8062 var TextHighlightRules = function() {
8064     // regexp must not have capturing parentheses
8065     // regexps are ordered -> the first match is used
8067     this.$rules = {
8068         "start" : [{
8069             token : "empty_line",
8070             regex : '^$'
8071         }, {
8072             token : "text",
8073             regex : ".+"
8074         }]
8075     };
8078 (function() {
8080     this.addRules = function(rules, prefix) {
8081         for (var key in rules) {
8082             var state = rules[key];
8083             for (var i=0; i<state.length; i++) {
8084                 var rule = state[i];
8085                 if (rule.next) {
8086                     rule.next = prefix + rule.next;
8087                 }
8088             }
8089             this.$rules[prefix + key] = state;
8090         }
8091     };
8093     this.getRules = function() {
8094         return this.$rules;
8095     };
8097     this.embedRules = function (HighlightRules, prefix, escapeRules, states) {
8098         var embedRules = new HighlightRules().getRules();
8099         if (states) {
8100             for (var i = 0; i < states.length; i++) {
8101                 states[i] = prefix + states[i];
8102             }
8103         } else {
8104             states = [];
8105             for (var key in embedRules) {
8106                 states.push(prefix + key);
8107             }
8108         }
8109         this.addRules(embedRules, prefix);
8111         for (var i = 0; i < states.length; i++) {
8112             Array.prototype.unshift.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
8113         }
8115         if (!this.$embeds) {
8116             this.$embeds = [];
8117         }
8118         this.$embeds.push(prefix);
8119     }
8121     this.getEmbeds = function() {
8122         return this.$embeds;
8123     }
8125     this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
8126         var keywords = Object.create(null);
8127         Object.keys(map).forEach(function(className) {
8128             var list = map[className].split(splitChar || "|");
8129             for (var i = list.length; i--; )
8130                 keywords[list[i]] = className;
8131         });
8132         map = null;
8133         return ignoreCase
8134             ? function(value) {return keywords[value.toLowerCase()] || defaultToken }
8135             : function(value) {return keywords[value] || defaultToken };
8136     }
8138 }).call(TextHighlightRules.prototype);
8140 exports.TextHighlightRules = TextHighlightRules;
8143 define('ace/mode/behaviour', ['require', 'exports', 'module' ], function(require, exports, module) {
8146 var Behaviour = function() {
8147    this.$behaviours = {};
8150 (function () {
8152     this.add = function (name, action, callback) {
8153         switch (undefined) {
8154           case this.$behaviours:
8155               this.$behaviours = {};
8156           case this.$behaviours[name]:
8157               this.$behaviours[name] = {};
8158         }
8159         this.$behaviours[name][action] = callback;
8160     }
8161     
8162     this.addBehaviours = function (behaviours) {
8163         for (var key in behaviours) {
8164             for (var action in behaviours[key]) {
8165                 this.add(key, action, behaviours[key][action]);
8166             }
8167         }
8168     }
8169     
8170     this.remove = function (name) {
8171         if (this.$behaviours && this.$behaviours[name]) {
8172             delete this.$behaviours[name];
8173         }
8174     }
8175     
8176     this.inherit = function (mode, filter) {
8177         if (typeof mode === "function") {
8178             var behaviours = new mode().getBehaviours(filter);
8179         } else {
8180             var behaviours = mode.getBehaviours(filter);
8181         }
8182         this.addBehaviours(behaviours);
8183     }
8184     
8185     this.getBehaviours = function (filter) {
8186         if (!filter) {
8187             return this.$behaviours;
8188         } else {
8189             var ret = {}
8190             for (var i = 0; i < filter.length; i++) {
8191                 if (this.$behaviours[filter[i]]) {
8192                     ret[filter[i]] = this.$behaviours[filter[i]];
8193                 }
8194             }
8195             return ret;
8196         }
8197     }
8199 }).call(Behaviour.prototype);
8201 exports.Behaviour = Behaviour;
8203 define('ace/unicode', ['require', 'exports', 'module' ], function(require, exports, module) {
8207 XRegExp Unicode plugin pack: Categories 1.0
8208 (c) 2010 Steven Levithan
8209 MIT License
8210 <http://xregexp.com>
8211 Uses the Unicode 5.2 character database
8213 This package for the XRegExp Unicode plugin enables the following Unicode categories (aka properties):
8215 L - Letter (the top-level Letter category is included in the Unicode plugin base script)
8216     Ll - Lowercase letter
8217     Lu - Uppercase letter
8218     Lt - Titlecase letter
8219     Lm - Modifier letter
8220     Lo - Letter without case
8221 M - Mark
8222     Mn - Non-spacing mark
8223     Mc - Spacing combining mark
8224     Me - Enclosing mark
8225 N - Number
8226     Nd - Decimal digit
8227     Nl - Letter number
8228     No -  Other number
8229 P - Punctuation
8230     Pd - Dash punctuation
8231     Ps - Open punctuation
8232     Pe - Close punctuation
8233     Pi - Initial punctuation
8234     Pf - Final punctuation
8235     Pc - Connector punctuation
8236     Po - Other punctuation
8237 S - Symbol
8238     Sm - Math symbol
8239     Sc - Currency symbol
8240     Sk - Modifier symbol
8241     So - Other symbol
8242 Z - Separator
8243     Zs - Space separator
8244     Zl - Line separator
8245     Zp - Paragraph separator
8246 C - Other
8247     Cc - Control
8248     Cf - Format
8249     Co - Private use
8250     Cs - Surrogate
8251     Cn - Unassigned
8253 Example usage:
8255     \p{N}
8256     \p{Cn}
8260 // will be populated by addUnicodePackage
8261 exports.packages = {};
8263 addUnicodePackage({
8264     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",
8265     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",
8266     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",
8267     Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
8268     Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
8269     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",
8270     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",
8271     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",
8272     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",
8273     Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
8274     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",
8275     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",
8276     Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
8277     No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
8278     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",
8279     Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
8280     Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
8281     Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
8282     Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
8283     Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
8284     Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
8285     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",
8286     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",
8287     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",
8288     Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
8289     Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
8290     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",
8291     Z:  "002000A01680180E2000-200A20282029202F205F3000",
8292     Zs: "002000A01680180E2000-200A202F205F3000",
8293     Zl: "2028",
8294     Zp: "2029",
8295     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",
8296     Cc: "0000-001F007F-009F",
8297     Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
8298     Co: "E000-F8FF",
8299     Cs: "D800-DFFF",
8300     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"
8303 function addUnicodePackage (pack) {
8304     var codePoint = /\w{4}/g;
8305     for (var name in pack)
8306         exports.packages[name] = pack[name].replace(codePoint, "\\u$&");
8311 define('ace/document', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter', 'ace/range', 'ace/anchor'], function(require, exports, module) {
8314 var oop = require("./lib/oop");
8315 var EventEmitter = require("./lib/event_emitter").EventEmitter;
8316 var Range = require("./range").Range;
8317 var Anchor = require("./anchor").Anchor;
8319  /**
8320  * new Document([text])
8321  * - text (String | Array): The starting text
8323  * Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty.
8325  **/
8327 var Document = function(text) {
8328     this.$lines = [];
8330     // There has to be one line at least in the document. If you pass an empty
8331     // string to the insert function, nothing will happen. Workaround.
8332     if (text.length == 0) {
8333         this.$lines = [""];
8334     } else if (Array.isArray(text)) {
8335         this.insertLines(0, text);
8336     } else {
8337         this.insert({row: 0, column:0}, text);
8338     }
8341 (function() {
8343     oop.implement(this, EventEmitter);
8344     this.setValue = function(text) {
8345         var len = this.getLength();
8346         this.remove(new Range(0, 0, len, this.getLine(len-1).length));
8347         this.insert({row: 0, column:0}, text);
8348     };
8349     this.getValue = function() {
8350         return this.getAllLines().join(this.getNewLineCharacter());
8351     };
8352     this.createAnchor = function(row, column) {
8353         return new Anchor(this, row, column);
8354     };
8356     // check for IE split bug
8357     if ("aaa".split(/a/).length == 0)
8358         this.$split = function(text) {
8359             return text.replace(/\r\n|\r/g, "\n").split("\n");
8360         }
8361     else
8362         this.$split = function(text) {
8363             return text.split(/\r\n|\r|\n/);
8364         };
8365     this.$detectNewLine = function(text) {
8366         var match = text.match(/^.*?(\r\n|\r|\n)/m);
8367         if (match) {
8368             this.$autoNewLine = match[1];
8369         } else {
8370             this.$autoNewLine = "\n";
8371         }
8372     };
8373     this.getNewLineCharacter = function() {
8374       switch (this.$newLineMode) {
8375           case "windows":
8376               return "\r\n";
8378           case "unix":
8379               return "\n";
8381           case "auto":
8382               return this.$autoNewLine;
8383       }
8384     };
8386     this.$autoNewLine = "\n";
8387     this.$newLineMode = "auto";
8388     this.setNewLineMode = function(newLineMode) {
8389         if (this.$newLineMode === newLineMode)
8390             return;
8392         this.$newLineMode = newLineMode;
8393     };
8394     this.getNewLineMode = function() {
8395         return this.$newLineMode;
8396     };
8397     this.isNewLine = function(text) {
8398         return (text == "\r\n" || text == "\r" || text == "\n");
8399     };
8400     this.getLine = function(row) {
8401         return this.$lines[row] || "";
8402     };
8403     this.getLines = function(firstRow, lastRow) {
8404         return this.$lines.slice(firstRow, lastRow + 1);
8405     };
8406     this.getAllLines = function() {
8407         return this.getLines(0, this.getLength());
8408     };
8409     this.getLength = function() {
8410         return this.$lines.length;
8411     };
8412     this.getTextRange = function(range) {
8413         if (range.start.row == range.end.row) {
8414             return this.$lines[range.start.row].substring(range.start.column,
8415                                                          range.end.column);
8416         }
8417         else {
8418             var lines = this.getLines(range.start.row+1, range.end.row-1);
8419             lines.unshift((this.$lines[range.start.row] || "").substring(range.start.column));
8420             lines.push((this.$lines[range.end.row] || "").substring(0, range.end.column));
8421             return lines.join(this.getNewLineCharacter());
8422         }
8423     };
8424     this.$clipPosition = function(position) {
8425         var length = this.getLength();
8426         if (position.row >= length) {
8427             position.row = Math.max(0, length - 1);
8428             position.column = this.getLine(length-1).length;
8429         }
8430         return position;
8431     };
8432     this.insert = function(position, text) {
8433         if (!text || text.length === 0)
8434             return position;
8436         position = this.$clipPosition(position);
8438         // only detect new lines if the document has no line break yet
8439         if (this.getLength() <= 1)
8440             this.$detectNewLine(text);
8442         var lines = this.$split(text);
8443         var firstLine = lines.splice(0, 1)[0];
8444         var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
8446         position = this.insertInLine(position, firstLine);
8447         if (lastLine !== null) {
8448             position = this.insertNewLine(position); // terminate first line
8449             position = this.insertLines(position.row, lines);
8450             position = this.insertInLine(position, lastLine || "");
8451         }
8452         return position;
8453     };
8454     /**
8455      * Document@change(e)
8456      * - e (Object): Contains at least one property called `"action"`. `"action"` indicates the action that triggered the change. Each action also has a set of additional properties.
8457      *
8458      * Fires whenever the document changes.
8459      *
8460      * Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available:
8461      *
8462      *  * `"insertLines"` (emitted by [[Document.insertLines]])
8463      *    * `range`: the [[Range]] of the change within the document
8464      *    * `lines`: the lines in the document that are changing
8465      *  * `"insertText"` (emitted by [[Document.insertNewLine]])
8466      *    * `range`: the [[Range]] of the change within the document
8467      *    * `text`: the text that's being added
8468      *  * `"removeLines"` (emitted by [[Document.insertLines]])
8469      *    * `range`: the [[Range]] of the change within the document
8470      *    * `lines`: the lines in the document that were removed
8471      *    * `nl`: the new line character (as defined by [[Document.getNewLineCharacter]])
8472      *  * `"removeText"` (emitted by [[Document.removeInLine]] and [[Document.removeNewLine]])
8473      *    * `range`: the [[Range]] of the change within the document
8474      *    * `text`: the text that's being removed
8475      *
8476      **/
8477     this.insertLines = function(row, lines) {
8478         if (lines.length == 0)
8479             return {row: row, column: 0};
8481         // apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF)
8482         // to circumvent that we have to break huge inserts into smaller chunks here
8483         if (lines.length > 0xFFFF) {
8484             var end = this.insertLines(row, lines.slice(0xFFFF));
8485             lines = lines.slice(0, 0xFFFF);
8486         }
8488         var args = [row, 0];
8489         args.push.apply(args, lines);
8490         this.$lines.splice.apply(this.$lines, args);
8492         var range = new Range(row, 0, row + lines.length, 0);
8493         var delta = {
8494             action: "insertLines",
8495             range: range,
8496             lines: lines
8497         };
8498         this._emit("change", { data: delta });
8499         return end || range.end;
8500     };
8501     this.insertNewLine = function(position) {
8502         position = this.$clipPosition(position);
8503         var line = this.$lines[position.row] || "";
8505         this.$lines[position.row] = line.substring(0, position.column);
8506         this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
8508         var end = {
8509             row : position.row + 1,
8510             column : 0
8511         };
8513         var delta = {
8514             action: "insertText",
8515             range: Range.fromPoints(position, end),
8516             text: this.getNewLineCharacter()
8517         };
8518         this._emit("change", { data: delta });
8520         return end;
8521     };
8522     this.insertInLine = function(position, text) {
8523         if (text.length == 0)
8524             return position;
8526         var line = this.$lines[position.row] || "";
8528         this.$lines[position.row] = line.substring(0, position.column) + text
8529                 + line.substring(position.column);
8531         var end = {
8532             row : position.row,
8533             column : position.column + text.length
8534         };
8536         var delta = {
8537             action: "insertText",
8538             range: Range.fromPoints(position, end),
8539             text: text
8540         };
8541         this._emit("change", { data: delta });
8543         return end;
8544     };
8545     this.remove = function(range) {
8546         // clip to document
8547         range.start = this.$clipPosition(range.start);
8548         range.end = this.$clipPosition(range.end);
8550         if (range.isEmpty())
8551             return range.start;
8553         var firstRow = range.start.row;
8554         var lastRow = range.end.row;
8556         if (range.isMultiLine()) {
8557             var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
8558             var lastFullRow = lastRow - 1;
8560             if (range.end.column > 0)
8561                 this.removeInLine(lastRow, 0, range.end.column);
8563             if (lastFullRow >= firstFullRow)
8564                 this.removeLines(firstFullRow, lastFullRow);
8566             if (firstFullRow != firstRow) {
8567                 this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
8568                 this.removeNewLine(range.start.row);
8569             }
8570         }
8571         else {
8572             this.removeInLine(firstRow, range.start.column, range.end.column);
8573         }
8574         return range.start;
8575     };
8576     this.removeInLine = function(row, startColumn, endColumn) {
8577         if (startColumn == endColumn)
8578             return;
8580         var range = new Range(row, startColumn, row, endColumn);
8581         var line = this.getLine(row);
8582         var removed = line.substring(startColumn, endColumn);
8583         var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
8584         this.$lines.splice(row, 1, newLine);
8586         var delta = {
8587             action: "removeText",
8588             range: range,
8589             text: removed
8590         };
8591         this._emit("change", { data: delta });
8592         return range.start;
8593     };
8594     this.removeLines = function(firstRow, lastRow) {
8595         var range = new Range(firstRow, 0, lastRow + 1, 0);
8596         var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
8598         var delta = {
8599             action: "removeLines",
8600             range: range,
8601             nl: this.getNewLineCharacter(),
8602             lines: removed
8603         };
8604         this._emit("change", { data: delta });
8605         return removed;
8606     };
8607     this.removeNewLine = function(row) {
8608         var firstLine = this.getLine(row);
8609         var secondLine = this.getLine(row+1);
8611         var range = new Range(row, firstLine.length, row+1, 0);
8612         var line = firstLine + secondLine;
8614         this.$lines.splice(row, 2, line);
8616         var delta = {
8617             action: "removeText",
8618             range: range,
8619             text: this.getNewLineCharacter()
8620         };
8621         this._emit("change", { data: delta });
8622     };
8623     this.replace = function(range, text) {
8624         if (text.length == 0 && range.isEmpty())
8625             return range.start;
8627         // Shortcut: If the text we want to insert is the same as it is already
8628         // in the document, we don't have to replace anything.
8629         if (text == this.getTextRange(range))
8630             return range.end;
8632         this.remove(range);
8633         if (text) {
8634             var end = this.insert(range.start, text);
8635         }
8636         else {
8637             end = range.start;
8638         }
8640         return end;
8641     };
8642     this.applyDeltas = function(deltas) {
8643         for (var i=0; i<deltas.length; i++) {
8644             var delta = deltas[i];
8645             var range = Range.fromPoints(delta.range.start, delta.range.end);
8647             if (delta.action == "insertLines")
8648                 this.insertLines(range.start.row, delta.lines);
8649             else if (delta.action == "insertText")
8650                 this.insert(range.start, delta.text);
8651             else if (delta.action == "removeLines")
8652                 this.removeLines(range.start.row, range.end.row - 1);
8653             else if (delta.action == "removeText")
8654                 this.remove(range);
8655         }
8656     };
8657     this.revertDeltas = function(deltas) {
8658         for (var i=deltas.length-1; i>=0; i--) {
8659             var delta = deltas[i];
8661             var range = Range.fromPoints(delta.range.start, delta.range.end);
8663             if (delta.action == "insertLines")
8664                 this.removeLines(range.start.row, range.end.row - 1);
8665             else if (delta.action == "insertText")
8666                 this.remove(range);
8667             else if (delta.action == "removeLines")
8668                 this.insertLines(range.start.row, delta.lines);
8669             else if (delta.action == "removeText")
8670                 this.insert(range.start, delta.text);
8671         }
8672     };
8674 }).call(Document.prototype);
8676 exports.Document = Document;
8679 define('ace/anchor', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
8682 var oop = require("./lib/oop");
8683 var EventEmitter = require("./lib/event_emitter").EventEmitter;
8686  * new Anchor(doc, row, column)
8687  * - doc (Document): The document to associate with the anchor
8688  * - row (Number): The starting row position
8689  * - column (Number): The starting column position
8691  * Creates a new `Anchor` and associates it with a document.
8693  **/
8695 var Anchor = exports.Anchor = function(doc, row, column) {
8696     this.document = doc;
8697     
8698     if (typeof column == "undefined")
8699         this.setPosition(row.row, row.column);
8700     else
8701         this.setPosition(row, column);
8703     this.$onChange = this.onChange.bind(this);
8704     doc.on("change", this.$onChange);
8707 (function() {
8709     oop.implement(this, EventEmitter);
8711     this.getPosition = function() {
8712         return this.$clipPositionToDocument(this.row, this.column);
8713     };
8714         
8715     this.getDocument = function() {
8716         return this.document;
8717     };
8719     this.onChange = function(e) {
8720         var delta = e.data;
8721         var range = delta.range;
8722             
8723         if (range.start.row == range.end.row && range.start.row != this.row)
8724             return;
8725             
8726         if (range.start.row > this.row)
8727             return;
8728             
8729         if (range.start.row == this.row && range.start.column > this.column)
8730             return;
8731     
8732         var row = this.row;
8733         var column = this.column;
8734         
8735         if (delta.action === "insertText") {
8736             if (range.start.row === row && range.start.column <= column) {
8737                 if (range.start.row === range.end.row) {
8738                     column += range.end.column - range.start.column;
8739                 }
8740                 else {
8741                     column -= range.start.column;
8742                     row += range.end.row - range.start.row;
8743                 }
8744             }
8745             else if (range.start.row !== range.end.row && range.start.row < row) {
8746                 row += range.end.row - range.start.row;
8747             }
8748         } else if (delta.action === "insertLines") {
8749             if (range.start.row <= row) {
8750                 row += range.end.row - range.start.row;
8751             }
8752         }
8753         else if (delta.action == "removeText") {
8754             if (range.start.row == row && range.start.column < column) {
8755                 if (range.end.column >= column)
8756                     column = range.start.column;
8757                 else
8758                     column = Math.max(0, column - (range.end.column - range.start.column));
8759                 
8760             } else if (range.start.row !== range.end.row && range.start.row < row) {
8761                 if (range.end.row == row) {
8762                     column = Math.max(0, column - range.end.column) + range.start.column;
8763                 }
8764                 row -= (range.end.row - range.start.row);
8765             }
8766             else if (range.end.row == row) {
8767                 row -= range.end.row - range.start.row;
8768                 column = Math.max(0, column - range.end.column) + range.start.column;
8769             }
8770         } else if (delta.action == "removeLines") {
8771             if (range.start.row <= row) {
8772                 if (range.end.row <= row)
8773                     row -= range.end.row - range.start.row;
8774                 else {
8775                     row = range.start.row;
8776                     column = 0;
8777                 }
8778             }
8779         }
8781         this.setPosition(row, column, true);
8782     };
8784     this.setPosition = function(row, column, noClip) {
8785         var pos;
8786         if (noClip) {
8787             pos = {
8788                 row: row,
8789                 column: column
8790             };
8791         }
8792         else {
8793             pos = this.$clipPositionToDocument(row, column);
8794         }
8795         
8796         if (this.row == pos.row && this.column == pos.column)
8797             return;
8798             
8799         var old = {
8800             row: this.row,
8801             column: this.column
8802         };
8803         
8804         this.row = pos.row;
8805         this.column = pos.column;
8806         this._emit("change", {
8807             old: old,
8808             value: pos
8809         });
8810     };
8812     this.detach = function() {
8813         this.document.removeEventListener("change", this.$onChange);
8814     };
8816     this.$clipPositionToDocument = function(row, column) {
8817         var pos = {};
8818     
8819         if (row >= this.document.getLength()) {
8820             pos.row = Math.max(0, this.document.getLength() - 1);
8821             pos.column = this.document.getLine(pos.row).length;
8822         }
8823         else if (row < 0) {
8824             pos.row = 0;
8825             pos.column = 0;
8826         }
8827         else {
8828             pos.row = row;
8829             pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
8830         }
8831         
8832         if (column < 0)
8833             pos.column = 0;
8834             
8835         return pos;
8836     };
8837     
8838 }).call(Anchor.prototype);
8842 define('ace/background_tokenizer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
8845 var oop = require("./lib/oop");
8846 var EventEmitter = require("./lib/event_emitter").EventEmitter;
8848 // tokenizing lines longer than this makes editor very slow
8849 var MAX_LINE_LENGTH = 5000;
8852  * new BackgroundTokenizer(tokenizer, editor)
8853  * - tokenizer (Tokenizer): The tokenizer to use
8854  * - editor (Editor): The editor to associate with
8856  * Creates a new `BackgroundTokenizer` object.
8859  **/
8861 var BackgroundTokenizer = function(tokenizer, editor) {
8862     this.running = false;
8863     this.lines = [];
8864     this.states = [];
8865     this.currentLine = 0;
8866     this.tokenizer = tokenizer;
8868     var self = this;
8870     this.$worker = function() {
8871         if (!self.running) { return; }
8873         var workerStart = new Date();
8874         var startLine = self.currentLine;
8875         var doc = self.doc;
8877         var processedLines = 0;
8879         var len = doc.getLength();
8880         while (self.currentLine < len) {
8881             self.$tokenizeRow(self.currentLine);
8882             while (self.lines[self.currentLine])
8883                 self.currentLine++;
8885             // only check every 5 lines
8886             processedLines ++;
8887             if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
8888                 self.fireUpdateEvent(startLine, self.currentLine-1);
8889                 self.running = setTimeout(self.$worker, 20);
8890                 return;
8891             }
8892         }
8894         self.running = false;
8896         self.fireUpdateEvent(startLine, len - 1);
8897     };
8900 (function(){
8902     oop.implement(this, EventEmitter);
8903     this.setTokenizer = function(tokenizer) {
8904         this.tokenizer = tokenizer;
8905         this.lines = [];
8906         this.states = [];
8908         this.start(0);
8909     };
8910     this.setDocument = function(doc) {
8911         this.doc = doc;
8912         this.lines = [];
8913         this.states = [];
8915         this.stop();
8916     };
8917      /**
8918      * BackgroundTokenizer@update(e)
8919      * - e (Object): An object containing two properties, `first` and `last`, which indicate the rows of the region being updated.
8920      *
8921      * Fires whenever the background tokeniziers between a range of rows are going to be updated.
8922      *
8923      **/
8924     this.fireUpdateEvent = function(firstRow, lastRow) {
8925         var data = {
8926             first: firstRow,
8927             last: lastRow
8928         };
8929         this._emit("update", {data: data});
8930     };
8931     this.start = function(startRow) {
8932         this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
8934         // remove all cached items below this line
8935         this.lines.splice(this.currentLine, this.lines.length);
8936         this.states.splice(this.currentLine, this.states.length);
8938         this.stop();
8939         // pretty long delay to prevent the tokenizer from interfering with the user
8940         this.running = setTimeout(this.$worker, 700);
8941     };
8943     this.$updateOnChange = function(delta) {
8944         var range = delta.range;
8945         var startRow = range.start.row;
8946         var len = range.end.row - startRow;
8948         if (len === 0) {
8949             this.lines[startRow] = null;
8950         } else if (delta.action == "removeText" || delta.action == "removeLines") {
8951             this.lines.splice(startRow, len + 1, null);
8952             this.states.splice(startRow, len + 1, null);
8953         } else {
8954             var args = Array(len + 1);
8955             args.unshift(startRow, 1);
8956             this.lines.splice.apply(this.lines, args);
8957             this.states.splice.apply(this.states, args);
8958         }
8960         this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
8962         this.stop();
8963         // pretty long delay to prevent the tokenizer from interfering with the user
8964         this.running = setTimeout(this.$worker, 700);
8965     };
8966     this.stop = function() {
8967         if (this.running)
8968             clearTimeout(this.running);
8969         this.running = false;
8970     };
8971     this.getTokens = function(row) {
8972         return this.lines[row] || this.$tokenizeRow(row);
8973     };
8974     this.getState = function(row) {
8975         if (this.currentLine == row)
8976             this.$tokenizeRow(row);
8977         return this.states[row] || "start";
8978     };
8980     this.$tokenizeRow = function(row) {
8981         var line = this.doc.getLine(row);
8982         var state = this.states[row - 1];
8984         if (line.length > MAX_LINE_LENGTH) {
8985             var overflow = {value: line.substr(MAX_LINE_LENGTH), type: "text"};
8986             line = line.slice(0, MAX_LINE_LENGTH);
8987         }
8988         var data = this.tokenizer.getLineTokens(line, state);
8989         if (overflow) {
8990             data.tokens.push(overflow);
8991             data.state = "start";
8992         }
8994         if (this.states[row] !== data.state) {
8995             this.states[row] = data.state;
8996             this.lines[row + 1] = null;
8997             if (this.currentLine > row + 1)
8998                 this.currentLine = row + 1;
8999         } else if (this.currentLine == row) {
9000             this.currentLine = row + 1;
9001         }
9003         return this.lines[row] = data.tokens;
9004     };
9006 }).call(BackgroundTokenizer.prototype);
9008 exports.BackgroundTokenizer = BackgroundTokenizer;
9011 define('ace/search_highlight', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/lib/oop', 'ace/range'], function(require, exports, module) {
9014 var lang = require("./lib/lang");
9015 var oop = require("./lib/oop");
9016 var Range = require("./range").Range;
9018 var SearchHighlight = function(regExp, clazz, type) {
9019     this.setRegexp(regExp);
9020     this.clazz = clazz;
9021     this.type = type || "text";
9024 (function() {
9025     this.setRegexp = function(regExp) {
9026         if (this.regExp+"" == regExp+"")
9027             return;
9028         this.regExp = regExp;
9029         this.cache = [];
9030     };
9032     this.update = function(html, markerLayer, session, config) {
9033         if (!this.regExp)
9034             return;
9035         var start = config.firstRow, end = config.lastRow;
9037         for (var i = start; i <= end; i++) {
9038             var ranges = this.cache[i];
9039             if (ranges == null) {
9040                 ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
9041                 ranges = ranges.map(function(match) {
9042                     return new Range(i, match.offset, i, match.offset + match.length);
9043                 });
9044                 this.cache[i] = ranges.length ? ranges : "";
9045             }
9047             for (var j = ranges.length; j --; ) {
9048                 markerLayer.drawSingleLineMarker(
9049                     html, ranges[j].toScreenRange(session), this.clazz, config,
9050                     null, this.type
9051                 );
9052             }
9053         }
9054     };
9056 }).call(SearchHighlight.prototype);
9058 exports.SearchHighlight = SearchHighlight;
9061 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) {
9064 var Range = require("../range").Range;
9065 var FoldLine = require("./fold_line").FoldLine;
9066 var Fold = require("./fold").Fold;
9067 var TokenIterator = require("../token_iterator").TokenIterator;
9069 function Folding() {
9070     /*
9071      * Looks up a fold at a given row/column. Possible values for side:
9072      *   -1: ignore a fold if fold.start = row/column
9073      *   +1: ignore a fold if fold.end = row/column
9074      */
9075     this.getFoldAt = function(row, column, side) {
9076         var foldLine = this.getFoldLine(row);
9077         if (!foldLine)
9078             return null;
9080         var folds = foldLine.folds;
9081         for (var i = 0; i < folds.length; i++) {
9082             var fold = folds[i];
9083             if (fold.range.contains(row, column)) {
9084                 if (side == 1 && fold.range.isEnd(row, column)) {
9085                     continue;
9086                 } else if (side == -1 && fold.range.isStart(row, column)) {
9087                     continue;
9088                 }
9089                 return fold;
9090             }
9091         }
9092     };
9093     this.getFoldsInRange = function(range) {
9094         range = range.clone();
9095         var start = range.start;
9096         var end = range.end;
9097         var foldLines = this.$foldData;
9098         var foundFolds = [];
9100         start.column += 1;
9101         end.column -= 1;
9103         for (var i = 0; i < foldLines.length; i++) {
9104             var cmp = foldLines[i].range.compareRange(range);
9105             if (cmp == 2) {
9106                 // Range is before foldLine. No intersection. This means,
9107                 // there might be other foldLines that intersect.
9108                 continue;
9109             }
9110             else if (cmp == -2) {
9111                 // Range is after foldLine. There can't be any other foldLines then,
9112                 // so let's give up.
9113                 break;
9114             }
9116             var folds = foldLines[i].folds;
9117             for (var j = 0; j < folds.length; j++) {
9118                 var fold = folds[j];
9119                 cmp = fold.range.compareRange(range);
9120                 if (cmp == -2) {
9121                     break;
9122                 } else if (cmp == 2) {
9123                     continue;
9124                 } else
9125                 // WTF-state: Can happen due to -1/+1 to start/end column.
9126                 if (cmp == 42) {
9127                     break;
9128                 }
9129                 foundFolds.push(fold);
9130             }
9131         }
9132         return foundFolds;
9133     };
9134     this.getAllFolds = function() {
9135         var folds = [];
9136         var foldLines = this.$foldData;
9137         
9138         function addFold(fold) {
9139             folds.push(fold);
9140             if (!fold.subFolds)
9141                 return;
9142                 
9143             for (var i = 0; i < fold.subFolds.length; i++)
9144                 addFold(fold.subFolds[i]);
9145         }
9146         
9147         for (var i = 0; i < foldLines.length; i++)
9148             for (var j = 0; j < foldLines[i].folds.length; j++)
9149                 addFold(foldLines[i].folds[j]);
9151         return folds;
9152     };
9153     this.getFoldStringAt = function(row, column, trim, foldLine) {
9154         foldLine = foldLine || this.getFoldLine(row);
9155         if (!foldLine)
9156             return null;
9158         var lastFold = {
9159             end: { column: 0 }
9160         };
9161         // TODO: Refactor to use getNextFoldTo function.
9162         var str, fold;
9163         for (var i = 0; i < foldLine.folds.length; i++) {
9164             fold = foldLine.folds[i];
9165             var cmp = fold.range.compareEnd(row, column);
9166             if (cmp == -1) {
9167                 str = this
9168                     .getLine(fold.start.row)
9169                     .substring(lastFold.end.column, fold.start.column);
9170                 break;
9171             }
9172             else if (cmp === 0) {
9173                 return null;
9174             }
9175             lastFold = fold;
9176         }
9177         if (!str)
9178             str = this.getLine(fold.start.row).substring(lastFold.end.column);
9180         if (trim == -1)
9181             return str.substring(0, column - lastFold.end.column);
9182         else if (trim == 1)
9183             return str.substring(column - lastFold.end.column);
9184         else
9185             return str;
9186     };
9188     this.getFoldLine = function(docRow, startFoldLine) {
9189         var foldData = this.$foldData;
9190         var i = 0;
9191         if (startFoldLine)
9192             i = foldData.indexOf(startFoldLine);
9193         if (i == -1)
9194             i = 0;
9195         for (i; i < foldData.length; i++) {
9196             var foldLine = foldData[i];
9197             if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
9198                 return foldLine;
9199             } else if (foldLine.end.row > docRow) {
9200                 return null;
9201             }
9202         }
9203         return null;
9204     };
9206     // returns the fold which starts after or contains docRow
9207     this.getNextFoldLine = function(docRow, startFoldLine) {
9208         var foldData = this.$foldData;
9209         var i = 0;
9210         if (startFoldLine)
9211             i = foldData.indexOf(startFoldLine);
9212         if (i == -1)
9213             i = 0;
9214         for (i; i < foldData.length; i++) {
9215             var foldLine = foldData[i];
9216             if (foldLine.end.row >= docRow) {
9217                 return foldLine;
9218             }
9219         }
9220         return null;
9221     };
9223     this.getFoldedRowCount = function(first, last) {
9224         var foldData = this.$foldData, rowCount = last-first+1;
9225         for (var i = 0; i < foldData.length; i++) {
9226             var foldLine = foldData[i],
9227                 end = foldLine.end.row,
9228                 start = foldLine.start.row;
9229             if (end >= last) {
9230                 if(start < last) {
9231                     if(start >= first)
9232                         rowCount -= last-start;
9233                     else
9234                         rowCount = 0;//in one fold
9235                 }
9236                 break;
9237             } else if(end >= first){
9238                 if (start >= first) //fold inside range
9239                     rowCount -=  end-start;
9240                 else
9241                     rowCount -=  end-first+1;
9242             }
9243         }
9244         return rowCount;
9245     };
9247     this.$addFoldLine = function(foldLine) {
9248         this.$foldData.push(foldLine);
9249         this.$foldData.sort(function(a, b) {
9250             return a.start.row - b.start.row;
9251         });
9252         return foldLine;
9253     };
9254     this.addFold = function(placeholder, range) {
9255         var foldData = this.$foldData;
9256         var added = false;
9257         var fold;
9258         
9259         if (placeholder instanceof Fold)
9260             fold = placeholder;
9261         else
9262             fold = new Fold(range, placeholder);
9264         this.$clipRangeToDocument(fold.range);
9266         var startRow = fold.start.row;
9267         var startColumn = fold.start.column;
9268         var endRow = fold.end.row;
9269         var endColumn = fold.end.column;
9271         // --- Some checking ---
9272         if (fold.placeholder.length < 2)
9273             throw "Placeholder has to be at least 2 characters";
9275         if (startRow == endRow && endColumn - startColumn < 2)
9276             throw "The range has to be at least 2 characters width";
9278         var startFold = this.getFoldAt(startRow, startColumn, 1);
9279         var endFold = this.getFoldAt(endRow, endColumn, -1);
9280         if (startFold && endFold == startFold)
9281             return startFold.addSubFold(fold);
9283         if (
9284             (startFold && !startFold.range.isStart(startRow, startColumn))
9285             || (endFold && !endFold.range.isEnd(endRow, endColumn))
9286         ) {
9287             throw "A fold can't intersect already existing fold" + fold.range + startFold.range;
9288         }
9290         // Check if there are folds in the range we create the new fold for.
9291         var folds = this.getFoldsInRange(fold.range);
9292         if (folds.length > 0) {
9293             // Remove the folds from fold data.
9294             this.removeFolds(folds);
9295             // Add the removed folds as subfolds on the new fold.
9296             fold.subFolds = folds;
9297         }
9299         for (var i = 0; i < foldData.length; i++) {
9300             var foldLine = foldData[i];
9301             if (endRow == foldLine.start.row) {
9302                 foldLine.addFold(fold);
9303                 added = true;
9304                 break;
9305             }
9306             else if (startRow == foldLine.end.row) {
9307                 foldLine.addFold(fold);
9308                 added = true;
9309                 if (!fold.sameRow) {
9310                     // Check if we might have to merge two FoldLines.
9311                     var foldLineNext = foldData[i + 1];
9312                     if (foldLineNext && foldLineNext.start.row == endRow) {
9313                         // We need to merge!
9314                         foldLine.merge(foldLineNext);
9315                         break;
9316                     }
9317                 }
9318                 break;
9319             }
9320             else if (endRow <= foldLine.start.row) {
9321                 break;
9322             }
9323         }
9325         if (!added)
9326             foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
9328         if (this.$useWrapMode)
9329             this.$updateWrapData(foldLine.start.row, foldLine.start.row);
9330         else
9331             this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
9333         // Notify that fold data has changed.
9334         this.$modified = true;
9335         this._emit("changeFold", { data: fold });
9337         return fold;
9338     };
9340     this.addFolds = function(folds) {
9341         folds.forEach(function(fold) {
9342             this.addFold(fold);
9343         }, this);
9344     };
9346     this.removeFold = function(fold) {
9347         var foldLine = fold.foldLine;
9348         var startRow = foldLine.start.row;
9349         var endRow = foldLine.end.row;
9351         var foldLines = this.$foldData;
9352         var folds = foldLine.folds;
9353         // Simple case where there is only one fold in the FoldLine such that
9354         // the entire fold line can get removed directly.
9355         if (folds.length == 1) {
9356             foldLines.splice(foldLines.indexOf(foldLine), 1);
9357         } else
9358         // If the fold is the last fold of the foldLine, just remove it.
9359         if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
9360             folds.pop();
9361             foldLine.end.row = folds[folds.length - 1].end.row;
9362             foldLine.end.column = folds[folds.length - 1].end.column;
9363         } else
9364         // If the fold is the first fold of the foldLine, just remove it.
9365         if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
9366             folds.shift();
9367             foldLine.start.row = folds[0].start.row;
9368             foldLine.start.column = folds[0].start.column;
9369         } else
9370         // We know there are more then 2 folds and the fold is not at the edge.
9371         // This means, the fold is somewhere in between.
9372         //
9373         // If the fold is in one row, we just can remove it.
9374         if (fold.sameRow) {
9375             folds.splice(folds.indexOf(fold), 1);
9376         } else
9377         // The fold goes over more then one row. This means remvoing this fold
9378         // will cause the fold line to get splitted up. newFoldLine is the second part
9379         {
9380             var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
9381             folds = newFoldLine.folds;
9382             folds.shift();
9383             newFoldLine.start.row = folds[0].start.row;
9384             newFoldLine.start.column = folds[0].start.column;
9385         }
9387         if (this.$useWrapMode)
9388             this.$updateWrapData(startRow, endRow);
9389         else
9390             this.$updateRowLengthCache(startRow, endRow);
9392         // Notify that fold data has changed.
9393         this.$modified = true;
9394         this._emit("changeFold", { data: fold });
9395     };
9397     this.removeFolds = function(folds) {
9398         // We need to clone the folds array passed in as it might be the folds
9399         // array of a fold line and as we call this.removeFold(fold), folds
9400         // are removed from folds and changes the current index.
9401         var cloneFolds = [];
9402         for (var i = 0; i < folds.length; i++) {
9403             cloneFolds.push(folds[i]);
9404         }
9406         cloneFolds.forEach(function(fold) {
9407             this.removeFold(fold);
9408         }, this);
9409         this.$modified = true;
9410     };
9412     this.expandFold = function(fold) {
9413         this.removeFold(fold);
9414         fold.subFolds.forEach(function(fold) {
9415             this.addFold(fold);
9416         }, this);
9417         fold.subFolds = [];
9418     };
9420     this.expandFolds = function(folds) {
9421         folds.forEach(function(fold) {
9422             this.expandFold(fold);
9423         }, this);
9424     };
9426     this.unfold = function(location, expandInner) {
9427         var range, folds;
9428         if (location == null)
9429             range = new Range(0, 0, this.getLength(), 0);
9430         else if (typeof location == "number")
9431             range = new Range(location, 0, location, this.getLine(location).length);
9432         else if ("row" in location)
9433             range = Range.fromPoints(location, location);
9434         else
9435             range = location;
9437         folds = this.getFoldsInRange(range);
9438         if (expandInner) {
9439             this.removeFolds(folds);
9440         } else {
9441             // TODO: might need to remove and add folds in one go instead of using
9442             // expandFolds several times.
9443             while (folds.length) {
9444                 this.expandFolds(folds);
9445                 folds = this.getFoldsInRange(range);
9446             }
9447         }
9448     };
9449     this.isRowFolded = function(docRow, startFoldRow) {
9450         return !!this.getFoldLine(docRow, startFoldRow);
9451     };
9453     this.getRowFoldEnd = function(docRow, startFoldRow) {
9454         var foldLine = this.getFoldLine(docRow, startFoldRow);
9455         return foldLine ? foldLine.end.row : docRow;
9456     };
9458     this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
9459         if (startRow == null) {
9460             startRow = foldLine.start.row;
9461             startColumn = 0;
9462         }
9464         if (endRow == null) {
9465             endRow = foldLine.end.row;
9466             endColumn = this.getLine(endRow).length;
9467         }
9469         // Build the textline using the FoldLine walker.
9470         var doc = this.doc;
9471         var textLine = "";
9473         foldLine.walk(function(placeholder, row, column, lastColumn) {
9474             if (row < startRow) {
9475                 return;
9476             } else if (row == startRow) {
9477                 if (column < startColumn) {
9478                     return;
9479                 }
9480                 lastColumn = Math.max(startColumn, lastColumn);
9481             }
9482             if (placeholder) {
9483                 textLine += placeholder;
9484             } else {
9485                 textLine += doc.getLine(row).substring(lastColumn, column);
9486             }
9487         }.bind(this), endRow, endColumn);
9488         return textLine;
9489     };
9491     this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
9492         var foldLine = this.getFoldLine(row);
9494         if (!foldLine) {
9495             var line;
9496             line = this.doc.getLine(row);
9497             return line.substring(startColumn || 0, endColumn || line.length);
9498         } else {
9499             return this.getFoldDisplayLine(
9500                 foldLine, row, endColumn, startRow, startColumn);
9501         }
9502     };
9504     this.$cloneFoldData = function() {
9505         var fd = [];
9506         fd = this.$foldData.map(function(foldLine) {
9507             var folds = foldLine.folds.map(function(fold) {
9508                 return fold.clone();
9509             });
9510             return new FoldLine(fd, folds);
9511         });
9513         return fd;
9514     };
9516     this.toggleFold = function(tryToUnfold) {
9517         var selection = this.selection;
9518         var range = selection.getRange();
9519         var fold;
9520         var bracketPos;
9522         if (range.isEmpty()) {
9523             var cursor = range.start;
9524             fold = this.getFoldAt(cursor.row, cursor.column);
9526             if (fold) {
9527                 this.expandFold(fold);
9528                 return;
9529             }
9530             else if (bracketPos = this.findMatchingBracket(cursor)) {
9531                 if (range.comparePoint(bracketPos) == 1) {
9532                     range.end = bracketPos;
9533                 } 
9534                 else {
9535                     range.start = bracketPos;
9536                     range.start.column++;
9537                     range.end.column--;
9538                 }
9539             }
9540             else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
9541                 if (range.comparePoint(bracketPos) == 1)
9542                     range.end = bracketPos;
9543                 else
9544                     range.start = bracketPos;
9546                 range.start.column++;
9547             }
9548             else {
9549                 range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
9550             }
9551         } else {
9552             var folds = this.getFoldsInRange(range);
9553             if (tryToUnfold && folds.length) {
9554                 this.expandFolds(folds);
9555                 return;
9556             } 
9557             else if (folds.length == 1 ) {
9558                 fold = folds[0];
9559             }
9560         }
9562         if (!fold)
9563             fold = this.getFoldAt(range.start.row, range.start.column);
9565         if (fold && fold.range.toString() == range.toString()) {
9566             this.expandFold(fold);
9567             return;
9568         }
9570         var placeholder = "...";
9571         if (!range.isMultiLine()) {
9572             placeholder = this.getTextRange(range);
9573             if(placeholder.length < 4)
9574                 return;
9575             placeholder = placeholder.trim().substring(0, 2) + "..";
9576         }
9578         this.addFold(placeholder, range);
9579     };
9581     this.getCommentFoldRange = function(row, column) {
9582         var iterator = new TokenIterator(this, row, column);
9583         var token = iterator.getCurrentToken();
9584         if (token && /^comment|string/.test(token.type)) {
9585             var range = new Range();
9586             var re = new RegExp(token.type.replace(/\..*/, "\\."));
9587             do {
9588                 token = iterator.stepBackward();
9589             } while(token && re.test(token.type));
9591             iterator.stepForward();
9592             range.start.row = iterator.getCurrentTokenRow();
9593             range.start.column = iterator.getCurrentTokenColumn() + 2;
9595             iterator = new TokenIterator(this, row, column);
9597             do {
9598                 token = iterator.stepForward();
9599             } while(token && re.test(token.type));
9600             
9601             token = iterator.stepBackward();
9603             range.end.row = iterator.getCurrentTokenRow();
9604             range.end.column = iterator.getCurrentTokenColumn() + token.value.length;
9605             return range;
9606         }
9607     };
9609     this.foldAll = function(startRow, endRow) {
9610         var foldWidgets = this.foldWidgets;
9611         endRow = endRow || this.getLength();
9612         for (var row = startRow || 0; row < endRow; row++) {
9613             if (foldWidgets[row] == null)
9614                 foldWidgets[row] = this.getFoldWidget(row);
9615             if (foldWidgets[row] != "start")
9616                 continue;
9618             var range = this.getFoldWidgetRange(row);
9619             // sometimes range can be incompatible with existing fold
9620             // wouldn't it be better for addFold to return null istead of throwing?
9621             if (range && range.end.row < endRow) try {
9622                 this.addFold("...", range);
9623             } catch(e) {}
9624         }
9625     };
9626     
9627     this.$foldStyles = {
9628         "manual": 1,
9629         "markbegin": 1,
9630         "markbeginend": 1
9631     };
9632     this.$foldStyle = "markbegin";
9633     this.setFoldStyle = function(style) {
9634         if (!this.$foldStyles[style])
9635             throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
9636         
9637         if (this.$foldStyle == style)
9638             return;
9640         this.$foldStyle = style;
9641         
9642         if (style == "manual")
9643             this.unfold();
9644         
9645         // reset folding
9646         var mode = this.$foldMode;
9647         this.$setFolding(null);
9648         this.$setFolding(mode);
9649     };
9651     // structured folding
9652     this.$setFolding = function(foldMode) {
9653         if (this.$foldMode == foldMode)
9654             return;
9655             
9656         this.$foldMode = foldMode;
9657         
9658         this.removeListener('change', this.$updateFoldWidgets);
9659         this._emit("changeAnnotation");
9660         
9661         if (!foldMode || this.$foldStyle == "manual") {
9662             this.foldWidgets = null;
9663             return;
9664         }
9665         
9666         this.foldWidgets = [];
9667         this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
9668         this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
9669         
9670         this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
9671         this.on('change', this.$updateFoldWidgets);
9672         
9673     };
9675     this.onFoldWidgetClick = function(row, e) {
9676         var type = this.getFoldWidget(row);
9677         var line = this.getLine(row);
9678         var onlySubfolds = e.shiftKey;
9679         var addSubfolds = onlySubfolds || e.ctrlKey || e.altKey || e.metaKey;
9680         var fold;
9682         if (type == "end")
9683             fold = this.getFoldAt(row, 0, -1);
9684         else
9685             fold = this.getFoldAt(row, line.length, 1);
9687         if (fold) {
9688             if (addSubfolds)
9689                 this.removeFold(fold);
9690             else
9691                 this.expandFold(fold);
9692             return;
9693         }
9695         var range = this.getFoldWidgetRange(row);
9696         if (range) {
9697             // sometimes singleline folds can be missed by the code above
9698             if (!range.isMultiLine()) {
9699                 fold = this.getFoldAt(range.start.row, range.start.column, 1);
9700                 if (fold && range.isEqual(fold.range)) {
9701                     this.removeFold(fold);
9702                     return;
9703                 }
9704             }
9705             
9706             if (!onlySubfolds)
9707                 this.addFold("...", range);
9709             if (addSubfolds)
9710                 this.foldAll(range.start.row + 1, range.end.row);
9711         } else {
9712             if (addSubfolds)
9713                 this.foldAll(row + 1, this.getLength());
9714             (e.target || e.srcElement).className += " invalid"
9715         }
9716     };
9717     
9718     this.updateFoldWidgets = function(e) {
9719         var delta = e.data;
9720         var range = delta.range;
9721         var firstRow = range.start.row;
9722         var len = range.end.row - firstRow;
9724         if (len === 0) {
9725             this.foldWidgets[firstRow] = null;
9726         } else if (delta.action == "removeText" || delta.action == "removeLines") {
9727             this.foldWidgets.splice(firstRow, len + 1, null);
9728         } else {
9729             var args = Array(len + 1);
9730             args.unshift(firstRow, 1);
9731             this.foldWidgets.splice.apply(this.foldWidgets, args);
9732         }
9733     };
9737 exports.Folding = Folding;
9741 define('ace/edit_session/fold_line', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
9744 var Range = require("../range").Range;
9745 function FoldLine(foldData, folds) {
9746     this.foldData = foldData;
9747     if (Array.isArray(folds)) {
9748         this.folds = folds;
9749     } else {
9750         folds = this.folds = [ folds ];
9751     }
9753     var last = folds[folds.length - 1]
9754     this.range = new Range(folds[0].start.row, folds[0].start.column,
9755                            last.end.row, last.end.column);
9756     this.start = this.range.start;
9757     this.end   = this.range.end;
9759     this.folds.forEach(function(fold) {
9760         fold.setFoldLine(this);
9761     }, this);
9764 (function() {
9765     /*
9766      * Note: This doesn't update wrapData!
9767      */
9768     this.shiftRow = function(shift) {
9769         this.start.row += shift;
9770         this.end.row += shift;
9771         this.folds.forEach(function(fold) {
9772             fold.start.row += shift;
9773             fold.end.row += shift;
9774         });
9775     }
9777     this.addFold = function(fold) {
9778         if (fold.sameRow) {
9779             if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
9780                 throw "Can't add a fold to this FoldLine as it has no connection";
9781             }
9782             this.folds.push(fold);
9783             this.folds.sort(function(a, b) {
9784                 return -a.range.compareEnd(b.start.row, b.start.column);
9785             });
9786             if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
9787                 this.end.row = fold.end.row;
9788                 this.end.column =  fold.end.column;
9789             } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
9790                 this.start.row = fold.start.row;
9791                 this.start.column = fold.start.column;
9792             }
9793         } else if (fold.start.row == this.end.row) {
9794             this.folds.push(fold);
9795             this.end.row = fold.end.row;
9796             this.end.column = fold.end.column;
9797         } else if (fold.end.row == this.start.row) {
9798             this.folds.unshift(fold);
9799             this.start.row = fold.start.row;
9800             this.start.column = fold.start.column;
9801         } else {
9802             throw "Trying to add fold to FoldRow that doesn't have a matching row";
9803         }
9804         fold.foldLine = this;
9805     }
9807     this.containsRow = function(row) {
9808         return row >= this.start.row && row <= this.end.row;
9809     }
9811     this.walk = function(callback, endRow, endColumn) {
9812         var lastEnd = 0,
9813             folds = this.folds,
9814             fold,
9815             comp, stop, isNewRow = true;
9817         if (endRow == null) {
9818             endRow = this.end.row;
9819             endColumn = this.end.column;
9820         }
9822         for (var i = 0; i < folds.length; i++) {
9823             fold = folds[i];
9825             comp = fold.range.compareStart(endRow, endColumn);
9826             // This fold is after the endRow/Column.
9827             if (comp == -1) {
9828                 callback(null, endRow, endColumn, lastEnd, isNewRow);
9829                 return;
9830             }
9832             stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
9833             stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
9835             // If the user requested to stop the walk or endRow/endColumn is
9836             // inside of this fold (comp == 0), then end here.
9837             if (stop || comp == 0) {
9838                 return;
9839             }
9841             // Note the new lastEnd might not be on the same line. However,
9842             // it's the callback's job to recognize this.
9843             isNewRow = !fold.sameRow;
9844             lastEnd = fold.end.column;
9845         }
9846         callback(null, endRow, endColumn, lastEnd, isNewRow);
9847     }
9849     this.getNextFoldTo = function(row, column) {
9850         var fold, cmp;
9851         for (var i = 0; i < this.folds.length; i++) {
9852             fold = this.folds[i];
9853             cmp = fold.range.compareEnd(row, column);
9854             if (cmp == -1) {
9855                 return {
9856                     fold: fold,
9857                     kind: "after"
9858                 };
9859             } else if (cmp == 0) {
9860                 return {
9861                     fold: fold,
9862                     kind: "inside"
9863                 }
9864             }
9865         }
9866         return null;
9867     }
9869     this.addRemoveChars = function(row, column, len) {
9870         var ret = this.getNextFoldTo(row, column),
9871             fold, folds;
9872         if (ret) {
9873             fold = ret.fold;
9874             if (ret.kind == "inside"
9875                 && fold.start.column != column
9876                 && fold.start.row != row)
9877             {
9878                 //throwing here breaks whole editor
9879                 //TODO: properly handle this
9880                 window.console && window.console.log(row, column, fold);
9881             } else if (fold.start.row == row) {
9882                 folds = this.folds;
9883                 var i = folds.indexOf(fold);
9884                 if (i == 0) {
9885                     this.start.column += len;
9886                 }
9887                 for (i; i < folds.length; i++) {
9888                     fold = folds[i];
9889                     fold.start.column += len;
9890                     if (!fold.sameRow) {
9891                         return;
9892                     }
9893                     fold.end.column += len;
9894                 }
9895                 this.end.column += len;
9896             }
9897         }
9898     }
9900     this.split = function(row, column) {
9901         var fold = this.getNextFoldTo(row, column).fold,
9902             folds = this.folds;
9903         var foldData = this.foldData;
9905         if (!fold) {
9906             return null;
9907         }
9908         var i = folds.indexOf(fold);
9909         var foldBefore = folds[i - 1];
9910         this.end.row = foldBefore.end.row;
9911         this.end.column = foldBefore.end.column;
9913         // Remove the folds after row/column and create a new FoldLine
9914         // containing these removed folds.
9915         folds = folds.splice(i, folds.length - i);
9917         var newFoldLine = new FoldLine(foldData, folds);
9918         foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
9919         return newFoldLine;
9920     }
9922     this.merge = function(foldLineNext) {
9923         var folds = foldLineNext.folds;
9924         for (var i = 0; i < folds.length; i++) {
9925             this.addFold(folds[i]);
9926         }
9927         // Remove the foldLineNext - no longer needed, as
9928         // it's merged now with foldLineNext.
9929         var foldData = this.foldData;
9930         foldData.splice(foldData.indexOf(foldLineNext), 1);
9931     }
9933     this.toString = function() {
9934         var ret = [this.range.toString() + ": [" ];
9936         this.folds.forEach(function(fold) {
9937             ret.push("  " + fold.toString());
9938         });
9939         ret.push("]")
9940         return ret.join("\n");
9941     }
9943     this.idxToPosition = function(idx) {
9944         var lastFoldEndColumn = 0;
9945         var fold;
9947         for (var i = 0; i < this.folds.length; i++) {
9948             var fold = this.folds[i];
9950             idx -= fold.start.column - lastFoldEndColumn;
9951             if (idx < 0) {
9952                 return {
9953                     row: fold.start.row,
9954                     column: fold.start.column + idx
9955                 };
9956             }
9958             idx -= fold.placeholder.length;
9959             if (idx < 0) {
9960                 return fold.start;
9961             }
9963             lastFoldEndColumn = fold.end.column;
9964         }
9966         return {
9967             row: this.end.row,
9968             column: this.end.column + idx
9969         };
9970     }
9971 }).call(FoldLine.prototype);
9973 exports.FoldLine = FoldLine;
9976 define('ace/edit_session/fold', ['require', 'exports', 'module' ], function(require, exports, module) {
9980  * Simple fold-data struct.
9981  **/
9982 var Fold = exports.Fold = function(range, placeholder) {
9983     this.foldLine = null;
9984     this.placeholder = placeholder;
9985     this.range = range;
9986     this.start = range.start;
9987     this.end = range.end;
9989     this.sameRow = range.start.row == range.end.row;
9990     this.subFolds = [];
9993 (function() {
9995     this.toString = function() {
9996         return '"' + this.placeholder + '" ' + this.range.toString();
9997     };
9999     this.setFoldLine = function(foldLine) {
10000         this.foldLine = foldLine;
10001         this.subFolds.forEach(function(fold) {
10002             fold.setFoldLine(foldLine);
10003         });
10004     };
10006     this.clone = function() {
10007         var range = this.range.clone();
10008         var fold = new Fold(range, this.placeholder);
10009         this.subFolds.forEach(function(subFold) {
10010             fold.subFolds.push(subFold.clone());
10011         });
10012         return fold;
10013     };
10015     this.addSubFold = function(fold) {
10016         if (this.range.isEqual(fold))
10017             return this;
10019         if (!this.range.containsRange(fold))
10020             throw "A fold can't intersect already existing fold" + fold.range + this.range;
10022         var row = fold.range.start.row, column = fold.range.start.column;
10023         for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
10024             cmp = this.subFolds[i].range.compare(row, column);
10025             if (cmp != 1)
10026                 break;
10027         }
10028         var afterStart = this.subFolds[i];
10030         if (cmp == 0)
10031             return afterStart.addSubFold(fold);
10033         // cmp == -1
10034         var row = fold.range.end.row, column = fold.range.end.column;
10035         for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
10036             cmp = this.subFolds[j].range.compare(row, column);
10037             if (cmp != 1)
10038                 break;
10039         }
10040         var afterEnd = this.subFolds[j];
10042         if (cmp == 0)
10043             throw "A fold can't intersect already existing fold" + fold.range + this.range;
10045         var consumedFolds = this.subFolds.splice(i, j - i, fold);
10046         fold.setFoldLine(this.foldLine);
10048         return fold;
10049     };
10051 }).call(Fold.prototype);
10055 define('ace/token_iterator', ['require', 'exports', 'module' ], function(require, exports, module) {
10059  * class TokenIterator
10061  * This class provides an essay way to treat the document as a stream of tokens, and provides methods to iterate over these tokens.
10063  **/
10066  * new TokenIterator(session, initialRow, initialColumn)
10067  * - session (EditSession): The session to associate with
10068  * - initialRow (Number): The row to start the tokenizing at
10069  * - initialColumn (Number): The column to start the tokenizing at
10071  * Creates a new token iterator object. The inital token index is set to the provided row and column coordinates.
10073  **/
10074 var TokenIterator = function(session, initialRow, initialColumn) {
10075     this.$session = session;
10076     this.$row = initialRow;
10077     this.$rowTokens = session.getTokens(initialRow);
10079     var token = session.getTokenAt(initialRow, initialColumn);
10080     this.$tokenIndex = token ? token.index : -1;
10083 (function() {
10084    
10085     /**
10086     * TokenIterator.stepBackward() -> [String]
10087     * + (String): If the current point is not at the top of the file, this function returns `null`. Otherwise, it returns an array of the tokenized strings.
10088     * 
10089     * Tokenizes all the items from the current point to the row prior in the document. 
10090     **/ 
10091     this.stepBackward = function() {
10092         this.$tokenIndex -= 1;
10093         
10094         while (this.$tokenIndex < 0) {
10095             this.$row -= 1;
10096             if (this.$row < 0) {
10097                 this.$row = 0;
10098                 return null;
10099             }
10100                 
10101             this.$rowTokens = this.$session.getTokens(this.$row);
10102             this.$tokenIndex = this.$rowTokens.length - 1;
10103         }
10104             
10105         return this.$rowTokens[this.$tokenIndex];
10106     };   
10107     this.stepForward = function() {
10108         var rowCount = this.$session.getLength();
10109         this.$tokenIndex += 1;
10110         
10111         while (this.$tokenIndex >= this.$rowTokens.length) {
10112             this.$row += 1;
10113             if (this.$row >= rowCount) {
10114                 this.$row = rowCount - 1;
10115                 return null;
10116             }
10118             this.$rowTokens = this.$session.getTokens(this.$row);
10119             this.$tokenIndex = 0;
10120         }
10121             
10122         return this.$rowTokens[this.$tokenIndex];
10123     };      
10124     this.getCurrentToken = function () {
10125         return this.$rowTokens[this.$tokenIndex];
10126     };      
10127     this.getCurrentTokenRow = function () {
10128         return this.$row;
10129     };     
10130     this.getCurrentTokenColumn = function() {
10131         var rowTokens = this.$rowTokens;
10132         var tokenIndex = this.$tokenIndex;
10133         
10134         // If a column was cached by EditSession.getTokenAt, then use it
10135         var column = rowTokens[tokenIndex].start;
10136         if (column !== undefined)
10137             return column;
10138             
10139         column = 0;
10140         while (tokenIndex > 0) {
10141             tokenIndex -= 1;
10142             column += rowTokens[tokenIndex].value.length;
10143         }
10144         
10145         return column;  
10146     };
10147             
10148 }).call(TokenIterator.prototype);
10150 exports.TokenIterator = TokenIterator;
10153 define('ace/edit_session/bracket_match', ['require', 'exports', 'module' , 'ace/token_iterator', 'ace/range'], function(require, exports, module) {
10156 var TokenIterator = require("../token_iterator").TokenIterator;
10157 var Range = require("../range").Range;
10160 function BracketMatch() {
10162     this.findMatchingBracket = function(position) {
10163         if (position.column == 0) return null;
10165         var charBeforeCursor = this.getLine(position.row).charAt(position.column-1);
10166         if (charBeforeCursor == "") return null;
10168         var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
10169         if (!match)
10170             return null;
10172         if (match[1])
10173             return this.$findClosingBracket(match[1], position);
10174         else
10175             return this.$findOpeningBracket(match[2], position);
10176     };
10177     
10178     this.getBracketRange = function(pos) {
10179         var line = this.getLine(pos.row);
10180         var before = true, range;
10182         var chr = line.charAt(pos.column-1);
10183         var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
10184         if (!match) {
10185             chr = line.charAt(pos.column);
10186             pos = {row: pos.row, column: pos.column + 1};
10187             match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
10188             before = false;
10189         }
10190         if (!match)
10191             return null;
10193         if (match[1]) {
10194             var bracketPos = this.$findClosingBracket(match[1], pos);
10195             if (!bracketPos)
10196                 return null;
10197             range = Range.fromPoints(pos, bracketPos);
10198             if (!before) {
10199                 range.end.column++;
10200                 range.start.column--;
10201             }
10202             range.cursor = range.end;
10203         } else {
10204             var bracketPos = this.$findOpeningBracket(match[2], pos);
10205             if (!bracketPos)
10206                 return null;
10207             range = Range.fromPoints(bracketPos, pos);
10208             if (!before) {
10209                 range.start.column++;
10210                 range.end.column--;
10211             }
10212             range.cursor = range.start;
10213         }
10214         
10215         return range;
10216     };
10218     this.$brackets = {
10219         ")": "(",
10220         "(": ")",
10221         "]": "[",
10222         "[": "]",
10223         "{": "}",
10224         "}": "{"
10225     };
10227     this.$findOpeningBracket = function(bracket, position, typeRe) {
10228         var openBracket = this.$brackets[bracket];
10229         var depth = 1;
10231         var iterator = new TokenIterator(this, position.row, position.column);
10232         var token = iterator.getCurrentToken();
10233         if (!token)
10234             token = iterator.stepForward();
10235         if (!token)
10236             return;
10237         
10238          if (!typeRe){
10239             typeRe = new RegExp(
10240                 "(\\.?" +
10241                 token.type.replace(".", "\\.").replace("rparen", ".paren")
10242                 + ")+"
10243             );
10244         }
10245         
10246         // Start searching in token, just before the character at position.column
10247         var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
10248         var value = token.value;
10249         
10250         while (true) {
10251         
10252             while (valueIndex >= 0) {
10253                 var chr = value.charAt(valueIndex);
10254                 if (chr == openBracket) {
10255                     depth -= 1;
10256                     if (depth == 0) {
10257                         return {row: iterator.getCurrentTokenRow(),
10258                             column: valueIndex + iterator.getCurrentTokenColumn()};
10259                     }
10260                 }
10261                 else if (chr == bracket) {
10262                     depth += 1;
10263                 }
10264                 valueIndex -= 1;
10265             }
10267             // Scan backward through the document, looking for the next token
10268             // whose type matches typeRe
10269             do {
10270                 token = iterator.stepBackward();
10271             } while (token && !typeRe.test(token.type));
10273             if (token == null)
10274                 break;
10275                 
10276             value = token.value;
10277             valueIndex = value.length - 1;
10278         }
10279         
10280         return null;
10281     };
10283     this.$findClosingBracket = function(bracket, position, typeRe) {
10284         var closingBracket = this.$brackets[bracket];
10285         var depth = 1;
10287         var iterator = new TokenIterator(this, position.row, position.column);
10288         var token = iterator.getCurrentToken();
10289         if (!token)
10290             token = iterator.stepForward();
10291         if (!token)
10292             return;
10294         if (!typeRe){
10295             typeRe = new RegExp(
10296                 "(\\.?" +
10297                 token.type.replace(".", "\\.").replace("lparen", ".paren")
10298                 + ")+"
10299             );
10300         }
10302         // Start searching in token, after the character at position.column
10303         var valueIndex = position.column - iterator.getCurrentTokenColumn();
10305         while (true) {
10307             var value = token.value;
10308             var valueLength = value.length;
10309             while (valueIndex < valueLength) {
10310                 var chr = value.charAt(valueIndex);
10311                 if (chr == closingBracket) {
10312                     depth -= 1;
10313                     if (depth == 0) {
10314                         return {row: iterator.getCurrentTokenRow(),
10315                             column: valueIndex + iterator.getCurrentTokenColumn()};
10316                     }
10317                 }
10318                 else if (chr == bracket) {
10319                     depth += 1;
10320                 }
10321                 valueIndex += 1;
10322             }
10324             // Scan forward through the document, looking for the next token
10325             // whose type matches typeRe
10326             do {
10327                 token = iterator.stepForward();
10328             } while (token && !typeRe.test(token.type));
10330             if (token == null)
10331                 break;
10333             valueIndex = 0;
10334         }
10335         
10336         return null;
10337     };
10339 exports.BracketMatch = BracketMatch;
10343 define('ace/search', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/lib/oop', 'ace/range'], function(require, exports, module) {
10346 var lang = require("./lib/lang");
10347 var oop = require("./lib/oop");
10348 var Range = require("./range").Range;
10351  * new Search()
10353  * Creates a new `Search` object. The following search options are avaliable:
10355  * * `needle`: The string or regular expression you're looking for
10356  * * `backwards`: Whether to search backwards from where cursor currently is. Defaults to `false`.
10357  * * `wrap`: Whether to wrap the search back to the beginning when it hits the end. Defaults to `false`.
10358  * * `caseSensitive`: Whether the search ought to be case-sensitive. Defaults to `false`.
10359  * * `wholeWord`: Whether the search matches only on whole words. Defaults to `false`.
10360  * * `range`: The [[Range]] to search within. Set this to `null` for the whole document
10361  * * `regExp`: Whether the search is a regular expression or not. Defaults to `false`.
10362  * * `start`: The starting [[Range]] or cursor position to begin the search
10363  * * `skipCurrent`: Whether or not to include the current line in the search. Default to `false`.
10367 var Search = function() {
10368     this.$options = {};
10371 (function() {
10372     /**
10373      * Search.set(options) -> Search
10374      * - options (Object): An object containing all the new search properties
10375      *
10376      * Sets the search options via the `options` parameter.
10377      *
10378     **/
10379     this.set = function(options) {
10380         oop.mixin(this.$options, options);
10381         return this;
10382     };
10383     this.getOptions = function() {
10384         return lang.copyObject(this.$options);
10385     };
10387     this.setOptions = function(options) {
10388         this.$options = options;
10389     };
10390     this.find = function(session) {
10391         var iterator = this.$matchIterator(session, this.$options);
10393         if (!iterator)
10394             return false;
10396         var firstRange = null;
10397         iterator.forEach(function(range, row, offset) {
10398             if (!range.start) {
10399                 var column = range.offset + (offset || 0);
10400                 firstRange = new Range(row, column, row, column+range.length);
10401             } else
10402                 firstRange = range;
10403             return true;
10404         });
10406         return firstRange;
10407     };
10408     this.findAll = function(session) {
10409         var options = this.$options;
10410         if (!options.needle)
10411             return [];
10412         this.$assembleRegExp(options);
10414         var range = options.range;
10415         var lines = range
10416             ? session.getLines(range.start.row, range.end.row)
10417             : session.doc.getAllLines();
10419         var ranges = [];
10420         var re = options.re;
10421         if (options.$isMultiLine) {
10422             var len = re.length;
10423             var maxRow = lines.length - len;
10424             for (var row = re.offset || 0; row <= maxRow; row++) {
10425                 for (var j = 0; j < len; j++)
10426                     if (lines[row + j].search(re[j]) == -1)
10427                         break;
10428                 
10429                 var startLine = lines[row];
10430                 var line = lines[row + len - 1];
10431                 var startIndex = startLine.match(re[0])[0].length;
10432                 var endIndex = line.match(re[len - 1])[0].length;
10434                 ranges.push(new Range(
10435                     row, startLine.length - startIndex,
10436                     row + len - 1, endIndex
10437                 ));
10438             }
10439         } else {
10440             for (var i = 0; i < lines.length; i++) {
10441                 var matches = lang.getMatchOffsets(lines[i], re);
10442                 for (var j = 0; j < matches.length; j++) {
10443                     var match = matches[j];
10444                     ranges.push(new Range(i, match.offset, i, match.offset + match.length));
10445                 }
10446             }
10447         }
10449         if (range) {
10450             var startColumn = range.start.column;
10451             var endColumn = range.start.column;
10452             var i = 0, j = ranges.length - 1;
10453             while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
10454                 i++;
10456             while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
10457                 j--;
10458             return ranges.slice(i, j + 1);
10459         }
10461         return ranges;
10462     };
10463     this.replace = function(input, replacement) {
10464         var options = this.$options;
10466         var re = this.$assembleRegExp(options);
10467         if (options.$isMultiLine)
10468             return replacement;
10470         if (!re)
10471             return;
10473         var match = re.exec(input);
10474         if (!match || match[0].length != input.length)
10475             return null;
10476         
10477         replacement = input.replace(re, replacement);
10478         if (options.preserveCase) {
10479             replacement = replacement.split("");
10480             for (var i = Math.min(input.length, input.length); i--; ) {
10481                 var ch = input[i];
10482                 if (ch && ch.toLowerCase() != ch)
10483                     replacement[i] = replacement[i].toUpperCase();
10484                 else
10485                     replacement[i] = replacement[i].toLowerCase();
10486             }
10487             replacement = replacement.join("");
10488         }
10489         
10490         return replacement;
10491     };
10492     this.$matchIterator = function(session, options) {
10493         var re = this.$assembleRegExp(options);
10494         if (!re)
10495             return false;
10497         var self = this, callback, backwards = options.backwards;
10499         if (options.$isMultiLine) {
10500             var len = re.length;
10501             var matchIterator = function(line, row, offset) {
10502                 var startIndex = line.search(re[0]);
10503                 if (startIndex == -1)
10504                     return;
10505                 for (var i = 1; i < len; i++) {
10506                     line = session.getLine(row + i);
10507                     if (line.search(re[i]) == -1)
10508                         return;
10509                 }
10511                 var endIndex = line.match(re[len - 1])[0].length;
10513                 var range = new Range(row, startIndex, row + len - 1, endIndex);
10514                 if (re.offset == 1) {
10515                     range.start.row--;
10516                     range.start.column = Number.MAX_VALUE;
10517                 } else if (offset)
10518                     range.start.column += offset;
10520                 if (callback(range))
10521                     return true;
10522             };
10523         } else if (backwards) {
10524             var matchIterator = function(line, row, startIndex) {
10525                 var matches = lang.getMatchOffsets(line, re);
10526                 for (var i = matches.length-1; i >= 0; i--)
10527                     if (callback(matches[i], row, startIndex))
10528                         return true;
10529             };
10530         } else {
10531             var matchIterator = function(line, row, startIndex) {
10532                 var matches = lang.getMatchOffsets(line, re);
10533                 for (var i = 0; i < matches.length; i++)
10534                     if (callback(matches[i], row, startIndex))
10535                         return true;
10536             };
10537         }
10539         return {
10540             forEach: function(_callback) {
10541                 callback = _callback;
10542                 self.$lineIterator(session, options).forEach(matchIterator);
10543             }
10544         };
10545     };
10547     this.$assembleRegExp = function(options) {
10548         if (options.needle instanceof RegExp)
10549             return options.re = options.needle;
10551         var needle = options.needle;
10553         if (!options.needle)
10554             return options.re = false;
10556         if (!options.regExp)
10557             needle = lang.escapeRegExp(needle);
10559         if (options.wholeWord)
10560             needle = "\\b" + needle + "\\b";
10562         var modifier = options.caseSensitive ? "g" : "gi";
10564         options.$isMultiLine = /[\n\r]/.test(needle);
10565         if (options.$isMultiLine)
10566             return options.re = this.$assembleMultilineRegExp(needle, modifier);
10568         try {
10569             var re = new RegExp(needle, modifier);
10570         } catch(e) {
10571             re = false;
10572         }
10573         return options.re = re;
10574     };
10576     this.$assembleMultilineRegExp = function(needle, modifier) {
10577         var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
10578         var re = [];
10579         for (var i = 0; i < parts.length; i++) try {
10580             re.push(new RegExp(parts[i], modifier));
10581         } catch(e) {
10582             return false;
10583         }
10584         if (parts[0] == "") {
10585             re.shift();
10586             re.offset = 1;
10587         } else {
10588             re.offset = 0;
10589         }
10590         return re;
10591     };
10593     this.$lineIterator = function(session, options) {
10594         var backwards = options.backwards == true;
10595         var skipCurrent = options.skipCurrent != false;
10597         var range = options.range;
10598         var start = options.start;
10599         if (!start)
10600             start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
10601          
10602         if (start.start)
10603             start = start[skipCurrent != backwards ? "end" : "start"];
10605         var firstRow = range ? range.start.row : 0;
10606         var lastRow = range ? range.end.row : session.getLength() - 1;
10608         var forEach = backwards ? function(callback) {
10609                 var row = start.row;
10611                 var line = session.getLine(row).substring(0, start.column);
10612                 if (callback(line, row))
10613                     return;
10615                 for (row--; row >= firstRow; row--)
10616                     if (callback(session.getLine(row), row))
10617                         return;
10619                 if (options.wrap == false)
10620                     return;
10622                 for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
10623                     if (callback(session.getLine(row), row))
10624                         return;
10625             } : function(callback) {
10626                 var row = start.row;
10628                 var line = session.getLine(row).substr(start.column);
10629                 if (callback(line, row, start.column))
10630                     return;
10632                 for (row = row+1; row <= lastRow; row++)
10633                     if (callback(session.getLine(row), row))
10634                         return;
10636                 if (options.wrap == false)
10637                     return;
10639                 for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
10640                     if (callback(session.getLine(row), row))
10641                         return;
10642             };
10643         
10644         return {forEach: forEach};
10645     };
10647 }).call(Search.prototype);
10649 exports.Search = Search;
10651 define('ace/commands/command_manager', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/keyboard/hash_handler', 'ace/lib/event_emitter'], function(require, exports, module) {
10654 var oop = require("../lib/oop");
10655 var HashHandler = require("../keyboard/hash_handler").HashHandler;
10656 var EventEmitter = require("../lib/event_emitter").EventEmitter;
10659  * new CommandManager(platform, commands)
10660  * - platform (String): Identifier for the platform; must be either `'mac'` or `'win'`
10661  * - commands (Array): A list of commands
10663  * TODO
10666  **/
10668 var CommandManager = function(platform, commands) {
10669     this.platform = platform;
10670     this.commands = this.byName = {};
10671     this.commmandKeyBinding = {};
10673     this.addCommands(commands);
10674     
10675     this.setDefaultHandler("exec", function(e) {
10676         return e.command.exec(e.editor, e.args || {});
10677     });
10680 oop.inherits(CommandManager, HashHandler);
10682 (function() {
10684     oop.implement(this, EventEmitter);
10686     this.exec = function(command, editor, args) {
10687         if (typeof command === 'string')
10688             command = this.commands[command];
10690         if (!command)
10691             return false;
10693         if (editor && editor.$readOnly && !command.readOnly)
10694             return false;
10696         var retvalue = this._emit("exec", {
10697             editor: editor,
10698             command: command,
10699             args: args
10700         });
10702         return retvalue === false ? false : true;
10703     };
10705     this.toggleRecording = function(editor) {
10706         if (this.$inReplay)
10707             return;
10709         editor && editor._emit("changeStatus");
10710         if (this.recording) {
10711             this.macro.pop();
10712             this.removeEventListener("exec", this.$addCommandToMacro);
10714             if (!this.macro.length)
10715                 this.macro = this.oldMacro;
10717             return this.recording = false;
10718         }
10719         if (!this.$addCommandToMacro) {
10720             this.$addCommandToMacro = function(e) {
10721                 this.macro.push([e.command, e.args]);
10722             }.bind(this);
10723         }
10725         this.oldMacro = this.macro;
10726         this.macro = [];
10727         this.on("exec", this.$addCommandToMacro);
10728         return this.recording = true;
10729     };
10731     this.replay = function(editor) {
10732         if (this.$inReplay || !this.macro)
10733             return;
10735         if (this.recording)
10736             return this.toggleRecording(editor);
10738         try {
10739             this.$inReplay = true;
10740             this.macro.forEach(function(x) {
10741                 if (typeof x == "string")
10742                     this.exec(x, editor);
10743                 else
10744                     this.exec(x[0], editor, x[1]);
10745             }, this);
10746         } finally {
10747             this.$inReplay = false;
10748         }
10749     };
10751     this.trimMacro = function(m) {
10752         return m.map(function(x){
10753             if (typeof x[0] != "string")
10754                 x[0] = x[0].name;
10755             if (!x[1])
10756                 x = x[0];
10757             return x;
10758         });
10759     };
10761 }).call(CommandManager.prototype);
10763 exports.CommandManager = CommandManager;
10767 define('ace/keyboard/hash_handler', ['require', 'exports', 'module' , 'ace/lib/keys'], function(require, exports, module) {
10770 var keyUtil  = require("../lib/keys");
10772 function HashHandler(config, platform) {
10773     this.platform = platform;
10774     this.commands = {};
10775     this.commmandKeyBinding = {};
10777     this.addCommands(config);
10780 (function() {
10782     this.addCommand = function(command) {
10783         if (this.commands[command.name])
10784             this.removeCommand(command);
10786         this.commands[command.name] = command;
10788         if (command.bindKey)
10789             this._buildKeyHash(command);
10790     };
10792     this.removeCommand = function(command) {
10793         var name = (typeof command === 'string' ? command : command.name);
10794         command = this.commands[name];
10795         delete this.commands[name];
10797         // exhaustive search is brute force but since removeCommand is
10798         // not a performance critical operation this should be OK
10799         var ckb = this.commmandKeyBinding;
10800         for (var hashId in ckb) {
10801             for (var key in ckb[hashId]) {
10802                 if (ckb[hashId][key] == command)
10803                     delete ckb[hashId][key];
10804             }
10805         }
10806     };
10808     this.bindKey = function(key, command) {
10809         if(!key)
10810             return;
10811         if (typeof command == "function") {
10812             this.addCommand({exec: command, bindKey: key, name: key});
10813             return;
10814         }
10816         var ckb = this.commmandKeyBinding;
10817         key.split("|").forEach(function(keyPart) {
10818             var binding = this.parseKeys(keyPart, command);
10819             var hashId = binding.hashId;
10820             (ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
10821         }, this);
10822     };
10824     this.addCommands = function(commands) {
10825         commands && Object.keys(commands).forEach(function(name) {
10826             var command = commands[name];
10827             if (typeof command === "string")
10828                 return this.bindKey(command, name);
10830             if (typeof command === "function")
10831                 command = { exec: command };
10833             if (!command.name)
10834                 command.name = name;
10836             this.addCommand(command);
10837         }, this);
10838     };
10840     this.removeCommands = function(commands) {
10841         Object.keys(commands).forEach(function(name) {
10842             this.removeCommand(commands[name]);
10843         }, this);
10844     };
10846     this.bindKeys = function(keyList) {
10847         Object.keys(keyList).forEach(function(key) {
10848             this.bindKey(key, keyList[key]);
10849         }, this);
10850     };
10852     this._buildKeyHash = function(command) {
10853         var binding = command.bindKey;
10854         if (!binding)
10855             return;
10857         var key = typeof binding == "string" ? binding: binding[this.platform];
10858         this.bindKey(key, command);
10859     };
10860         
10861         // accepts keys in the form ctrl+Enter or ctrl-Enter
10862         // keys without modifiers or shift only 
10863     this.parseKeys = function(keys) {
10864         var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
10865         var key = parts.pop();
10867         var keyCode = keyUtil[key];
10868         if (keyUtil.FUNCTION_KEYS[keyCode])
10869             key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
10870         else if (!parts.length)
10871             return {key: key, hashId: -1};
10872         else if (parts.length == 1 && parts[0] == "shift")
10873             return {key: key.toUpperCase(), hashId: -1};
10875         var hashId = 0;
10876         for (var i = parts.length; i--;) {
10877             var modifier = keyUtil.KEY_MODS[parts[i]];
10878             if (modifier == null)
10879                 throw "invalid modifier " + parts[i] + " in " + keys;
10880             hashId |= modifier;
10881         }
10882         return {key: key, hashId: hashId};
10883     };
10885     this.findKeyCommand = function findKeyCommand(hashId, keyString) {
10886         var ckbr = this.commmandKeyBinding;
10887         return ckbr[hashId] && ckbr[hashId][keyString];
10888     };
10890     this.handleKeyboard = function(data, hashId, keyString, keyCode) {
10891         return {
10892             command: this.findKeyCommand(hashId, keyString)
10893         };
10894     };
10896 }).call(HashHandler.prototype)
10898 exports.HashHandler = HashHandler;
10901 define('ace/commands/default_commands', ['require', 'exports', 'module' , 'ace/lib/lang'], function(require, exports, module) {
10904 var lang = require("../lib/lang");
10906 function bindKey(win, mac) {
10907     return {
10908         win: win,
10909         mac: mac
10910     };
10913 exports.commands = [{
10914     name: "selectall",
10915     bindKey: bindKey("Ctrl-A", "Command-A"),
10916     exec: function(editor) { editor.selectAll(); },
10917     readOnly: true
10918 }, {
10919     name: "centerselection",
10920     bindKey: bindKey(null, "Ctrl-L"),
10921     exec: function(editor) { editor.centerSelection(); },
10922     readOnly: true
10923 }, {
10924     name: "gotoline",
10925     bindKey: bindKey("Ctrl-L", "Command-L"),
10926     exec: function(editor) {
10927         var line = parseInt(prompt("Enter line number:"), 10);
10928         if (!isNaN(line)) {
10929             editor.gotoLine(line);
10930         }
10931     },
10932     readOnly: true
10933 }, {
10934     name: "fold",
10935     bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
10936     exec: function(editor) { editor.session.toggleFold(false); },
10937     readOnly: true
10938 }, {
10939     name: "unfold",
10940     bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
10941     exec: function(editor) { editor.session.toggleFold(true); },
10942     readOnly: true
10943 }, {
10944     name: "foldall",
10945     bindKey: bindKey("Alt-0", "Command-Option-0"),
10946     exec: function(editor) { editor.session.foldAll(); },
10947     readOnly: true
10948 }, {
10949     name: "unfoldall",
10950     bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
10951     exec: function(editor) { editor.session.unfold(); },
10952     readOnly: true
10953 }, {
10954     name: "findnext",
10955     bindKey: bindKey("Ctrl-K", "Command-G"),
10956     exec: function(editor) { editor.findNext(); },
10957     readOnly: true
10958 }, {
10959     name: "findprevious",
10960     bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
10961     exec: function(editor) { editor.findPrevious(); },
10962     readOnly: true
10963 }, {
10964     name: "find",
10965     bindKey: bindKey("Ctrl-F", "Command-F"),
10966     exec: function(editor) {
10967         var needle = prompt("Find:", editor.getCopyText());
10968         editor.find(needle);
10969     },
10970     readOnly: true
10971 }, {
10972     name: "overwrite",
10973     bindKey: "Insert",
10974     exec: function(editor) { editor.toggleOverwrite(); },
10975     readOnly: true
10976 }, {
10977     name: "selecttostart",
10978     bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
10979     exec: function(editor) { editor.getSelection().selectFileStart(); },
10980     multiSelectAction: "forEach",
10981     readOnly: true
10982 }, {
10983     name: "gotostart",
10984     bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
10985     exec: function(editor) { editor.navigateFileStart(); },
10986     multiSelectAction: "forEach",
10987     readOnly: true
10988 }, {
10989     name: "selectup",
10990     bindKey: bindKey("Shift-Up", "Shift-Up"),
10991     exec: function(editor) { editor.getSelection().selectUp(); },
10992     multiSelectAction: "forEach",
10993     readOnly: true
10994 }, {
10995     name: "golineup",
10996     bindKey: bindKey("Up", "Up|Ctrl-P"),
10997     exec: function(editor, args) { editor.navigateUp(args.times); },
10998     multiSelectAction: "forEach",
10999     readOnly: true
11000 }, {
11001     name: "selecttoend",
11002     bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
11003     exec: function(editor) { editor.getSelection().selectFileEnd(); },
11004     multiSelectAction: "forEach",
11005     readOnly: true
11006 }, {
11007     name: "gotoend",
11008     bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
11009     exec: function(editor) { editor.navigateFileEnd(); },
11010     multiSelectAction: "forEach",
11011     readOnly: true
11012 }, {
11013     name: "selectdown",
11014     bindKey: bindKey("Shift-Down", "Shift-Down"),
11015     exec: function(editor) { editor.getSelection().selectDown(); },
11016     multiSelectAction: "forEach",
11017     readOnly: true
11018 }, {
11019     name: "golinedown",
11020     bindKey: bindKey("Down", "Down|Ctrl-N"),
11021     exec: function(editor, args) { editor.navigateDown(args.times); },
11022     multiSelectAction: "forEach",
11023     readOnly: true
11024 }, {
11025     name: "selectwordleft",
11026     bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
11027     exec: function(editor) { editor.getSelection().selectWordLeft(); },
11028     multiSelectAction: "forEach",
11029     readOnly: true
11030 }, {
11031     name: "gotowordleft",
11032     bindKey: bindKey("Ctrl-Left", "Option-Left"),
11033     exec: function(editor) { editor.navigateWordLeft(); },
11034     multiSelectAction: "forEach",
11035     readOnly: true
11036 }, {
11037     name: "selecttolinestart",
11038     bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
11039     exec: function(editor) { editor.getSelection().selectLineStart(); },
11040     multiSelectAction: "forEach",
11041     readOnly: true
11042 }, {
11043     name: "gotolinestart",
11044     bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
11045     exec: function(editor) { editor.navigateLineStart(); },
11046     multiSelectAction: "forEach",
11047     readOnly: true
11048 }, {
11049     name: "selectleft",
11050     bindKey: bindKey("Shift-Left", "Shift-Left"),
11051     exec: function(editor) { editor.getSelection().selectLeft(); },
11052     multiSelectAction: "forEach",
11053     readOnly: true
11054 }, {
11055     name: "gotoleft",
11056     bindKey: bindKey("Left", "Left|Ctrl-B"),
11057     exec: function(editor, args) { editor.navigateLeft(args.times); },
11058     multiSelectAction: "forEach",
11059     readOnly: true
11060 }, {
11061     name: "selectwordright",
11062     bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
11063     exec: function(editor) { editor.getSelection().selectWordRight(); },
11064     multiSelectAction: "forEach",
11065     readOnly: true
11066 }, {
11067     name: "gotowordright",
11068     bindKey: bindKey("Ctrl-Right", "Option-Right"),
11069     exec: function(editor) { editor.navigateWordRight(); },
11070     multiSelectAction: "forEach",
11071     readOnly: true
11072 }, {
11073     name: "selecttolineend",
11074     bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
11075     exec: function(editor) { editor.getSelection().selectLineEnd(); },
11076     multiSelectAction: "forEach",
11077     readOnly: true
11078 }, {
11079     name: "gotolineend",
11080     bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
11081     exec: function(editor) { editor.navigateLineEnd(); },
11082     multiSelectAction: "forEach",
11083     readOnly: true
11084 }, {
11085     name: "selectright",
11086     bindKey: bindKey("Shift-Right", "Shift-Right"),
11087     exec: function(editor) { editor.getSelection().selectRight(); },
11088     multiSelectAction: "forEach",
11089     readOnly: true
11090 }, {
11091     name: "gotoright",
11092     bindKey: bindKey("Right", "Right|Ctrl-F"),
11093     exec: function(editor, args) { editor.navigateRight(args.times); },
11094     multiSelectAction: "forEach",
11095     readOnly: true
11096 }, {
11097     name: "selectpagedown",
11098     bindKey: "Shift-PageDown",
11099     exec: function(editor) { editor.selectPageDown(); },
11100     readOnly: true
11101 }, {
11102     name: "pagedown",
11103     bindKey: bindKey(null, "Option-PageDown"),
11104     exec: function(editor) { editor.scrollPageDown(); },
11105     readOnly: true
11106 }, {
11107     name: "gotopagedown",
11108     bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
11109     exec: function(editor) { editor.gotoPageDown(); },
11110     readOnly: true
11111 }, {
11112     name: "selectpageup",
11113     bindKey: "Shift-PageUp",
11114     exec: function(editor) { editor.selectPageUp(); },
11115     readOnly: true
11116 }, {
11117     name: "pageup",
11118     bindKey: bindKey(null, "Option-PageUp"),
11119     exec: function(editor) { editor.scrollPageUp(); },
11120     readOnly: true
11121 }, {
11122     name: "gotopageup",
11123     bindKey: "PageUp",
11124     exec: function(editor) { editor.gotoPageUp(); },
11125     readOnly: true
11126 }, {
11127     name: "scrollup",
11128     bindKey: bindKey("Ctrl-Up", null),
11129     exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
11130     readOnly: true
11131 }, {
11132     name: "scrolldown",
11133     bindKey: bindKey("Ctrl-Down", null),
11134     exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
11135     readOnly: true
11136 }, {
11137     name: "selectlinestart",
11138     bindKey: "Shift-Home",
11139     exec: function(editor) { editor.getSelection().selectLineStart(); },
11140     multiSelectAction: "forEach",
11141     readOnly: true
11142 }, {
11143     name: "selectlineend",
11144     bindKey: "Shift-End",
11145     exec: function(editor) { editor.getSelection().selectLineEnd(); },
11146     multiSelectAction: "forEach",
11147     readOnly: true
11148 }, {
11149     name: "togglerecording",
11150     bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
11151     exec: function(editor) { editor.commands.toggleRecording(editor); },
11152     readOnly: true
11153 }, {
11154     name: "replaymacro",
11155     bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
11156     exec: function(editor) { editor.commands.replay(editor); },
11157     readOnly: true
11158 }, {
11159     name: "jumptomatching",
11160     bindKey: bindKey("Ctrl-P", "Ctrl-Shift-P"),
11161     exec: function(editor) { editor.jumpToMatching(); },
11162     multiSelectAction: "forEach",
11163     readOnly: true
11164 }, {
11165     name: "selecttomatching",
11166     bindKey: bindKey("Ctrl-Shift-P", null),
11167     exec: function(editor) { editor.jumpToMatching(true); },
11168     readOnly: true
11169 }, 
11171 // commands disabled in readOnly mode
11173     name: "cut",
11174     exec: function(editor) {
11175         var range = editor.getSelectionRange();
11176         editor._emit("cut", range);
11178         if (!editor.selection.isEmpty()) {
11179             editor.session.remove(range);
11180             editor.clearSelection();
11181         }
11182     },
11183     multiSelectAction: "forEach"
11184 }, {
11185     name: "removeline",
11186     bindKey: bindKey("Ctrl-D", "Command-D"),
11187     exec: function(editor) { editor.removeLines(); },
11188     multiSelectAction: "forEach"
11189 }, {
11190     name: "duplicateSelection",
11191     bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
11192     exec: function(editor) { editor.duplicateSelection(); },
11193     multiSelectAction: "forEach"
11194 }, {
11195     name: "togglecomment",
11196     bindKey: bindKey("Ctrl-/", "Command-/"),
11197     exec: function(editor) { editor.toggleCommentLines(); },
11198     multiSelectAction: "forEach"
11199 }, {
11200     name: "replace",
11201     bindKey: bindKey("Ctrl-R", "Command-Option-F"),
11202     exec: function(editor) {
11203         var needle = prompt("Find:", editor.getCopyText());
11204         if (!needle)
11205             return;
11206         var replacement = prompt("Replacement:");
11207         if (!replacement)
11208             return;
11209         editor.replace(replacement, {needle: needle});
11210     }
11211 }, {
11212     name: "replaceall",
11213     bindKey: bindKey("Ctrl-Shift-R", "Command-Shift-Option-F"),
11214     exec: function(editor) {
11215         var needle = prompt("Find:");
11216         if (!needle)
11217             return;
11218         var replacement = prompt("Replacement:");
11219         if (!replacement)
11220             return;
11221         editor.replaceAll(replacement, {needle: needle});
11222     }
11223 }, {
11224     name: "undo",
11225     bindKey: bindKey("Ctrl-Z", "Command-Z"),
11226     exec: function(editor) { editor.undo(); }
11227 }, {
11228     name: "redo",
11229     bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
11230     exec: function(editor) { editor.redo(); }
11231 }, {
11232     name: "copylinesup",
11233     bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
11234     exec: function(editor) { editor.copyLinesUp(); }
11235 }, {
11236     name: "movelinesup",
11237     bindKey: bindKey("Alt-Up", "Option-Up"),
11238     exec: function(editor) { editor.moveLinesUp(); }
11239 }, {
11240     name: "copylinesdown",
11241     bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
11242     exec: function(editor) { editor.copyLinesDown(); }
11243 }, {
11244     name: "movelinesdown",
11245     bindKey: bindKey("Alt-Down", "Option-Down"),
11246     exec: function(editor) { editor.moveLinesDown(); }
11247 }, {
11248     name: "del",
11249     bindKey: bindKey("Delete", "Delete|Ctrl-D"),
11250     exec: function(editor) { editor.remove("right"); },
11251     multiSelectAction: "forEach"
11252 }, {
11253     name: "backspace",
11254     bindKey: bindKey(
11255         "Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
11256         "Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
11257     ),
11258     exec: function(editor) { editor.remove("left"); },
11259     multiSelectAction: "forEach"
11260 }, {
11261     name: "removetolinestart",
11262     bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
11263     exec: function(editor) { editor.removeToLineStart(); },
11264     multiSelectAction: "forEach"
11265 }, {
11266     name: "removetolineend",
11267     bindKey: bindKey("Alt-Delete", "Ctrl-K"),
11268     exec: function(editor) { editor.removeToLineEnd(); },
11269     multiSelectAction: "forEach"
11270 }, {
11271     name: "removewordleft",
11272     bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
11273     exec: function(editor) { editor.removeWordLeft(); },
11274     multiSelectAction: "forEach"
11275 }, {
11276     name: "removewordright",
11277     bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
11278     exec: function(editor) { editor.removeWordRight(); },
11279     multiSelectAction: "forEach"
11280 }, {
11281     name: "outdent",
11282     bindKey: bindKey("Shift-Tab", "Shift-Tab"),
11283     exec: function(editor) { editor.blockOutdent(); },
11284     multiSelectAction: "forEach"
11285 }, {
11286     name: "indent",
11287     bindKey: bindKey("Tab", "Tab"),
11288     exec: function(editor) { editor.indent(); },
11289     multiSelectAction: "forEach"
11290 }, {
11291     name: "insertstring",
11292     exec: function(editor, str) { editor.insert(str); },
11293     multiSelectAction: "forEach"
11294 }, {
11295     name: "inserttext",
11296     exec: function(editor, args) {
11297         editor.insert(lang.stringRepeat(args.text  || "", args.times || 1));
11298     },
11299     multiSelectAction: "forEach"
11300 }, {
11301     name: "splitline",
11302     bindKey: bindKey(null, "Ctrl-O"),
11303     exec: function(editor) { editor.splitLine(); },
11304     multiSelectAction: "forEach"
11305 }, {
11306     name: "transposeletters",
11307     bindKey: bindKey("Ctrl-T", "Ctrl-T"),
11308     exec: function(editor) { editor.transposeLetters(); },
11309     multiSelectAction: function(editor) {editor.transposeSelections(1); }
11310 }, {
11311     name: "touppercase",
11312     bindKey: bindKey("Ctrl-U", "Ctrl-U"),
11313     exec: function(editor) { editor.toUpperCase(); },
11314     multiSelectAction: "forEach"
11315 }, {
11316     name: "tolowercase",
11317     bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
11318     exec: function(editor) { editor.toLowerCase(); },
11319     multiSelectAction: "forEach"
11324 define('ace/undomanager', ['require', 'exports', 'module' ], function(require, exports, module) {
11328  * class UndoManager
11330  * This object maintains the undo stack for an [[EditSession `EditSession`]].
11332  **/
11335  * new UndoManager()
11336  * 
11337  * Resets the current undo state and creates a new `UndoManager`.
11338  **/
11339 var UndoManager = function() {
11340     this.reset();
11343 (function() {
11345     /**
11346     * UndoManager.execute(options) -> Void
11347     * - options (Object): Contains additional properties
11348     *
11349     * Provides a means for implementing your own undo manager. `options` has one property, `args`, an [[Array `Array`]], with two elements:
11350     *
11351     * * `args[0]` is an array of deltas
11352     * * `args[1]` is the document to associate with
11353     *
11354     **/
11355     this.execute = function(options) {
11356         var deltas = options.args[0];
11357         this.$doc  = options.args[1];
11358         this.$undoStack.push(deltas);
11359         this.$redoStack = [];
11360     };
11361     this.undo = function(dontSelect) {
11362         var deltas = this.$undoStack.pop();
11363         var undoSelectionRange = null;
11364         if (deltas) {
11365             undoSelectionRange =
11366                 this.$doc.undoChanges(deltas, dontSelect);
11367             this.$redoStack.push(deltas);
11368         }
11369         return undoSelectionRange;
11370     };
11371     this.redo = function(dontSelect) {
11372         var deltas = this.$redoStack.pop();
11373         var redoSelectionRange = null;
11374         if (deltas) {
11375             redoSelectionRange =
11376                 this.$doc.redoChanges(deltas, dontSelect);
11377             this.$undoStack.push(deltas);
11378         }
11379         return redoSelectionRange;
11380     };
11381     this.reset = function() {
11382         this.$undoStack = [];
11383         this.$redoStack = [];
11384     };
11385     this.hasUndo = function() {
11386         return this.$undoStack.length > 0;
11387     };
11388     this.hasRedo = function() {
11389         return this.$redoStack.length > 0;
11390     };
11392 }).call(UndoManager.prototype);
11394 exports.UndoManager = UndoManager;
11397 define('ace/virtual_renderer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/event', 'ace/lib/useragent', 'ace/config', 'ace/lib/net', 'ace/layer/gutter', 'ace/layer/marker', 'ace/layer/text', 'ace/layer/cursor', 'ace/scrollbar', 'ace/renderloop', 'ace/lib/event_emitter', 'text!ace/css/editor.css'], function(require, exports, module) {
11400 var oop = require("./lib/oop");
11401 var dom = require("./lib/dom");
11402 var event = require("./lib/event");
11403 var useragent = require("./lib/useragent");
11404 var config = require("./config");
11405 var net = require("./lib/net");
11406 var GutterLayer = require("./layer/gutter").Gutter;
11407 var MarkerLayer = require("./layer/marker").Marker;
11408 var TextLayer = require("./layer/text").Text;
11409 var CursorLayer = require("./layer/cursor").Cursor;
11410 var ScrollBar = require("./scrollbar").ScrollBar;
11411 var RenderLoop = require("./renderloop").RenderLoop;
11412 var EventEmitter = require("./lib/event_emitter").EventEmitter;
11413 var editorCss = require("text!./css/editor.css");
11415 dom.importCssString(editorCss, "ace_editor");
11418  * new VirtualRenderer(container, theme)
11419  * - container (DOMElement): The root element of the editor
11420  * - theme (String): The starting theme
11422  * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`.
11424  **/
11426 var VirtualRenderer = function(container, theme) {
11427     var _self = this;
11429     this.container = container;
11431     // TODO: this breaks rendering in Cloud9 with multiple ace instances
11432 //    // Imports CSS once per DOM document ('ace_editor' serves as an identifier).
11433 //    dom.importCssString(editorCss, "ace_editor", container.ownerDocument);
11435     // in IE <= 9 the native cursor always shines through
11436     this.$keepTextAreaAtCursor = !useragent.isIE;
11438     dom.addCssClass(container, "ace_editor");
11440     this.setTheme(theme);
11442     this.$gutter = dom.createElement("div");
11443     this.$gutter.className = "ace_gutter";
11444     this.container.appendChild(this.$gutter);
11446     this.scroller = dom.createElement("div");
11447     this.scroller.className = "ace_scroller";
11448     this.container.appendChild(this.scroller);
11450     this.content = dom.createElement("div");
11451     this.content.className = "ace_content";
11452     this.scroller.appendChild(this.content);
11454     this.setHighlightGutterLine(true);
11455     this.$gutterLayer = new GutterLayer(this.$gutter);
11456     this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
11458     this.$markerBack = new MarkerLayer(this.content);
11460     var textLayer = this.$textLayer = new TextLayer(this.content);
11461     this.canvas = textLayer.element;
11463     this.$markerFront = new MarkerLayer(this.content);
11465     this.characterWidth = textLayer.getCharacterWidth();
11466     this.lineHeight = textLayer.getLineHeight();
11468     this.$cursorLayer = new CursorLayer(this.content);
11469     this.$cursorPadding = 8;
11471     // Indicates whether the horizontal scrollbar is visible
11472     this.$horizScroll = false;
11473     this.$horizScrollAlwaysVisible = false;
11475     this.$animatedScroll = false;
11477     this.scrollBar = new ScrollBar(container);
11478     this.scrollBar.addEventListener("scroll", function(e) {
11479         if (!_self.$inScrollAnimation)
11480             _self.session.setScrollTop(e.data);
11481     });
11483     this.scrollTop = 0;
11484     this.scrollLeft = 0;
11486     event.addListener(this.scroller, "scroll", function() {
11487         var scrollLeft = _self.scroller.scrollLeft;
11488         _self.scrollLeft = scrollLeft;
11489         _self.session.setScrollLeft(scrollLeft);
11490     });
11492     this.cursorPos = {
11493         row : 0,
11494         column : 0
11495     };
11497     this.$textLayer.addEventListener("changeCharacterSize", function() {
11498         _self.characterWidth = textLayer.getCharacterWidth();
11499         _self.lineHeight = textLayer.getLineHeight();
11500         _self.$updatePrintMargin();
11501         _self.onResize(true);
11503         _self.$loop.schedule(_self.CHANGE_FULL);
11504     });
11506     this.$size = {
11507         width: 0,
11508         height: 0,
11509         scrollerHeight: 0,
11510         scrollerWidth: 0
11511     };
11513     this.layerConfig = {
11514         width : 1,
11515         padding : 0,
11516         firstRow : 0,
11517         firstRowScreen: 0,
11518         lastRow : 0,
11519         lineHeight : 1,
11520         characterWidth : 1,
11521         minHeight : 1,
11522         maxHeight : 1,
11523         offset : 0,
11524         height : 1
11525     };
11527     this.$loop = new RenderLoop(
11528         this.$renderChanges.bind(this),
11529         this.container.ownerDocument.defaultView
11530     );
11531     this.$loop.schedule(this.CHANGE_FULL);
11533     this.setPadding(4);
11534     this.$updatePrintMargin();
11537 (function() {
11538     this.showGutter = true;
11540     this.CHANGE_CURSOR = 1;
11541     this.CHANGE_MARKER = 2;
11542     this.CHANGE_GUTTER = 4;
11543     this.CHANGE_SCROLL = 8;
11544     this.CHANGE_LINES = 16;
11545     this.CHANGE_TEXT = 32;
11546     this.CHANGE_SIZE = 64;
11547     this.CHANGE_MARKER_BACK = 128;
11548     this.CHANGE_MARKER_FRONT = 256;
11549     this.CHANGE_FULL = 512;
11550     this.CHANGE_H_SCROLL = 1024;
11552     oop.implement(this, EventEmitter);
11553     this.setSession = function(session) {
11554         this.session = session;
11555         
11556         this.scroller.className = "ace_scroller";
11557         
11558         this.$cursorLayer.setSession(session);
11559         this.$markerBack.setSession(session);
11560         this.$markerFront.setSession(session);
11561         this.$gutterLayer.setSession(session);
11562         this.$textLayer.setSession(session);
11563         this.$loop.schedule(this.CHANGE_FULL);
11564         
11565     };
11566     this.updateLines = function(firstRow, lastRow) {
11567         if (lastRow === undefined)
11568             lastRow = Infinity;
11570         if (!this.$changedLines) {
11571             this.$changedLines = {
11572                 firstRow: firstRow,
11573                 lastRow: lastRow
11574             };
11575         }
11576         else {
11577             if (this.$changedLines.firstRow > firstRow)
11578                 this.$changedLines.firstRow = firstRow;
11580             if (this.$changedLines.lastRow < lastRow)
11581                 this.$changedLines.lastRow = lastRow;
11582         }
11584         this.$loop.schedule(this.CHANGE_LINES);
11585     };
11587     this.onChangeTabSize = function() {
11588         this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
11589         this.$textLayer.onChangeTabSize();
11590     };
11591     this.updateText = function() {
11592         this.$loop.schedule(this.CHANGE_TEXT);
11593     };
11594     this.updateFull = function(force) {
11595         if (force){
11596             this.$renderChanges(this.CHANGE_FULL, true);
11597         }
11598         else {
11599             this.$loop.schedule(this.CHANGE_FULL);
11600         }
11601     };
11602     this.updateFontSize = function() {
11603         this.$textLayer.checkForSizeChanges();
11604     };
11605     this.onResize = function(force, gutterWidth, width, height) {
11606         var changes = this.CHANGE_SIZE;
11607         var size = this.$size;
11609         if (this.resizing > 2)
11610             return;
11611         else if (this.resizing > 1)
11612             this.resizing++;
11613         else
11614             this.resizing = force ? 1 : 0;
11615         
11616         if (!height)
11617             height = dom.getInnerHeight(this.container);
11618         if (force || size.height != height) {
11619             size.height = height;
11621             this.scroller.style.height = height + "px";
11622             size.scrollerHeight = this.scroller.clientHeight;
11623             this.scrollBar.setHeight(size.scrollerHeight);
11625             if (this.session) {
11626                 this.session.setScrollTop(this.getScrollTop());
11627                 changes = changes | this.CHANGE_FULL;
11628             }
11629         }
11631         if (!width)
11632             width = dom.getInnerWidth(this.container);
11633         if (force || this.resizing > 1 || size.width != width) {
11634             size.width = width;
11636             var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
11637             this.scroller.style.left = gutterWidth + "px";
11638             size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth());
11639             this.scroller.style.right = this.scrollBar.getWidth() + "px";
11641             if (this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
11642                 changes = changes | this.CHANGE_FULL;
11643         }
11645         if (force)
11646             this.$renderChanges(changes, true);
11647         else
11648             this.$loop.schedule(changes);
11649         
11650         if (force)
11651             delete this.resizing;
11652     };
11653     this.adjustWrapLimit = function() {
11654         var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
11655         var limit = Math.floor(availableWidth / this.characterWidth);
11656         return this.session.adjustWrapLimit(limit);
11657     };
11658     this.setAnimatedScroll = function(shouldAnimate){
11659         this.$animatedScroll = shouldAnimate;
11660     };
11661     this.getAnimatedScroll = function() {
11662         return this.$animatedScroll;
11663     };
11664     this.setShowInvisibles = function(showInvisibles) {
11665         if (this.$textLayer.setShowInvisibles(showInvisibles))
11666             this.$loop.schedule(this.CHANGE_TEXT);
11667     };
11668     this.getShowInvisibles = function() {
11669         return this.$textLayer.showInvisibles;
11670     };
11672     this.getDisplayIndentGuides = function() {
11673         return this.$textLayer.displayIndentGuides;
11674     };
11675     
11676     this.setDisplayIndentGuides = function(display) {
11677         if (this.$textLayer.setDisplayIndentGuides(display))
11678             this.$loop.schedule(this.CHANGE_TEXT);
11679     };
11680     
11681     this.$showPrintMargin = true;
11682     this.setShowPrintMargin = function(showPrintMargin) {
11683         this.$showPrintMargin = showPrintMargin;
11684         this.$updatePrintMargin();
11685     };
11686     this.getShowPrintMargin = function() {
11687         return this.$showPrintMargin;
11688     };
11690     this.$printMarginColumn = 80;
11691     this.setPrintMarginColumn = function(showPrintMargin) {
11692         this.$printMarginColumn = showPrintMargin;
11693         this.$updatePrintMargin();
11694     };
11695     this.getPrintMarginColumn = function() {
11696         return this.$printMarginColumn;
11697     };
11698     this.getShowGutter = function(){
11699         return this.showGutter;
11700     };
11701     this.setShowGutter = function(show){
11702         if(this.showGutter === show)
11703             return;
11704         this.$gutter.style.display = show ? "block" : "none";
11705         this.showGutter = show;
11706         this.onResize(true);
11707     };
11709     this.getFadeFoldWidgets = function(){
11710         return dom.hasCssClass(this.$gutter, "ace_fade-fold-widgets");
11711     };
11713     this.setFadeFoldWidgets = function(show) {
11714         if (show)
11715             dom.addCssClass(this.$gutter, "ace_fade-fold-widgets");
11716         else
11717             dom.removeCssClass(this.$gutter, "ace_fade-fold-widgets");
11718     };
11720     this.$highlightGutterLine = false;
11721     this.setHighlightGutterLine = function(shouldHighlight) {
11722         if (this.$highlightGutterLine == shouldHighlight)
11723             return;
11724         this.$highlightGutterLine = shouldHighlight;
11726         if (!this.$gutterLineHighlight) {
11727             this.$gutterLineHighlight = dom.createElement("div");
11728             this.$gutterLineHighlight.className = "ace_gutter_active_line";
11729             this.$gutter.appendChild(this.$gutterLineHighlight);
11730             return;
11731         }
11733         this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
11734         // if cursorlayer have never been updated there's nothing on screen to update
11735         if (this.$cursorLayer.$pixelPos)
11736             this.$updateGutterLineHighlight();
11737     };
11739     this.getHighlightGutterLine = function() {
11740         return this.$highlightGutterLine;
11741     };
11743     this.$updateGutterLineHighlight = function() {
11744         this.$gutterLineHighlight.style.top = this.$cursorLayer.$pixelPos.top - this.layerConfig.offset + "px";
11745         this.$gutterLineHighlight.style.height = this.layerConfig.lineHeight + "px";
11746     };
11747     
11748     this.$updatePrintMargin = function() {
11749         var containerEl;
11751         if (!this.$showPrintMargin && !this.$printMarginEl)
11752             return;
11754         if (!this.$printMarginEl) {
11755             containerEl = dom.createElement("div");
11756             containerEl.className = "ace_print_margin_layer";
11757             this.$printMarginEl = dom.createElement("div");
11758             this.$printMarginEl.className = "ace_print_margin";
11759             containerEl.appendChild(this.$printMarginEl);
11760             this.content.insertBefore(containerEl, this.$textLayer.element);
11761         }
11763         var style = this.$printMarginEl.style;
11764         style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
11765         style.visibility = this.$showPrintMargin ? "visible" : "hidden";
11766     };
11767     this.getContainerElement = function() {
11768         return this.container;
11769     };
11770     this.getMouseEventTarget = function() {
11771         return this.content;
11772     };
11773     this.getTextAreaContainer = function() {
11774         return this.container;
11775     };
11777     // move text input over the cursor
11778     // this is required for iOS and IME
11779     this.$moveTextAreaToCursor = function() {
11780         if (!this.$keepTextAreaAtCursor)
11781             return;
11783         var posTop = this.$cursorLayer.$pixelPos.top;
11784         var posLeft = this.$cursorLayer.$pixelPos.left;
11785         posTop -= this.layerConfig.offset;
11787         if (posTop < 0 || posTop > this.layerConfig.height - this.lineHeight)
11788             return;
11790         var w = this.characterWidth;
11791         if (this.$composition)
11792             w += this.textarea.scrollWidth;
11793         posLeft -= this.scrollLeft;
11794         if (posLeft > this.$size.scrollerWidth - w)
11795             posLeft = this.$size.scrollerWidth - w;
11797         if (this.showGutter)
11798             posLeft += this.$gutterLayer.gutterWidth;
11800         this.textarea.style.height = this.lineHeight + "px";
11801         this.textarea.style.width = w + "px";
11802         this.textarea.style.left = posLeft + "px";
11803         this.textarea.style.top = posTop - 1 + "px";
11804     };
11805     this.getFirstVisibleRow = function() {
11806         return this.layerConfig.firstRow;
11807     };
11808     this.getFirstFullyVisibleRow = function() {
11809         return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
11810     };
11811     this.getLastFullyVisibleRow = function() {
11812         var flint = Math.floor((this.layerConfig.height + this.layerConfig.offset) / this.layerConfig.lineHeight);
11813         return this.layerConfig.firstRow - 1 + flint;
11814     };
11815     this.getLastVisibleRow = function() {
11816         return this.layerConfig.lastRow;
11817     };
11819     this.$padding = null;
11820     this.setPadding = function(padding) {
11821         this.$padding = padding;
11822         this.$textLayer.setPadding(padding);
11823         this.$cursorLayer.setPadding(padding);
11824         this.$markerFront.setPadding(padding);
11825         this.$markerBack.setPadding(padding);
11826         this.$loop.schedule(this.CHANGE_FULL);
11827         this.$updatePrintMargin();
11828     };
11829     this.getHScrollBarAlwaysVisible = function() {
11830         return this.$horizScrollAlwaysVisible;
11831     };
11832     this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
11833         if (this.$horizScrollAlwaysVisible != alwaysVisible) {
11834             this.$horizScrollAlwaysVisible = alwaysVisible;
11835             if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
11836                 this.$loop.schedule(this.CHANGE_SCROLL);
11837         }
11838     };
11840     this.$updateScrollBar = function() {
11841         this.scrollBar.setInnerHeight(this.layerConfig.maxHeight);
11842         this.scrollBar.setScrollTop(this.scrollTop);
11843     };
11845     this.$renderChanges = function(changes, force) {
11846         if (!force && (!changes || !this.session || !this.container.offsetWidth))
11847             return;
11849         // text, scrolling and resize changes can cause the view port size to change
11850         if (changes & this.CHANGE_FULL ||
11851             changes & this.CHANGE_SIZE ||
11852             changes & this.CHANGE_TEXT ||
11853             changes & this.CHANGE_LINES ||
11854             changes & this.CHANGE_SCROLL
11855         )
11856             this.$computeLayerConfig();
11858         // horizontal scrolling
11859         if (changes & this.CHANGE_H_SCROLL) {
11860             this.scroller.scrollLeft = this.scrollLeft;
11862             // read the value after writing it since the value might get clipped
11863             var scrollLeft = this.scroller.scrollLeft;
11864             this.scrollLeft = scrollLeft;
11865             this.session.setScrollLeft(scrollLeft);
11867             this.scroller.className = this.scrollLeft == 0 ? "ace_scroller" : "ace_scroller horscroll";
11868         }
11870         // full
11871         if (changes & this.CHANGE_FULL) {
11872             this.$textLayer.checkForSizeChanges();
11873             // update scrollbar first to not lose scroll position when gutter calls resize
11874             this.$updateScrollBar();
11875             this.$textLayer.update(this.layerConfig);
11876             if (this.showGutter)
11877                 this.$gutterLayer.update(this.layerConfig);
11878             this.$markerBack.update(this.layerConfig);
11879             this.$markerFront.update(this.layerConfig);
11880             this.$cursorLayer.update(this.layerConfig);
11881             this.$moveTextAreaToCursor();
11882             this.$highlightGutterLine && this.$updateGutterLineHighlight();
11883             return;
11884         }
11886         // scrolling
11887         if (changes & this.CHANGE_SCROLL) {
11888             this.$updateScrollBar();
11889             if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
11890                 this.$textLayer.update(this.layerConfig);
11891             else
11892                 this.$textLayer.scrollLines(this.layerConfig);
11894             if (this.showGutter)
11895                 this.$gutterLayer.update(this.layerConfig);
11896             this.$markerBack.update(this.layerConfig);
11897             this.$markerFront.update(this.layerConfig);
11898             this.$cursorLayer.update(this.layerConfig);
11899             this.$moveTextAreaToCursor();
11900             this.$highlightGutterLine && this.$updateGutterLineHighlight();
11901             return;
11902         }
11904         if (changes & this.CHANGE_TEXT) {
11905             this.$textLayer.update(this.layerConfig);
11906             if (this.showGutter)
11907                 this.$gutterLayer.update(this.layerConfig);
11908         }
11909         else if (changes & this.CHANGE_LINES) {
11910             if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.showGutter)
11911                 this.$gutterLayer.update(this.layerConfig);
11912         }
11913         else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
11914             if (this.showGutter)
11915                 this.$gutterLayer.update(this.layerConfig);
11916         }
11918         if (changes & this.CHANGE_CURSOR) {
11919             this.$cursorLayer.update(this.layerConfig);
11920             this.$moveTextAreaToCursor();
11921             this.$highlightGutterLine && this.$updateGutterLineHighlight();
11922         }
11924         if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
11925             this.$markerFront.update(this.layerConfig);
11926         }
11928         if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
11929             this.$markerBack.update(this.layerConfig);
11930         }
11932         if (changes & this.CHANGE_SIZE)
11933             this.$updateScrollBar();
11934     };
11936     this.$computeLayerConfig = function() {
11937         var session = this.session;
11939         var offset = this.scrollTop % this.lineHeight;
11940         var minHeight = this.$size.scrollerHeight + this.lineHeight;
11942         var longestLine = this.$getLongestLine();
11944         var horizScroll = this.$horizScrollAlwaysVisible || this.$size.scrollerWidth - longestLine < 0;
11945         var horizScrollChanged = this.$horizScroll !== horizScroll;
11946         this.$horizScroll = horizScroll;
11947         if (horizScrollChanged) {
11948             this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
11949             // when we hide scrollbar scroll event isn't emited
11950             // leaving session with wrong scrollLeft value
11951             if (!horizScroll)
11952                 this.session.setScrollLeft(0);
11953         }
11954         var maxHeight = this.session.getScreenLength() * this.lineHeight;
11955         this.session.setScrollTop(Math.max(0, Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight)));
11957         var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
11958         var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
11959         var lastRow = firstRow + lineCount;
11961         // Map lines on the screen to lines in the document.
11962         var firstRowScreen, firstRowHeight;
11963         var lineHeight = this.lineHeight;
11964         firstRow = session.screenToDocumentRow(firstRow, 0);
11966         // Check if firstRow is inside of a foldLine. If true, then use the first
11967         // row of the foldLine.
11968         var foldLine = session.getFoldLine(firstRow);
11969         if (foldLine) {
11970             firstRow = foldLine.start.row;
11971         }
11973         firstRowScreen = session.documentToScreenRow(firstRow, 0);
11974         firstRowHeight = session.getRowLength(firstRow) * lineHeight;
11976         lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
11977         minHeight = this.$size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
11978                                                 firstRowHeight;
11980         offset = this.scrollTop - firstRowScreen * lineHeight;
11982         this.layerConfig = {
11983             width : longestLine,
11984             padding : this.$padding,
11985             firstRow : firstRow,
11986             firstRowScreen: firstRowScreen,
11987             lastRow : lastRow,
11988             lineHeight : lineHeight,
11989             characterWidth : this.characterWidth,
11990             minHeight : minHeight,
11991             maxHeight : maxHeight,
11992             offset : offset,
11993             height : this.$size.scrollerHeight
11994         };
11996         // For debugging.
11997         // console.log(JSON.stringify(this.layerConfig));
11999         this.$gutterLayer.element.style.marginTop = (-offset) + "px";
12000         this.content.style.marginTop = (-offset) + "px";
12001         this.content.style.width = longestLine + 2 * this.$padding + "px";
12002         this.content.style.height = minHeight + "px";
12004         // Horizontal scrollbar visibility may have changed, which changes
12005         // the client height of the scroller
12006         if (horizScrollChanged)
12007             this.onResize(true);
12008     };
12010     this.$updateLines = function() {
12011         var firstRow = this.$changedLines.firstRow;
12012         var lastRow = this.$changedLines.lastRow;
12013         this.$changedLines = null;
12015         var layerConfig = this.layerConfig;
12017         if (firstRow > layerConfig.lastRow + 1) { return; }
12018         if (lastRow < layerConfig.firstRow) { return; }
12020         // if the last row is unknown -> redraw everything
12021         if (lastRow === Infinity) {
12022             if (this.showGutter)
12023                 this.$gutterLayer.update(layerConfig);
12024             this.$textLayer.update(layerConfig);
12025             return;
12026         }
12028         // else update only the changed rows
12029         this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
12030         return true;
12031     };
12033     this.$getLongestLine = function() {
12034         var charCount = this.session.getScreenWidth();
12035         if (this.$textLayer.showInvisibles)
12036             charCount += 1;
12038         return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
12039     };
12040     this.updateFrontMarkers = function() {
12041         this.$markerFront.setMarkers(this.session.getMarkers(true));
12042         this.$loop.schedule(this.CHANGE_MARKER_FRONT);
12043     };
12044     this.updateBackMarkers = function() {
12045         this.$markerBack.setMarkers(this.session.getMarkers());
12046         this.$loop.schedule(this.CHANGE_MARKER_BACK);
12047     };
12048     this.addGutterDecoration = function(row, className){
12049         this.$gutterLayer.addGutterDecoration(row, className);
12050     };
12051     this.removeGutterDecoration = function(row, className){
12052         this.$gutterLayer.removeGutterDecoration(row, className);
12053     };
12054     this.updateBreakpoints = function(rows) {
12055         this.$loop.schedule(this.CHANGE_GUTTER);
12056     };
12057     this.setAnnotations = function(annotations) {
12058         this.$gutterLayer.setAnnotations(annotations);
12059         this.$loop.schedule(this.CHANGE_GUTTER);
12060     };
12061     this.updateCursor = function() {
12062         this.$loop.schedule(this.CHANGE_CURSOR);
12063     };
12064     this.hideCursor = function() {
12065         this.$cursorLayer.hideCursor();
12066     };
12067     this.showCursor = function() {
12068         this.$cursorLayer.showCursor();
12069     };
12071     this.scrollSelectionIntoView = function(anchor, lead, offset) {
12072         // first scroll anchor into view then scroll lead into view
12073         this.scrollCursorIntoView(anchor, offset);
12074         this.scrollCursorIntoView(lead, offset);
12075     };
12076     this.scrollCursorIntoView = function(cursor, offset) {
12077         // the editor is not visible
12078         if (this.$size.scrollerHeight === 0)
12079             return;
12081         var pos = this.$cursorLayer.getPixelPosition(cursor);
12083         var left = pos.left;
12084         var top = pos.top;
12086         if (this.scrollTop > top) {
12087             if (offset)
12088                 top -= offset * this.$size.scrollerHeight;
12089             this.session.setScrollTop(top);
12090         } else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
12091             if (offset)
12092                 top += offset * this.$size.scrollerHeight;
12093             this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
12094         }
12096         var scrollLeft = this.scrollLeft;
12098         if (scrollLeft > left) {
12099             if (left < this.$padding + 2 * this.layerConfig.characterWidth)
12100                 left = 0;
12101             this.session.setScrollLeft(left);
12102         } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
12103             this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
12104         }
12105     };
12106     this.getScrollTop = function() {
12107         return this.session.getScrollTop();
12108     };
12109     this.getScrollLeft = function() {
12110         return this.session.getScrollLeft();
12111     };
12112     this.getScrollTopRow = function() {
12113         return this.scrollTop / this.lineHeight;
12114     };
12115     this.getScrollBottomRow = function() {
12116         return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
12117     };
12118     this.scrollToRow = function(row) {
12119         this.session.setScrollTop(row * this.lineHeight);
12120     };
12122     this.alignCursor = function(cursor, alignment) {
12123         if (typeof cursor == "number")
12124             cursor = {row: cursor, column: 0};
12126         var pos = this.$cursorLayer.getPixelPosition(cursor);
12127         var h = this.$size.scrollerHeight - this.lineHeight;
12128         var offset = pos.top - h * (alignment || 0);
12130         this.session.setScrollTop(offset);
12131         return offset;
12132     };
12134     this.STEPS = 8;
12135     this.$calcSteps = function(fromValue, toValue){
12136         var i = 0;
12137         var l = this.STEPS;
12138         var steps = [];
12140         var func  = function(t, x_min, dx) {
12141             return dx * (Math.pow(t - 1, 3) + 1) + x_min;
12142         };
12144         for (i = 0; i < l; ++i)
12145             steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
12147         return steps;
12148     };
12149     this.scrollToLine = function(line, center, animate, callback) {
12150         var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
12151         var offset = pos.top;
12152         if (center)
12153             offset -= this.$size.scrollerHeight / 2;
12155         var initialScroll = this.scrollTop;
12156         this.session.setScrollTop(offset);
12157         if (animate !== false)
12158             this.animateScrolling(initialScroll, callback);
12159     };
12161     this.animateScrolling = function(fromValue, callback) {
12162         var toValue = this.scrollTop;
12163         if (this.$animatedScroll && Math.abs(fromValue - toValue) < 100000) {
12164             var _self = this;
12165             var steps = _self.$calcSteps(fromValue, toValue);
12166             this.$inScrollAnimation = true;
12168             clearInterval(this.$timer);
12170             _self.session.setScrollTop(steps.shift());
12171             this.$timer = setInterval(function() {
12172                 if (steps.length) {
12173                     _self.session.setScrollTop(steps.shift());
12174                     // trick session to think it's already scrolled to not loose toValue
12175                     _self.session.$scrollTop = toValue;
12176                 } else if (toValue != null) {
12177                     _self.session.$scrollTop = -1;
12178                     _self.session.setScrollTop(toValue);
12179                     toValue = null;
12180                 } else {
12181                     // do this on separate step to not get spurious scroll event from scrollbar
12182                     _self.$timer = clearInterval(_self.$timer);
12183                     _self.$inScrollAnimation = false;
12184                     callback && callback();
12185                 }
12186             }, 10);
12187         }
12188     };
12189     this.scrollToY = function(scrollTop) {
12190         // after calling scrollBar.setScrollTop
12191         // scrollbar sends us event with same scrollTop. ignore it
12192         if (this.scrollTop !== scrollTop) {
12193             this.$loop.schedule(this.CHANGE_SCROLL);
12194             this.scrollTop = scrollTop;
12195         }
12196     };
12197     this.scrollToX = function(scrollLeft) {
12198         if (scrollLeft < 0)
12199             scrollLeft = 0;
12201         if (this.scrollLeft !== scrollLeft)
12202             this.scrollLeft = scrollLeft;
12203         this.$loop.schedule(this.CHANGE_H_SCROLL);
12204     };
12205     this.scrollBy = function(deltaX, deltaY) {
12206         deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
12207         deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
12208     };
12209     this.isScrollableBy = function(deltaX, deltaY) {
12210         if (deltaY < 0 && this.session.getScrollTop() > 0)
12211            return true;
12212         if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight < this.layerConfig.maxHeight)
12213            return true;
12214         // todo: handle horizontal scrolling
12215     };
12217     this.pixelToScreenCoordinates = function(x, y) {
12218         var canvasPos = this.scroller.getBoundingClientRect();
12220         var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth;
12221         var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
12222         var col = Math.round(offset);
12224         return {row: row, column: col, side: offset - col > 0 ? 1 : -1};
12225     };
12227     this.screenToTextCoordinates = function(x, y) {
12228         var canvasPos = this.scroller.getBoundingClientRect();
12230         var col = Math.round(
12231             (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
12232         );
12233         var row = Math.floor(
12234             (y + this.scrollTop - canvasPos.top) / this.lineHeight
12235         );
12237         return this.session.screenToDocumentPosition(row, Math.max(col, 0));
12238     };
12239     this.textToScreenCoordinates = function(row, column) {
12240         var canvasPos = this.scroller.getBoundingClientRect();
12241         var pos = this.session.documentToScreenPosition(row, column);
12243         var x = this.$padding + Math.round(pos.column * this.characterWidth);
12244         var y = pos.row * this.lineHeight;
12246         return {
12247             pageX: canvasPos.left + x - this.scrollLeft,
12248             pageY: canvasPos.top + y - this.scrollTop
12249         };
12250     };
12251     this.visualizeFocus = function() {
12252         dom.addCssClass(this.container, "ace_focus");
12253     };
12254     this.visualizeBlur = function() {
12255         dom.removeCssClass(this.container, "ace_focus");
12256     };
12257     this.showComposition = function(position) {
12258         if (!this.$composition)
12259             this.$composition = {
12260                 keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
12261                 cssText: this.textarea.style.cssText
12262             };
12264         this.$keepTextAreaAtCursor = true;
12265         dom.addCssClass(this.textarea, "ace_composition");
12266         this.textarea.style.cssText = "";
12267         this.$moveTextAreaToCursor();
12268     };
12269     this.setCompositionText = function(text) {
12270         this.$moveTextAreaToCursor();
12271     };
12272     this.hideComposition = function() {
12273         if (!this.$composition)
12274             return;
12276         dom.removeCssClass(this.textarea, "ace_composition");
12277         this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
12278         this.textarea.style.cssText = this.$composition.cssText;
12279         this.$composition = null;
12280     };
12282     this._loadTheme = function(name, callback) {
12283         if (!config.get("packaged"))
12284             return callback();
12286         net.loadScript(config.moduleUrl(name, "theme"), callback);
12287     };
12288     this.setTheme = function(theme) {
12289         var _self = this;
12291         this.$themeValue = theme;
12292         if (!theme || typeof theme == "string") {
12293             var moduleName = theme || "ace/theme/textmate";
12295             var module;
12296             try {
12297                 module = require(moduleName);
12298             } catch (e) {};
12299             if (module)
12300                 return afterLoad(module);
12302             _self._loadTheme(moduleName, function() {
12303                 require([moduleName], function(module) {
12304                     if (_self.$themeValue !== theme)
12305                         return;
12307                     afterLoad(module);
12308                 });
12309             });
12310         } else {
12311             afterLoad(theme);
12312         }
12314         function afterLoad(theme) {
12315             dom.importCssString(
12316                 theme.cssText,
12317                 theme.cssClass,
12318                 _self.container.ownerDocument
12319             );
12321             if (_self.$theme)
12322                 dom.removeCssClass(_self.container, _self.$theme);
12324             _self.$theme = theme ? theme.cssClass : null;
12326             if (_self.$theme)
12327                 dom.addCssClass(_self.container, _self.$theme);
12329             if (theme && theme.isDark)
12330                 dom.addCssClass(_self.container, "ace_dark");
12331             else
12332                 dom.removeCssClass(_self.container, "ace_dark");
12334             // force re-measure of the gutter width
12335             if (_self.$size) {
12336                 _self.$size.width = 0;
12337                 _self.onResize();
12338             }
12339         }
12340     };
12341     this.getTheme = function() {
12342         return this.$themeValue;
12343     };
12345     // Methods allows to add / remove CSS classnames to the editor element.
12346     // This feature can be used by plug-ins to provide a visual indication of
12347     // a certain mode that editor is in.
12349     /**
12350     * VirtualRenderer.setStyle(style)
12351     * - style (String): A class name
12352     *
12353     * [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle}
12354     **/
12355     this.setStyle = function setStyle(style) {
12356       dom.addCssClass(this.container, style);
12357     };
12358     this.unsetStyle = function unsetStyle(style) {
12359       dom.removeCssClass(this.container, style);
12360     };
12361     this.destroy = function() {
12362         this.$textLayer.destroy();
12363         this.$cursorLayer.destroy();
12364     };
12366 }).call(VirtualRenderer.prototype);
12368 exports.VirtualRenderer = VirtualRenderer;
12371 define('ace/layer/gutter', ['require', 'exports', 'module' , 'ace/lib/dom', 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
12374 var dom = require("../lib/dom");
12375 var oop = require("../lib/oop");
12376 var EventEmitter = require("../lib/event_emitter").EventEmitter;
12378 var Gutter = function(parentEl) {
12379     this.element = dom.createElement("div");
12380     this.element.className = "ace_layer ace_gutter-layer";
12381     parentEl.appendChild(this.element);
12382     this.setShowFoldWidgets(this.$showFoldWidgets);
12383     
12384     this.gutterWidth = 0;
12386     this.$annotations = [];
12389 (function() {
12391     oop.implement(this, EventEmitter);
12392     
12393     this.setSession = function(session) {
12394         this.session = session;
12395     };
12397     this.addGutterDecoration = function(row, className){
12398         if (window.console)
12399             console.warn && console.warn("deprecated use session.addGutterDecoration");
12400         this.session.addGutterDecoration(row, className);
12401     };
12403     this.removeGutterDecoration = function(row, className){
12404         if (window.console)
12405             console.warn && console.warn("deprecated use session.removeGutterDecoration");
12406         this.session.removeGutterDecoration(row, className);
12407     };
12409     this.setAnnotations = function(annotations) {
12410         // iterate over sparse array
12411         this.$annotations = [];
12412         for (var row in annotations) if (annotations.hasOwnProperty(row)) {
12413             var rowAnnotations = annotations[row];
12414             if (!rowAnnotations)
12415                 continue;
12417             var rowInfo = this.$annotations[row] = {
12418                 text: []
12419             };
12420             for (var i=0; i<rowAnnotations.length; i++) {
12421                 var annotation = rowAnnotations[i];
12422                 var annoText = annotation.text.replace(/"/g, "&quot;").replace(/'/g, "&#8217;").replace(/</, "&lt;");
12423                 if (rowInfo.text.indexOf(annoText) === -1)
12424                     rowInfo.text.push(annoText);
12425                 var type = annotation.type;
12426                 if (type == "error")
12427                     rowInfo.className = " ace_error";
12428                 else if (type == "warning" && rowInfo.className != " ace_error")
12429                     rowInfo.className = " ace_warning";
12430                 else if (type == "info" && (!rowInfo.className))
12431                     rowInfo.className = " ace_info";
12432             }
12433         }
12434     };
12436     this.update = function(config) {
12437         var emptyAnno = {className: ""};
12438         var html = [];
12439         var i = config.firstRow;
12440         var lastRow = config.lastRow;
12441         var fold = this.session.getNextFoldLine(i);
12442         var foldStart = fold ? fold.start.row : Infinity;
12443         var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets;
12444         var breakpoints = this.session.$breakpoints;
12445         var decorations = this.session.$decorations;
12446         var lastLineNumber = 0;
12448         while (true) {
12449             if(i > foldStart) {
12450                 i = fold.end.row + 1;
12451                 fold = this.session.getNextFoldLine(i, fold);
12452                 foldStart = fold ?fold.start.row :Infinity;
12453             }
12454             if(i > lastRow)
12455                 break;
12457             var annotation = this.$annotations[i] || emptyAnno;
12458             html.push(
12459                 "<div class='ace_gutter-cell ",
12460                 breakpoints[i] || "", decorations[i] || "", annotation.className,
12461                 "' style='height:", this.session.getRowLength(i) * config.lineHeight, "px;'>", 
12462                 lastLineNumber = i + 1
12463             );
12465             if (foldWidgets) {
12466                 var c = foldWidgets[i];
12467                 // check if cached value is invalidated and we need to recompute
12468                 if (c == null)
12469                     c = foldWidgets[i] = this.session.getFoldWidget(i);
12470                 if (c)
12471                     html.push(
12472                         "<span class='ace_fold-widget ", c,
12473                         c == "start" && i == foldStart && i < fold.end.row ? " closed" : " open",
12474                         "' style='height:", config.lineHeight, "px",
12475                         "'></span>"
12476                     );
12477             }
12479             html.push("</div>");
12481             i++;
12482         }
12484         this.element = dom.setInnerHtml(this.element, html.join(""));
12485         this.element.style.height = config.minHeight + "px";
12486         
12487         if (this.session.$useWrapMode)
12488             lastLineNumber = this.session.getLength();
12489         
12490         var gutterWidth = ("" + lastLineNumber).length * config.characterWidth;
12491         var padding = this.$padding || this.$computePadding();
12492         gutterWidth += padding.left + padding.right;
12493         if (gutterWidth !== this.gutterWidth) {
12494             this.gutterWidth = gutterWidth;
12495             this.element.style.width = Math.ceil(this.gutterWidth) + "px";
12496             this._emit("changeGutterWidth", gutterWidth);
12497         }
12498     };
12500     this.$showFoldWidgets = true;
12501     this.setShowFoldWidgets = function(show) {
12502         if (show)
12503             dom.addCssClass(this.element, "ace_folding-enabled");
12504         else
12505             dom.removeCssClass(this.element, "ace_folding-enabled");
12507         this.$showFoldWidgets = show;
12508         this.$padding = null;
12509     };
12510     
12511     this.getShowFoldWidgets = function() {
12512         return this.$showFoldWidgets;
12513     };
12515     this.$computePadding = function() {
12516         if (!this.element.firstChild)
12517             return {left: 0, right: 0};
12518         var style = dom.computedStyle(this.element.firstChild);
12519         this.$padding = {}
12520         this.$padding.left = parseInt(style.paddingLeft) + 1;
12521         this.$padding.right = parseInt(style.paddingRight);  
12522         return this.$padding;
12523     };
12525     this.getRegion = function(point) {
12526         var padding = this.$padding || this.$computePadding();
12527         var rect = this.element.getBoundingClientRect();
12528         if (point.x < padding.left + rect.left)
12529             return "markers";
12530         if (this.$showFoldWidgets && point.x > rect.right - padding.right)
12531             return "foldWidgets";
12532     };
12534 }).call(Gutter.prototype);
12536 exports.Gutter = Gutter;
12540 define('ace/layer/marker', ['require', 'exports', 'module' , 'ace/range', 'ace/lib/dom'], function(require, exports, module) {
12543 var Range = require("../range").Range;
12544 var dom = require("../lib/dom");
12546 var Marker = function(parentEl) {
12547     this.element = dom.createElement("div");
12548     this.element.className = "ace_layer ace_marker-layer";
12549     parentEl.appendChild(this.element);
12552 (function() {
12554     this.$padding = 0;
12556     this.setPadding = function(padding) {
12557         this.$padding = padding;
12558     };
12559     this.setSession = function(session) {
12560         this.session = session;
12561     };
12562     
12563     this.setMarkers = function(markers) {
12564         this.markers = markers;
12565     };
12567     this.update = function(config) {
12568         var config = config || this.config;
12569         if (!config)
12570             return;
12572         this.config = config;
12575         var html = [];
12576         for (var key in this.markers) {
12577             var marker = this.markers[key];
12579             if (!marker.range) {
12580                 marker.update(html, this, this.session, config);
12581                 continue;
12582             }
12584             var range = marker.range.clipRows(config.firstRow, config.lastRow);
12585             if (range.isEmpty()) continue;
12587             range = range.toScreenRange(this.session);
12588             if (marker.renderer) {
12589                 var top = this.$getTop(range.start.row, config);
12590                 var left = Math.round(
12591                     this.$padding + range.start.column * config.characterWidth
12592                 );
12593                 marker.renderer(html, range, left, top, config);
12594             }
12595             else if (range.isMultiLine()) {
12596                 if (marker.type == "text") {
12597                     this.drawTextMarker(html, range, marker.clazz, config);
12598                 } else {
12599                     this.drawMultiLineMarker(
12600                         html, range, marker.clazz, config,
12601                         marker.type
12602                     );
12603                 }
12604             }
12605             else {
12606                 this.drawSingleLineMarker(
12607                     html, range, marker.clazz + " start", config,
12608                     null, marker.type
12609                 );
12610             }
12611         }
12612         this.element = dom.setInnerHtml(this.element, html.join(""));
12613     };
12615     this.$getTop = function(row, layerConfig) {
12616         return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
12617     };
12619     // Draws a marker, which spans a range of text on multiple lines 
12620     this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig) {
12621         // selection start
12622         var row = range.start.row;
12624         var lineRange = new Range(
12625             row, range.start.column,
12626             row, this.session.getScreenLastRowColumn(row)
12627         );
12628         this.drawSingleLineMarker(stringBuilder, lineRange, clazz + " start", layerConfig, 1, "text");
12630         // selection end
12631         row = range.end.row;
12632         lineRange = new Range(row, 0, row, range.end.column);
12633         this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, "text");
12635         for (row = range.start.row + 1; row < range.end.row; row++) {
12636             lineRange.start.row = row;
12637             lineRange.end.row = row;
12638             lineRange.end.column = this.session.getScreenLastRowColumn(row);
12639             this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, "text");
12640         }
12641     };
12643     // Draws a multi line marker, where lines span the full width
12644     this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, type) {
12645         var padding = type === "background" ? 0 : this.$padding;
12646         // from selection start to the end of the line
12647         var height = config.lineHeight;
12648         var top = this.$getTop(range.start.row, config);
12649         var left = Math.round(padding + range.start.column * config.characterWidth);
12651         stringBuilder.push(
12652             "<div class='", clazz, " start' style='",
12653             "height:", height, "px;",
12654             "right:0;",
12655             "top:", top, "px;",
12656             "left:", left, "px;'></div>"
12657         );
12659         // from start of the last line to the selection end
12660         top = this.$getTop(range.end.row, config);
12661         var width = Math.round(range.end.column * config.characterWidth);
12663         stringBuilder.push(
12664             "<div class='", clazz, "' style='",
12665             "height:", height, "px;",
12666             "width:", width, "px;",
12667             "top:", top, "px;",
12668             "left:", padding, "px;'></div>"
12669         );
12671         // all the complete lines
12672         height = (range.end.row - range.start.row - 1) * config.lineHeight;
12673         if (height < 0)
12674             return;
12675         top = this.$getTop(range.start.row + 1, config);
12677         stringBuilder.push(
12678             "<div class='", clazz, "' style='",
12679             "height:", height, "px;",
12680             "right:0;",
12681             "top:", top, "px;",
12682             "left:", padding, "px;'></div>"
12683         );
12684     };
12686     // Draws a marker which covers part or whole width of a single screen line
12687     this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig, extraLength, type) {
12688         var padding = type === "background" ? 0 : this.$padding;
12689         var height = layerConfig.lineHeight;
12691         if (type === "background")
12692             var width = layerConfig.width;
12693         else
12694             width = Math.round((range.end.column + (extraLength || 0) - range.start.column) * layerConfig.characterWidth);
12696         var top = this.$getTop(range.start.row, layerConfig);
12697         var left = Math.round(
12698             padding + range.start.column * layerConfig.characterWidth
12699         );
12701         stringBuilder.push(
12702             "<div class='", clazz, "' style='",
12703             "height:", height, "px;",
12704             "width:", width, "px;",
12705             "top:", top, "px;",
12706             "left:", left,"px;'></div>"
12707         );
12708     };
12710 }).call(Marker.prototype);
12712 exports.Marker = Marker;
12716 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) {
12719 var oop = require("../lib/oop");
12720 var dom = require("../lib/dom");
12721 var lang = require("../lib/lang");
12722 var useragent = require("../lib/useragent");
12723 var EventEmitter = require("../lib/event_emitter").EventEmitter;
12725 var Text = function(parentEl) {
12726     this.element = dom.createElement("div");
12727     this.element.className = "ace_layer ace_text-layer";
12728     parentEl.appendChild(this.element);
12730     this.$characterSize = this.$measureSizes() || {width: 0, height: 0};
12731     this.$pollSizeChanges();
12734 (function() {
12736     oop.implement(this, EventEmitter);
12738     this.EOF_CHAR = "\xB6"; //"&para;";
12739     this.EOL_CHAR = "\xAC"; //"&not;";
12740     this.TAB_CHAR = "\u2192"; //"&rarr;" "\u21E5";
12741     this.SPACE_CHAR = "\xB7"; //"&middot;";
12742     this.$padding = 0;
12744     this.setPadding = function(padding) {
12745         this.$padding = padding;
12746         this.element.style.padding = "0 " + padding + "px";
12747     };
12749     this.getLineHeight = function() {
12750         return this.$characterSize.height || 1;
12751     };
12753     this.getCharacterWidth = function() {
12754         return this.$characterSize.width || 1;
12755     };
12757     this.checkForSizeChanges = function() {
12758         var size = this.$measureSizes();
12759         if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
12760             this.$characterSize = size;
12761             this._emit("changeCharacterSize", {data: size});
12762         }
12763     };
12765     this.$pollSizeChanges = function() {
12766         var self = this;
12767         this.$pollSizeChangesTimer = setInterval(function() {
12768             self.checkForSizeChanges();
12769         }, 500);
12770     };
12772     this.$fontStyles = {
12773         fontFamily : 1,
12774         fontSize : 1,
12775         fontWeight : 1,
12776         fontStyle : 1,
12777         lineHeight : 1
12778     };
12780     this.$measureSizes = useragent.isIE || useragent.isOldGecko ? function() {
12781         var n = 1000;
12782         if (!this.$measureNode) {
12783             var measureNode = this.$measureNode = dom.createElement("div");
12784             var style = measureNode.style;
12786             style.width = style.height = "auto";
12787             style.left = style.top = (-n * 40)  + "px";
12789             style.visibility = "hidden";
12790             style.position = "fixed";
12791             style.overflow = "visible";
12792             style.whiteSpace = "nowrap";
12794             // in FF 3.6 monospace fonts can have a fixed sub pixel width.
12795             // that's why we have to measure many characters
12796             // Note: characterWidth can be a float!
12797             measureNode.innerHTML = lang.stringRepeat("Xy", n);
12799             if (this.element.ownerDocument.body) {
12800                 this.element.ownerDocument.body.appendChild(measureNode);
12801             } else {
12802                 var container = this.element.parentNode;
12803                 while (!dom.hasCssClass(container, "ace_editor"))
12804                     container = container.parentNode;
12805                 container.appendChild(measureNode);
12806             }
12807         }
12809         // Size and width can be null if the editor is not visible or
12810         // detached from the document
12811         if (!this.element.offsetWidth)
12812             return null;
12814         var style = this.$measureNode.style;
12815         var computedStyle = dom.computedStyle(this.element);
12816         for (var prop in this.$fontStyles)
12817             style[prop] = computedStyle[prop];
12819         var size = {
12820             height: this.$measureNode.offsetHeight,
12821             width: this.$measureNode.offsetWidth / (n * 2)
12822         };
12824         // Size and width can be null if the editor is not visible or
12825         // detached from the document
12826         if (size.width == 0 || size.height == 0)
12827             return null;
12829         return size;
12830     }
12831     : function() {
12832         if (!this.$measureNode) {
12833             var measureNode = this.$measureNode = dom.createElement("div");
12834             var style = measureNode.style;
12836             style.width = style.height = "auto";
12837             style.left = style.top = -100 + "px";
12839             style.visibility = "hidden";
12840             style.position = "fixed";
12841             style.overflow = "visible";
12842             style.whiteSpace = "nowrap";
12844             measureNode.innerHTML = "X";
12846             var container = this.element.parentNode;
12847             while (container && !dom.hasCssClass(container, "ace_editor"))
12848                 container = container.parentNode;
12850             if (!container)
12851                 return this.$measureNode = null;
12853             container.appendChild(measureNode);
12854         }
12856         var rect = this.$measureNode.getBoundingClientRect();
12858         var size = {
12859             height: rect.height,
12860             width: rect.width
12861         };
12863         // Size and width can be null if the editor is not visible or
12864         // detached from the document
12865         if (size.width == 0 || size.height == 0)
12866             return null;
12868         return size;
12869     };
12871     this.setSession = function(session) {
12872         this.session = session;
12873         this.$computeTabString();
12874     };
12876     this.showInvisibles = false;
12877     this.setShowInvisibles = function(showInvisibles) {
12878         if (this.showInvisibles == showInvisibles)
12879             return false;
12881         this.showInvisibles = showInvisibles;
12882         this.$computeTabString();
12883         return true;
12884     };
12886     this.displayIndentGuides = true;
12887     this.setDisplayIndentGuides = function(display) {
12888         if (this.displayIndentGuides == display)
12889             return false;
12891         this.displayIndentGuides = display;
12892         this.$computeTabString();
12893         return true;
12894     };
12896     this.$tabStrings = [];
12897     this.onChangeTabSize =
12898     this.$computeTabString = function() {
12899         var tabSize = this.session.getTabSize();
12900         this.tabSize = tabSize;
12901         var tabStr = this.$tabStrings = [0];
12902         for (var i = 1; i < tabSize + 1; i++) {
12903             if (this.showInvisibles) {
12904                 tabStr.push("<span class='ace_invisible'>"
12905                     + this.TAB_CHAR
12906                     + Array(i).join("&#160;")
12907                     + "</span>");
12908             } else {
12909                 tabStr.push(new Array(i+1).join("&#160;"));
12910             }
12911         }
12912         if (this.displayIndentGuides) {
12913             this.$indentGuideRe =  /\s\S| \t|\t |\s$/;
12914             var className = "ace_indent-guide";
12915             var content = Array(this.tabSize + 1).join("&#160;");
12916             var tabContent = content;
12917             if (this.showInvisibles) {
12918                 className += " ace_invisible";
12919                 tabContent = this.TAB_CHAR + content.substr(6);
12920             }
12922             this.$tabStrings[" "] = "<span class='" + className + "'>" + content + "</span>";
12923             this.$tabStrings["\t"] = "<span class='" + className + "'>" + tabContent + "</span>";
12924         }
12925     };
12927     this.updateLines = function(config, firstRow, lastRow) {
12928         // Due to wrap line changes there can be new lines if e.g.
12929         // the line to updated wrapped in the meantime.
12930         if (this.config.lastRow != config.lastRow ||
12931             this.config.firstRow != config.firstRow) {
12932             this.scrollLines(config);
12933         }
12934         this.config = config;
12936         var first = Math.max(firstRow, config.firstRow);
12937         var last = Math.min(lastRow, config.lastRow);
12939         var lineElements = this.element.childNodes;
12940         var lineElementsIdx = 0;
12942         for (var row = config.firstRow; row < first; row++) {
12943             var foldLine = this.session.getFoldLine(row);
12944             if (foldLine) {
12945                 if (foldLine.containsRow(first)) {
12946                     first = foldLine.start.row;
12947                     break;
12948                 } else {
12949                     row = foldLine.end.row;
12950                 }
12951             }
12952             lineElementsIdx ++;
12953         }
12955         var row = first;
12956         var foldLine = this.session.getNextFoldLine(row);
12957         var foldStart = foldLine ? foldLine.start.row : Infinity;
12959         while (true) {
12960             if (row > foldStart) {
12961                 row = foldLine.end.row+1;
12962                 foldLine = this.session.getNextFoldLine(row, foldLine);
12963                 foldStart = foldLine ? foldLine.start.row :Infinity;
12964             }
12965             if (row > last)
12966                 break;
12968             var lineElement = lineElements[lineElementsIdx++];
12969             if (lineElement) {
12970                 var html = [];
12971                 this.$renderLine(
12972                     html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
12973                 );
12974                 dom.setInnerHtml(lineElement, html.join(""));
12975             }
12976             row++;
12977         }
12978     };
12980     this.scrollLines = function(config) {
12981         var oldConfig = this.config;
12982         this.config = config;
12984         if (!oldConfig || oldConfig.lastRow < config.firstRow)
12985             return this.update(config);
12987         if (config.lastRow < oldConfig.firstRow)
12988             return this.update(config);
12990         var el = this.element;
12991         if (oldConfig.firstRow < config.firstRow)
12992             for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
12993                 el.removeChild(el.firstChild);
12995         if (oldConfig.lastRow > config.lastRow)
12996             for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
12997                 el.removeChild(el.lastChild);
12999         if (config.firstRow < oldConfig.firstRow) {
13000             var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
13001             if (el.firstChild)
13002                 el.insertBefore(fragment, el.firstChild);
13003             else
13004                 el.appendChild(fragment);
13005         }
13007         if (config.lastRow > oldConfig.lastRow) {
13008             var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
13009             el.appendChild(fragment);
13010         }
13011     };
13013     this.$renderLinesFragment = function(config, firstRow, lastRow) {
13014         var fragment = this.element.ownerDocument.createDocumentFragment();
13015         var row = firstRow;
13016         var foldLine = this.session.getNextFoldLine(row);
13017         var foldStart = foldLine ? foldLine.start.row : Infinity;
13019         while (true) {
13020             if (row > foldStart) {
13021                 row = foldLine.end.row+1;
13022                 foldLine = this.session.getNextFoldLine(row, foldLine);
13023                 foldStart = foldLine ? foldLine.start.row : Infinity;
13024             }
13025             if (row > lastRow)
13026                 break;
13028             var container = dom.createElement("div");
13030             var html = [];
13031             // Get the tokens per line as there might be some lines in between
13032             // beeing folded.
13033             this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
13035             // don't use setInnerHtml since we are working with an empty DIV
13036             container.innerHTML = html.join("");
13037             if (this.$useLineGroups()) {
13038                 container.className = 'ace_line_group';
13039                 fragment.appendChild(container);
13040             } else {
13041                 var lines = container.childNodes
13042                 while(lines.length)
13043                     fragment.appendChild(lines[0]);
13044             }
13046             row++;
13047         }
13048         return fragment;
13049     };
13051     this.update = function(config) {
13052         this.config = config;
13054         var html = [];
13055         var firstRow = config.firstRow, lastRow = config.lastRow;
13057         var row = firstRow;
13058         var foldLine = this.session.getNextFoldLine(row);
13059         var foldStart = foldLine ? foldLine.start.row : Infinity;
13061         while (true) {
13062             if (row > foldStart) {
13063                 row = foldLine.end.row+1;
13064                 foldLine = this.session.getNextFoldLine(row, foldLine);
13065                 foldStart = foldLine ? foldLine.start.row :Infinity;
13066             }
13067             if (row > lastRow)
13068                 break;
13070             if (this.$useLineGroups())
13071                 html.push("<div class='ace_line_group'>")
13073             this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
13075             if (this.$useLineGroups())
13076                 html.push("</div>"); // end the line group
13078             row++;
13079         }
13080         this.element = dom.setInnerHtml(this.element, html.join(""));
13081     };
13083     this.$textToken = {
13084         "text": true,
13085         "rparen": true,
13086         "lparen": true
13087     };
13089     this.$renderToken = function(stringBuilder, screenColumn, token, value) {
13090         var self = this;
13091         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;
13092         var replaceFunc = function(c, a, b, tabIdx, idx4) {
13093             if (a) {
13094                 return new Array(c.length+1).join("&#160;");
13095             } else if (c == "&") {
13096                 return "&#38;";
13097             } else if (c == "<") {
13098                 return "&#60;";
13099             } else if (c == "\t") {
13100                 var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
13101                 screenColumn += tabSize - 1;
13102                 return self.$tabStrings[tabSize];
13103             } else if (c == "\u3000") {
13104                 // U+3000 is both invisible AND full-width, so must be handled uniquely
13105                 var classToUse = self.showInvisibles ? "ace_cjk ace_invisible" : "ace_cjk";
13106                 var space = self.showInvisibles ? self.SPACE_CHAR : "";
13107                 screenColumn += 1;
13108                 return "<span class='" + classToUse + "' style='width:" +
13109                     (self.config.characterWidth * 2) +
13110                     "px'>" + space + "</span>";
13111             } else if (b) {
13112                 return "<span class='ace_invisible ace_invalid'>" + self.SPACE_CHAR + "</span>";
13113             } else {
13114                 screenColumn += 1;
13115                 return "<span class='ace_cjk' style='width:" +
13116                     (self.config.characterWidth * 2) +
13117                     "px'>" + c + "</span>";
13118             }
13119         };
13121         var output = value.replace(replaceReg, replaceFunc);
13123         if (!this.$textToken[token.type]) {
13124             var classes = "ace_" + token.type.replace(/\./g, " ace_");
13125             var style = "";
13126             if (token.type == "fold")
13127                 style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
13128             stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
13129         }
13130         else {
13131             stringBuilder.push(output);
13132         }
13133         return screenColumn + value.length;
13134     };
13136     this.renderIndentGuide = function(stringBuilder, value) {
13137         var cols = value.search(this.$indentGuideRe);
13138         if (cols <= 0)
13139             return value;
13140         if (value[0] == " ") {
13141             cols -= cols % this.tabSize;
13142             stringBuilder.push(Array(cols/this.tabSize + 1).join(this.$tabStrings[" "]));
13143             return value.substr(cols);
13144         } else if (value[0] == "\t") {
13145             stringBuilder.push(Array(cols + 1).join(this.$tabStrings["\t"]));
13146             return value.substr(cols);
13147         }
13148         return value;
13149     };
13151     this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
13152         var chars = 0;
13153         var split = 0;
13154         var splitChars = splits[0];
13155         var screenColumn = 0;
13157         for (var i = 0; i < tokens.length; i++) {
13158             var token = tokens[i];
13159             var value = token.value;
13160             if (i == 0 && this.displayIndentGuides) {
13161                 chars = value.length;
13162                 value = this.renderIndentGuide(stringBuilder, value);
13163                 if (!value)
13164                     continue;
13165                 chars -= value.length;
13166             }
13168             if (chars + value.length < splitChars) {
13169                 screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
13170                 chars += value.length;
13171             } else {
13172                 while (chars + value.length >= splitChars) {
13173                     screenColumn = this.$renderToken(
13174                         stringBuilder, screenColumn,
13175                         token, value.substring(0, splitChars - chars)
13176                     );
13177                     value = value.substring(splitChars - chars);
13178                     chars = splitChars;
13180                     if (!onlyContents) {
13181                         stringBuilder.push("</div>",
13182                             "<div class='ace_line' style='height:",
13183                             this.config.lineHeight, "px'>"
13184                         );
13185                     }
13187                     split ++;
13188                     screenColumn = 0;
13189                     splitChars = splits[split] || Number.MAX_VALUE;
13190                 }
13191                 if (value.length != 0) {
13192                     chars += value.length;
13193                     screenColumn = this.$renderToken(
13194                         stringBuilder, screenColumn, token, value
13195                     );
13196                 }
13197             }
13198         }
13199     };
13201     this.$renderSimpleLine = function(stringBuilder, tokens) {
13202         var screenColumn = 0;
13203         var token = tokens[0];
13204         var value = token.value;
13205         if (this.displayIndentGuides)
13206             value = this.renderIndentGuide(stringBuilder, value);
13207         if (value)
13208             screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
13209         for (var i = 1; i < tokens.length; i++) {
13210             token = tokens[i];
13211             value = token.value;
13212             screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
13213         }
13214     };
13216     // row is either first row of foldline or not in fold
13217     this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
13218         if (!foldLine && foldLine != false)
13219             foldLine = this.session.getFoldLine(row);
13221         if (foldLine)
13222             var tokens = this.$getFoldLineTokens(row, foldLine);
13223         else
13224             var tokens = this.session.getTokens(row);
13227         if (!onlyContents) {
13228             stringBuilder.push(
13229                 "<div class='ace_line' style='height:", this.config.lineHeight, "px'>"
13230             );
13231         }
13233         if (tokens.length) {
13234             var splits = this.session.getRowSplitData(row);
13235             if (splits && splits.length)
13236                 this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
13237             else
13238                 this.$renderSimpleLine(stringBuilder, tokens);
13239         }
13241         if (this.showInvisibles) {
13242             if (foldLine)
13243                 row = foldLine.end.row
13245             stringBuilder.push(
13246                 "<span class='ace_invisible'>",
13247                 row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
13248                 "</span>"
13249             );
13250         }
13251         if (!onlyContents)
13252             stringBuilder.push("</div>");
13253     };
13255     this.$getFoldLineTokens = function(row, foldLine) {
13256         var session = this.session;
13257         var renderTokens = [];
13259         function addTokens(tokens, from, to) {
13260             var idx = 0, col = 0;
13261             while ((col + tokens[idx].value.length) < from) {
13262                 col += tokens[idx].value.length;
13263                 idx++;
13265                 if (idx == tokens.length)
13266                     return;
13267             }
13268             if (col != from) {
13269                 var value = tokens[idx].value.substring(from - col);
13270                 // Check if the token value is longer then the from...to spacing.
13271                 if (value.length > (to - from))
13272                     value = value.substring(0, to - from);
13274                 renderTokens.push({
13275                     type: tokens[idx].type,
13276                     value: value
13277                 });
13279                 col = from + value.length;
13280                 idx += 1;
13281             }
13283             while (col < to && idx < tokens.length) {
13284                 var value = tokens[idx].value;
13285                 if (value.length + col > to) {
13286                     renderTokens.push({
13287                         type: tokens[idx].type,
13288                         value: value.substring(0, to - col)
13289                     });
13290                 } else
13291                     renderTokens.push(tokens[idx]);
13292                 col += value.length;
13293                 idx += 1;
13294             }
13295         }
13297         var tokens = session.getTokens(row);
13298         foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
13299             if (placeholder) {
13300                 renderTokens.push({
13301                     type: "fold",
13302                     value: placeholder
13303                 });
13304             } else {
13305                 if (isNewRow)
13306                     tokens = session.getTokens(row);
13308                 if (tokens.length)
13309                     addTokens(tokens, lastColumn, column);
13310             }
13311         }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
13313         return renderTokens;
13314     };
13316     this.$useLineGroups = function() {
13317         // For the updateLines function to work correctly, it's important that the
13318         // child nodes of this.element correspond on a 1-to-1 basis to rows in the
13319         // document (as distinct from lines on the screen). For sessions that are
13320         // wrapped, this means we need to add a layer to the node hierarchy (tagged
13321         // with the class name ace_line_group).
13322         return this.session.getUseWrapMode();
13323     };
13325     this.destroy = function() {
13326         clearInterval(this.$pollSizeChangesTimer);
13327         if (this.$measureNode)
13328             this.$measureNode.parentNode.removeChild(this.$measureNode);
13329         delete this.$measureNode;
13330     };
13332 }).call(Text.prototype);
13334 exports.Text = Text;
13338 define('ace/layer/cursor', ['require', 'exports', 'module' , 'ace/lib/dom'], function(require, exports, module) {
13341 var dom = require("../lib/dom");
13343 var Cursor = function(parentEl) {
13344     this.element = dom.createElement("div");
13345     this.element.className = "ace_layer ace_cursor-layer";
13346     parentEl.appendChild(this.element);
13348     this.isVisible = false;
13349     this.isBlinking = true;
13351     this.cursors = [];
13352     this.cursor = this.addCursor();
13355 (function() {
13357     this.$padding = 0;
13358     this.setPadding = function(padding) {
13359         this.$padding = padding;
13360     };
13362     this.setSession = function(session) {
13363         this.session = session;
13364     };
13366     this.setBlinking = function(blinking) {
13367         this.isBlinking = blinking;
13368         if (blinking)
13369             this.restartTimer();
13370     };
13372     this.addCursor = function() {
13373         var el = dom.createElement("div");
13374         var className = "ace_cursor";
13375         if (!this.isVisible)
13376             className += " ace_hidden";
13377         if (this.overwrite)
13378             className += " ace_overwrite";
13380         el.className = className;
13381         this.element.appendChild(el);
13382         this.cursors.push(el);
13383         return el;
13384     };
13386     this.removeCursor = function() {
13387         if (this.cursors.length > 1) {
13388             var el = this.cursors.pop();
13389             el.parentNode.removeChild(el);
13390             return el;
13391         }
13392     };
13394     this.hideCursor = function() {
13395         this.isVisible = false;
13396         for (var i = this.cursors.length; i--; )
13397             dom.addCssClass(this.cursors[i], "ace_hidden");
13398         clearInterval(this.blinkId);
13399     };
13401     this.showCursor = function() {
13402         this.isVisible = true;
13403         for (var i = this.cursors.length; i--; )
13404             dom.removeCssClass(this.cursors[i], "ace_hidden");
13406         this.element.style.visibility = "";
13407         this.restartTimer();
13408     };
13410     this.restartTimer = function() {
13411         clearInterval(this.blinkId);
13412         if (!this.isBlinking)
13413             return;
13414         if (!this.isVisible)
13415             return;
13417         var element = this.cursors.length == 1 ? this.cursor : this.element;
13418         this.blinkId = setInterval(function() {
13419             element.style.visibility = "hidden";
13420             setTimeout(function() {
13421                 element.style.visibility = "";
13422             }, 400);
13423         }, 1000);
13424     };
13426     this.getPixelPosition = function(position, onScreen) {
13427         if (!this.config || !this.session) {
13428             return {
13429                 left : 0,
13430                 top : 0
13431             };
13432         }
13434         if (!position)
13435             position = this.session.selection.getCursor();
13436         var pos = this.session.documentToScreenPosition(position);
13437         var cursorLeft = Math.round(this.$padding +
13438                                     pos.column * this.config.characterWidth);
13439         var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
13440             this.config.lineHeight;
13442         return {
13443             left : cursorLeft,
13444             top : cursorTop
13445         };
13446     };
13448     this.update = function(config) {
13449         this.config = config;
13451         if (this.session.selectionMarkerCount > 0) {
13452             var selections = this.session.$selectionMarkers;
13453             var i = 0, sel, cursorIndex = 0;
13455             for (var i = selections.length; i--; ) {
13456                 sel = selections[i];
13457                 var pixelPos = this.getPixelPosition(sel.cursor, true);
13458                 if ((pixelPos.top > config.height + config.offset || 
13459                      pixelPos.top < -config.offset) && i > 1) {
13460                     continue;
13461                 }
13463                 var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
13465                 style.left = pixelPos.left + "px";
13466                 style.top = pixelPos.top + "px";
13467                 style.width = config.characterWidth + "px";
13468                 style.height = config.lineHeight + "px";
13469             }
13470             if (cursorIndex > 1)
13471                 while (this.cursors.length > cursorIndex)
13472                     this.removeCursor();
13473         } else {
13474             var pixelPos = this.getPixelPosition(null, true);
13475             var style = this.cursor.style;
13476             style.left = pixelPos.left + "px";
13477             style.top = pixelPos.top + "px";
13478             style.width = config.characterWidth + "px";
13479             style.height = config.lineHeight + "px";
13481             while (this.cursors.length > 1)
13482                 this.removeCursor();
13483         }
13485         var overwrite = this.session.getOverwrite();
13486         if (overwrite != this.overwrite)
13487             this.$setOverite(overwrite);
13489         // cache for textarea and gutter highlight
13490         this.$pixelPos = pixelPos;
13492         this.restartTimer();
13493     };
13495     this.$setOverite = function(overwrite) {
13496         this.overwrite = overwrite;
13497         for (var i = this.cursors.length; i--; ) {
13498             if (overwrite)
13499                 dom.addCssClass(this.cursors[i], "ace_overwrite");
13500             else
13501                 dom.removeCssClass(this.cursors[i], "ace_overwrite");
13502         }
13503     };
13505     this.destroy = function() {
13506         clearInterval(this.blinkId);
13507     }
13509 }).call(Cursor.prototype);
13511 exports.Cursor = Cursor;
13515 define('ace/scrollbar', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/event', 'ace/lib/event_emitter'], function(require, exports, module) {
13518 var oop = require("./lib/oop");
13519 var dom = require("./lib/dom");
13520 var event = require("./lib/event");
13521 var EventEmitter = require("./lib/event_emitter").EventEmitter;
13524  * new ScrollBar(parent)
13525  * - parent (DOMElement): A DOM element 
13527  * Creates a new `ScrollBar`. `parent` is the owner of the scroll bar.
13529  **/
13530 var ScrollBar = function(parent) {
13531     this.element = dom.createElement("div");
13532     this.element.className = "ace_sb";
13534     this.inner = dom.createElement("div");
13535     this.element.appendChild(this.inner);
13537     parent.appendChild(this.element);
13539     // in OSX lion the scrollbars appear to have no width. In this case resize
13540     // the to show the scrollbar but still pretend that the scrollbar has a width
13541     // of 0px
13542     // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar
13543     // make element a little bit wider to retain scrollbar when page is zoomed 
13544     this.width = dom.scrollbarWidth(parent.ownerDocument);
13545     this.element.style.width = (this.width || 15) + 5 + "px";
13547     event.addListener(this.element, "scroll", this.onScroll.bind(this));
13550 (function() {
13551     oop.implement(this, EventEmitter);
13552     this.onScroll = function() {
13553         this._emit("scroll", {data: this.element.scrollTop});
13554     };
13555     this.getWidth = function() {
13556         return this.width;
13557     };
13558     this.setHeight = function(height) {
13559         this.element.style.height = height + "px";
13560     };
13561     this.setInnerHeight = function(height) {
13562         this.inner.style.height = height + "px";
13563     };
13564     // TODO: on chrome 17+ for small zoom levels after calling this function
13565     // this.element.scrollTop != scrollTop which makes page to scroll up.
13566     this.setScrollTop = function(scrollTop) {
13567         this.element.scrollTop = scrollTop;
13568     };
13570 }).call(ScrollBar.prototype);
13572 exports.ScrollBar = ScrollBar;
13575 define('ace/renderloop', ['require', 'exports', 'module' , 'ace/lib/event'], function(require, exports, module) {
13578 var event = require("./lib/event");
13580 /** internal, hide
13581  * new RenderLoop(onRender, win)
13583  * 
13586 var RenderLoop = function(onRender, win) {
13587     this.onRender = onRender;
13588     this.pending = false;
13589     this.changes = 0;
13590     this.window = win || window;
13593 (function() {
13595     /** internal, hide
13596      * RenderLoop.schedule(change)
13597      * - change (Array):
13598      * 
13599      * 
13600      **/
13601     this.schedule = function(change) {
13602         //this.onRender(change);
13603         //return;
13604         this.changes = this.changes | change;
13605         if (!this.pending) {
13606             this.pending = true;
13607             var _self = this;
13608             event.nextTick(function() {
13609                 _self.pending = false;
13610                 var changes;
13611                 while (changes = _self.changes) {
13612                     _self.changes = 0;
13613                     _self.onRender(changes);
13614                 }
13615             }, this.window);
13616         }
13617     };
13619 }).call(RenderLoop.prototype);
13621 exports.RenderLoop = RenderLoop;
13623 define("text!ace/css/editor.css", [], ".ace_editor {\n" +
13624   "    position: absolute;\n" +
13625   "    overflow: hidden;\n" +
13626   "    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Droid Sans Mono', 'Consolas', monospace;\n" +
13627   "    font-size: 12px;\n" +
13628   "}\n" +
13629   "\n" +
13630   ".ace_scroller {\n" +
13631   "    position: absolute;\n" +
13632   "    overflow: hidden;\n" +
13633   "}\n" +
13634   "\n" +
13635   ".ace_content {\n" +
13636   "    position: absolute;\n" +
13637   "    box-sizing: border-box;\n" +
13638   "    -moz-box-sizing: border-box;\n" +
13639   "    -webkit-box-sizing: border-box;\n" +
13640   "    cursor: text;\n" +
13641   "}\n" +
13642   "\n" +
13643   ".ace_gutter {\n" +
13644   "    position: absolute;\n" +
13645   "    overflow : hidden;\n" +
13646   "    height: 100%;\n" +
13647   "    width: auto;\n" +
13648   "    cursor: default;\n" +
13649   "    z-index: 4;\n" +
13650   "}\n" +
13651   "\n" +
13652   ".ace_gutter_active_line {\n" +
13653   "    position: absolute;\n" +
13654   "    left: 0;\n" +
13655   "    right: 0;\n" +
13656   "}\n" +
13657   "\n" +
13658   ".ace_scroller.horscroll {\n" +
13659   "    box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\n" +
13660   "}\n" +
13661   "\n" +
13662   ".ace_gutter-cell {\n" +
13663   "    padding-left: 19px;\n" +
13664   "    padding-right: 6px;\n" +
13665   "    background-repeat: no-repeat;\n" +
13666   "}\n" +
13667   "\n" +
13668   ".ace_gutter-cell.ace_error {\n" +
13669   "    background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6QUM2OEZDQTQ4RTU0MTFFMUEzM0VFRTM2RUY1M0RBMjYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6QUM2OEZDQTU4RTU0MTFFMUEzM0VFRTM2RUY1M0RBMjYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpBQzY4RkNBMjhFNTQxMUUxQTMzRUVFMzZFRjUzREEyNiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpBQzY4RkNBMzhFNTQxMUUxQTMzRUVFMzZFRjUzREEyNiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkgXxbAAAAJbSURBVHjapFNNaBNBFH4zs5vdZLP5sQmNpT82QY209heh1ioWisaDRcSKF0WKJ0GQnrzrxasHsR6EnlrwD0TagxJabaVEpFYxLWlLSS822tr87m66ccfd2GKyVhA6MMybgfe97/vmPUQphd0sZjto9XIn9OOsvlu2nkqRzVU+6vvlzPf8W6bk8dxQ0NPbxAALgCgg2JkaQuhzQau/El0zbmUA7U0Es8v2CiYmKQJHGO1QICCLoqilMhkmurDAyapKgqItezi/USRdJqEYY4D5jCy03ht2yMkkvL91jTTX10qzyyu2hruPRN7jgbH+EOsXcMLgYiThEgAMhABW85oqy1DXdRIdvP1AHJ2acQXvDIrVHcdQNrEKNYSVMSZGMjEzIIAwDXIo+6G/FxcGnzkC3T2oMhLjre49sBB+RRcHLqdafK6sYdE/GGBwU1VpFNj0aN8pJbe+BkZyevUrvLl6Xmm0W9IuTc0DxrDNAJd5oEvI/KRsNC3bQyNjPO9yQ1YHcfj2QvfQc/5TUhJTBc2iM0U7AWDQtc1nJHvD/cfO2s7jaGkiTEfa/Ep8coLu7zmNmh8+dc5lZDuUeFAGUNA/OY6JVaypQ0vjr7XYjUvJM37vt+j1vuTK5DgVfVUoTjVe+y3/LxMxY2GgU+CSLy4cpfsYorRXuXIOi0Vt40h67uZFTdIo6nLaZcwUJWAzwNS0tBnqqKzQDnjdG/iPyZxo46HaKUpbvYkj8qYRTZsBhge+JHhZyh0x9b95JqjVJkT084kZIPwu/mPWqPgfQ5jXh2+92Ay7HedfAgwA6KDWafb4w3cAAAAASUVORK5CYII=\");\n" +
13670   "    background-repeat: no-repeat;\n" +
13671   "    background-position: 2px center;\n" +
13672   "}\n" +
13673   "\n" +
13674   ".ace_gutter-cell.ace_warning {\n" +
13675   "    background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6QUM2OEZDQTg4RTU0MTFFMUEzM0VFRTM2RUY1M0RBMjYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6QUM2OEZDQTk4RTU0MTFFMUEzM0VFRTM2RUY1M0RBMjYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpBQzY4RkNBNjhFNTQxMUUxQTMzRUVFMzZFRjUzREEyNiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpBQzY4RkNBNzhFNTQxMUUxQTMzRUVFMzZFRjUzREEyNiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pgd7PfIAAAGmSURBVHjaYvr//z8DJZiJgUIANoCRkREb9gLiSVAaQx4OQM7AAkwd7XU2/v++/rOttdYGEB9dASEvOMydGKfH8Gv/p4XTkvRBfLxeQAP+1cUhXopyvzhP7P/IoSj7g7Mw09cNKO6J1QQ0L4gICPIv/veg/8W+JdFvQNLHVsW9/nmn9zk7B+cCkDwhL7gt6knSZnx9/LuCEOcvkIAMP+cvto9nfqyZmmUAksfnBUtbM60gX/3/kgyv3/xSFOL5DZT+L8vP+Yfh5cvfPvp/xUHyQHXGyAYwgpwBjZYFT3Y1OEl/OfCH4ffv3wzc4iwMvNIsDJ+f/mH4+vIPAxsb631WW0Yln6ZpQLXdMK/DXGDflh+sIv37EivD5x//Gb7+YWT4y86sl7BCCkSD+Z++/1dkvsFRl+HnD1Rvje4F8whjMXmGj58YGf5zsDMwcnAwfPvKcml62DsQDeaDxN+/Y0qwlpEHqrdB94IRNIDUgfgfKJChGK4OikEW3gTiXUB950ASLFAF54AC94A0G9QAfOnmF9DCDzABFqS08IHYDIScdijOjQABBgC+/9awBH96jwAAAABJRU5ErkJggg==\");\n" +
13676   "    background-position: 2px center;\n" +
13677   "}\n" +
13678   "\n" +
13679   ".ace_gutter-cell.ace_info {\n" +
13680   "    background-image: url(\"data:image/gif;base64,R0lGODlhEAAQAMQAAAAAAEFBQVJSUl5eXmRkZGtra39/f4WFhYmJiZGRkaampry8vMPDw8zMzNXV1dzc3OTk5Orq6vDw8P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABQALAAAAAAQABAAAAUuICWOZGmeaBml5XGwFCQSBGyXRSAwtqQIiRuiwIM5BoYVbEFIyGCQoeJGrVptIQA7\");\n" +
13681   "    background-position: 2px center;\n" +
13682   "}\n" +
13683   ".ace_dark .ace_gutter-cell.ace_info {\n" +
13684   "    background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpGRTk5MTVGREIxNDkxMUUxOTc5Q0FFREQyMTNGMjBFQyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpGRTk5MTVGRUIxNDkxMUUxOTc5Q0FFREQyMTNGMjBFQyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZFOTkxNUZCQjE0OTExRTE5NzlDQUVERDIxM0YyMEVDIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkZFOTkxNUZDQjE0OTExRTE5NzlDQUVERDIxM0YyMEVDIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+SIDkjAAAAJ1JREFUeNpi/P//PwMlgImBQkB7A6qrq/+DMC55FkIGKCoq4pVnpFkgTp069f/+/fv/r1u37r+tre1/kg0A+ptn9uzZYLaRkRHpLvjw4cNXWVlZhufPnzOcO3eOdAO0tbVPAjHDmzdvGA4fPsxIsgGSkpJmv379Ynj37h2DjIyMCMkG3LhxQ/T27dsMampqDHZ2dq/pH41DxwCAAAMAFdc68dUsFZgAAAAASUVORK5CYII=\");\n" +
13685   "}\n" +
13686   "\n" +
13687   ".ace_editor .ace_sb {\n" +
13688   "    position: absolute;\n" +
13689   "    overflow-x: hidden;\n" +
13690   "    overflow-y: scroll;\n" +
13691   "    right: 0;\n" +
13692   "}\n" +
13693   "\n" +
13694   ".ace_editor .ace_sb div {\n" +
13695   "    position: absolute;\n" +
13696   "    width: 1px;\n" +
13697   "    left: 0;\n" +
13698   "}\n" +
13699   "\n" +
13700   ".ace_editor .ace_print_margin_layer {\n" +
13701   "    z-index: 0;\n" +
13702   "    position: absolute;\n" +
13703   "    overflow: hidden;\n" +
13704   "    margin: 0;\n" +
13705   "    left: 0;\n" +
13706   "    height: 100%;\n" +
13707   "    width: 100%;\n" +
13708   "}\n" +
13709   "\n" +
13710   ".ace_editor .ace_print_margin {\n" +
13711   "    position: absolute;\n" +
13712   "    height: 100%;\n" +
13713   "}\n" +
13714   "\n" +
13715   ".ace_editor > textarea {\n" +
13716   "    position: absolute;\n" +
13717   "    z-index: 0;\n" +
13718   "    width: 0.5em;\n" +
13719   "    height: 1em;\n" +
13720   "    opacity: 0;\n" +
13721   "    background: transparent;\n" +
13722   "    appearance: none;\n" +
13723   "    -moz-appearance: none;\n" +
13724   "    border: none;\n" +
13725   "    resize: none;\n" +
13726   "    outline: none;\n" +
13727   "    overflow: hidden;\n" +
13728   "}\n" +
13729   "\n" +
13730   ".ace_editor > textarea.ace_composition {\n" +
13731   "    background: #fff;\n" +
13732   "    color: #000;\n" +
13733   "    z-index: 1000;\n" +
13734   "    opacity: 1;\n" +
13735   "    border: solid lightgray 1px;\n" +
13736   "    margin: -1px\n" +
13737   "}\n" +
13738   "\n" +
13739   ".ace_layer {\n" +
13740   "    z-index: 1;\n" +
13741   "    position: absolute;\n" +
13742   "    overflow: hidden;\n" +
13743   "    white-space: nowrap;\n" +
13744   "    height: 100%;\n" +
13745   "    width: 100%;\n" +
13746   "    box-sizing: border-box;\n" +
13747   "    -moz-box-sizing: border-box;\n" +
13748   "    -webkit-box-sizing: border-box;\n" +
13749   "    /* setting pointer-events: auto; on node under the mouse, which changes\n" +
13750   "        during scroll, will break mouse wheel scrolling in Safari */\n" +
13751   "    pointer-events: none;\n" +
13752   "}\n" +
13753   "\n" +
13754   ".ace_gutter .ace_layer {\n" +
13755   "    position: relative;\n" +
13756   "    width: auto;\n" +
13757   "    text-align: right;\n" +
13758   "    pointer-events: auto;\n" +
13759   "}\n" +
13760   "\n" +
13761   ".ace_text-layer {\n" +
13762   "    color: black;\n" +
13763   "    font: inherit !important;\n" +
13764   "}\n" +
13765   "\n" +
13766   ".ace_cjk {\n" +
13767   "    display: inline-block;\n" +
13768   "    text-align: center;\n" +
13769   "}\n" +
13770   "\n" +
13771   ".ace_cursor-layer {\n" +
13772   "    z-index: 4;\n" +
13773   "}\n" +
13774   "\n" +
13775   ".ace_cursor {\n" +
13776   "    z-index: 4;\n" +
13777   "    position: absolute;\n" +
13778   "}\n" +
13779   "\n" +
13780   ".ace_cursor.ace_hidden {\n" +
13781   "    opacity: 0.2;\n" +
13782   "}\n" +
13783   "\n" +
13784   ".ace_editor.multiselect .ace_cursor {\n" +
13785   "    border-left-width: 1px;\n" +
13786   "}\n" +
13787   "\n" +
13788   ".ace_line {\n" +
13789   "    white-space: nowrap;\n" +
13790   "}\n" +
13791   "\n" +
13792   ".ace_marker-layer .ace_step {\n" +
13793   "    position: absolute;\n" +
13794   "    z-index: 3;\n" +
13795   "}\n" +
13796   "\n" +
13797   ".ace_marker-layer .ace_selection {\n" +
13798   "    position: absolute;\n" +
13799   "    z-index: 5;\n" +
13800   "}\n" +
13801   "\n" +
13802   ".ace_marker-layer .ace_bracket {\n" +
13803   "    position: absolute;\n" +
13804   "    z-index: 6;\n" +
13805   "}\n" +
13806   "\n" +
13807   ".ace_marker-layer .ace_active_line {\n" +
13808   "    position: absolute;\n" +
13809   "    z-index: 2;\n" +
13810   "}\n" +
13811   "\n" +
13812   ".ace_marker-layer .ace_selected_word {\n" +
13813   "    position: absolute;\n" +
13814   "    z-index: 4;\n" +
13815   "    box-sizing: border-box;\n" +
13816   "    -moz-box-sizing: border-box;\n" +
13817   "    -webkit-box-sizing: border-box;\n" +
13818   "}\n" +
13819   "\n" +
13820   ".ace_line .ace_fold {\n" +
13821   "    box-sizing: border-box;\n" +
13822   "    -moz-box-sizing: border-box;\n" +
13823   "    -webkit-box-sizing: border-box;\n" +
13824   "\n" +
13825   "    display: inline-block;\n" +
13826   "    height: 11px;\n" +
13827   "    margin-top: -2px;\n" +
13828   "    vertical-align: middle;\n" +
13829   "\n" +
13830   "    background-image:\n" +
13831   "        url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%11%00%00%00%09%08%06%00%00%00%D4%E8%C7%0C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%DF%AB%FEc%D5%9A%95%0C%11%F0%1C%20%BE%945%C4%22%E1Y%A0i%5C%D4t%13%E0%D6%89%EF%9D15%C2%CDLsX%A7%04%09%1Fg8oc%81%E1%8C%8D%23%96f45%40%9A%09%C2%07%C5B%3AK%B8%408%98i%E0%F3%0D%D8%CE%81%14%E4'%26%A9%92.%8B%3C%ABER%2F%E5dE%B2%0C%F6%F0%1Fs%83%F2_%B0%A8%94%E9%9B%AD%E7%10%8Dm%9A%19N%D1%7C%8A%DE%1F9%7Dp%8C%E6%00%D5%C1%3F_%18%BDA%B8%9DpX6%E3%A35~B%CD%24%AE%11%26%BD%E7%EEti%98%EDe%9A%97Y)%12%25%1C%24%BCbT%AE3li%E6%0B%03%89%9A%E6%D3%ED%F4P%92%B0%9F4%BF43Y%F3%E3%EDP%95%04%EB1%C5%F5%F6KF%F4%BA%BD%D7%DB%91%93%07%E35%3E%A7)%D6%7F%40%FE%BD%F7%F5r%8A%E5y%92%F0%EB%B4%1E%8D%D5%F4%5B%92%3AV%DB%DB%E4%CD%A6%23%C3%C4wQ%3F%03HB%82%8E%1Cd(%E0%91B%0Ca%9Ac%C4%AA%F8L%16%19%22J%A4%D2itTy%B28%D6%3B(%93%96%ED%1CGx%C9_%0E%B8%5E%16%F5%5B%B2%B8%F6%E0%FB%9E%DD%25%D7%8E%BC%15%85%C5%B7%A3%D8Q%ED%B5%81%E9%BA%B2%13%9A%1B%7Fua%A5%A3n%E17%B9%E5%9B%1Bm%AB%0B%08Q%FE%8A%E5%B1H%5Ee%CAO%82Q%D7u6%E6%90S%97%FCu%0B%CF2%94%EE%25v%12X%0C%BA%AC%F0%5E%F8*l%0AO%85%17%C2%97%BF%D4%C8%CE%DE%AD%11%CB%80q%2C%3E%AB%9ES%CD%C6%EC%25%D2L%D2%EBd%B8%BF%8A%F5B%C6%18%F9%901CZ%9D%BE%24M%9C%8A9%F2%DAP%0B'%06w%82%EB%E6%E2%5C%2F%D7%07%9E%BB%CC%5D%E1%FA%B9%08%AD.r%23%8E%C2%17%F5E%7C!%F0%BE3%BE%3E_%B7o%88a%A7%DB%BE%D3d%EB%A31Z%EB%BB%D3%91%BA%A2%B1z%94%8F%DB'%F6%3D%8E%AA%13%19%B2%B1%BE%B1~V%08%2B%B4%A2cjJ%B3tO%00%03%25mN%97%F3%05%93%EF%11%84%0B%7C%88%AE-%89%8F%ABbW%90O%2B%0Ao%99%0C%5E%97%0CI%AFH%D9.%B0%3B%8F%ED%03%B6S%D6%5D%E6i_s9%F3*p%E9%1B%FD%C3%EB.7U%06%5E%19%C0%D1s.%17%A03u%E4%09%B0%7C%5E%2C%EB%15%DB%1F%3C%9E%B7%80%91%3B%DBc%AD%3Dma%BA%8B%3EV%AB%DBt.%5B%1E%01%BB%0F%AB%D5%9F%CF%AA%D5%DD%E7%E4%7F%0Bx%A3%FC%06%A9%23%0A%D6%C2%A1_2%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%B5IDAT(%15%A5%91%3D%0E%02!%10%85ac%E1%05%D6%CE%D6%C6%CE%D2%E8%ED%CD%DE%C0%C6%D6N.%E0V%F8%3D%9Ca%891XH%C2%BE%D9y%3F%90!%E6%9C%C3%BFk%E5%011%C6-%F5%C8N%04%DF%BD%FF%89%DFt%83DN%60%3E%F3%AB%A0%DE%1A%5Dg%BE%10Q%97%1B%40%9C%A8o%10%8F%5E%828%B4%1B%60%87%F6%02%26%85%1Ch%1E%C1%2B%5Bk%FF%86%EE%B7j%09%9A%DA%9B%ACe%A3%F9%EC%DA!9%B4%D5%A6%81%86%86%98%CC%3C%5B%40%FA%81%B3%E9%CB%23%94%C16Azo%05%D4%E1%C1%95a%3B%8A'%A0%E8%CC%17%22%85%1D%BA%00%A2%FA%DC%0A%94%D1%D1%8D%8B%3A%84%17B%C7%60%1A%25Z%FC%8D%00%00%00%00IEND%AEB%60%82\"),\n" +
13832   "        url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%007%08%06%00%00%00%C4%DD%80C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%DF%AB%FEc%D5%9A%95%0C%11%F0%1C%20%BE%945%C4%22%E1Y%A0i%5C%D4t%13%E0%D6%89%EF%9D15%C2%CDLsX%A7%04%09%1Fg8oc%81%E1%8C%8D%23%96f45%40%9A%09%C2%07%C5B%3AK%B8%408%98i%E0%F3%0D%D8%CE%81%14%E4'%26%A9%92.%8B%3C%ABER%2F%E5dE%B2%0C%F6%F0%1Fs%83%F2_%B0%A8%94%E9%9B%AD%E7%10%8Dm%9A%19N%D1%7C%8A%DE%1F9%7Dp%8C%E6%00%D5%C1%3F_%18%BDA%B8%9DpX6%E3%A35~B%CD%24%AE%11%26%BD%E7%EEti%98%EDe%9A%97Y)%12%25%1C%24%BCbT%AE3li%E6%0B%03%89%9A%E6%D3%ED%F4P%92%B0%9F4%BF43Y%F3%E3%EDP%95%04%EB1%C5%F5%F6KF%F4%BA%BD%D7%DB%91%93%07%E35%3E%A7)%D6%7F%40%FE%BD%F7%F5r%8A%E5y%92%F0%EB%B4%1E%8D%D5%F4%5B%92%3AV%DB%DB%E4%CD%A6%23%C3%C4wQ%3F%03HB%82%8E%1Cd(%E0%91B%0Ca%9Ac%C4%AA%F8L%16%19%22J%A4%D2itTy%B28%D6%3B(%93%96%ED%1CGx%C9_%0E%B8%5E%16%F5%5B%B2%B8%F6%E0%FB%9E%DD%25%D7%8E%BC%15%85%C5%B7%A3%D8Q%ED%B5%81%E9%BA%B2%13%9A%1B%7Fua%A5%A3n%E17%B9%E5%9B%1Bm%AB%0B%08Q%FE%8A%E5%B1H%5Ee%CAO%82Q%D7u6%E6%90S%97%FCu%0B%CF2%94%EE%25v%12X%0C%BA%AC%F0%5E%F8*l%0AO%85%17%C2%97%BF%D4%C8%CE%DE%AD%11%CB%80q%2C%3E%AB%9ES%CD%C6%EC%25%D2L%D2%EBd%B8%BF%8A%F5B%C6%18%F9%901CZ%9D%BE%24M%9C%8A9%F2%DAP%0B'%06w%82%EB%E6%E2%5C%2F%D7%07%9E%BB%CC%5D%E1%FA%B9%08%AD.r%23%8E%C2%17%F5E%7C!%F0%BE3%BE%3E_%B7o%88a%A7%DB%BE%D3d%EB%A31Z%EB%BB%D3%91%BA%A2%B1z%94%8F%DB'%F6%3D%8E%AA%13%19%B2%B1%BE%B1~V%08%2B%B4%A2cjJ%B3tO%00%03%25mN%97%F3%05%93%EF%11%84%0B%7C%88%AE-%89%8F%ABbW%90O%2B%0Ao%99%0C%5E%97%0CI%AFH%D9.%B0%3B%8F%ED%03%B6S%D6%5D%E6i_s9%F3*p%E9%1B%FD%C3%EB.7U%06%5E%19%C0%D1s.%17%A03u%E4%09%B0%7C%5E%2C%EB%15%DB%1F%3C%9E%B7%80%91%3B%DBc%AD%3Dma%BA%8B%3EV%AB%DBt.%5B%1E%01%BB%0F%AB%D5%9F%CF%AA%D5%DD%E7%E4%7F%0Bx%A3%FC%06%A9%23%0A%D6%C2%A1_2%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%3AIDAT8%11c%FC%FF%FF%7F%18%03%1A%60%01%F2%3F%A0%891%80%04%FF%11-%F8%17%9BJ%E2%05%B1ZD%81v%26t%E7%80%F8%A3%82h%A12%1A%20%A3%01%02%0F%01%BA%25%06%00%19%C0%0D%AEF%D5%3ES%00%00%00%00IEND%AEB%60%82\");\n" +
13833   "    background-repeat: no-repeat, repeat-x;\n" +
13834   "    background-position: center center, top left;\n" +
13835   "    color: transparent;\n" +
13836   "\n" +
13837   "    border: 1px solid black;\n" +
13838   "    -moz-border-radius: 2px;\n" +
13839   "    -webkit-border-radius: 2px;\n" +
13840   "    border-radius: 2px;\n" +
13841   "\n" +
13842   "    cursor: pointer;\n" +
13843   "    pointer-events: auto;\n" +
13844   "}\n" +
13845   "\n" +
13846   ".ace_dark .ace_fold {\n" +
13847   "}\n" +
13848   "\n" +
13849   ".ace_fold:hover{\n" +
13850   "    background-image:\n" +
13851   "        url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%11%00%00%00%09%08%06%00%00%00%D4%E8%C7%0C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%DF%AB%FEc%D5%9A%95%0C%11%F0%1C%20%BE%945%C4%22%E1Y%A0i%5C%D4t%13%E0%D6%89%EF%9D15%C2%CDLsX%A7%04%09%1Fg8oc%81%E1%8C%8D%23%96f45%40%9A%09%C2%07%C5B%3AK%B8%408%98i%E0%F3%0D%D8%CE%81%14%E4'%26%A9%92.%8B%3C%ABER%2F%E5dE%B2%0C%F6%F0%1Fs%83%F2_%B0%A8%94%E9%9B%AD%E7%10%8Dm%9A%19N%D1%7C%8A%DE%1F9%7Dp%8C%E6%00%D5%C1%3F_%18%BDA%B8%9DpX6%E3%A35~B%CD%24%AE%11%26%BD%E7%EEti%98%EDe%9A%97Y)%12%25%1C%24%BCbT%AE3li%E6%0B%03%89%9A%E6%D3%ED%F4P%92%B0%9F4%BF43Y%F3%E3%EDP%95%04%EB1%C5%F5%F6KF%F4%BA%BD%D7%DB%91%93%07%E35%3E%A7)%D6%7F%40%FE%BD%F7%F5r%8A%E5y%92%F0%EB%B4%1E%8D%D5%F4%5B%92%3AV%DB%DB%E4%CD%A6%23%C3%C4wQ%3F%03HB%82%8E%1Cd(%E0%91B%0Ca%9Ac%C4%AA%F8L%16%19%22J%A4%D2itTy%B28%D6%3B(%93%96%ED%1CGx%C9_%0E%B8%5E%16%F5%5B%B2%B8%F6%E0%FB%9E%DD%25%D7%8E%BC%15%85%C5%B7%A3%D8Q%ED%B5%81%E9%BA%B2%13%9A%1B%7Fua%A5%A3n%E17%B9%E5%9B%1Bm%AB%0B%08Q%FE%8A%E5%B1H%5Ee%CAO%82Q%D7u6%E6%90S%97%FCu%0B%CF2%94%EE%25v%12X%0C%BA%AC%F0%5E%F8*l%0AO%85%17%C2%97%BF%D4%C8%CE%DE%AD%11%CB%80q%2C%3E%AB%9ES%CD%C6%EC%25%D2L%D2%EBd%B8%BF%8A%F5B%C6%18%F9%901CZ%9D%BE%24M%9C%8A9%F2%DAP%0B'%06w%82%EB%E6%E2%5C%2F%D7%07%9E%BB%CC%5D%E1%FA%B9%08%AD.r%23%8E%C2%17%F5E%7C!%F0%BE3%BE%3E_%B7o%88a%A7%DB%BE%D3d%EB%A31Z%EB%BB%D3%91%BA%A2%B1z%94%8F%DB'%F6%3D%8E%AA%13%19%B2%B1%BE%B1~V%08%2B%B4%A2cjJ%B3tO%00%03%25mN%97%F3%05%93%EF%11%84%0B%7C%88%AE-%89%8F%ABbW%90O%2B%0Ao%99%0C%5E%97%0CI%AFH%D9.%B0%3B%8F%ED%03%B6S%D6%5D%E6i_s9%F3*p%E9%1B%FD%C3%EB.7U%06%5E%19%C0%D1s.%17%A03u%E4%09%B0%7C%5E%2C%EB%15%DB%1F%3C%9E%B7%80%91%3B%DBc%AD%3Dma%BA%8B%3EV%AB%DBt.%5B%1E%01%BB%0F%AB%D5%9F%CF%AA%D5%DD%E7%E4%7F%0Bx%A3%FC%06%A9%23%0A%D6%C2%A1_2%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%B5IDAT(%15%A5%91%3D%0E%02!%10%85ac%E1%05%D6%CE%D6%C6%CE%D2%E8%ED%CD%DE%C0%C6%D6N.%E0V%F8%3D%9Ca%891XH%C2%BE%D9y%3F%90!%E6%9C%C3%BFk%E5%011%C6-%F5%C8N%04%DF%BD%FF%89%DFt%83DN%60%3E%F3%AB%A0%DE%1A%5Dg%BE%10Q%97%1B%40%9C%A8o%10%8F%5E%828%B4%1B%60%87%F6%02%26%85%1Ch%1E%C1%2B%5Bk%FF%86%EE%B7j%09%9A%DA%9B%ACe%A3%F9%EC%DA!9%B4%D5%A6%81%86%86%98%CC%3C%5B%40%FA%81%B3%E9%CB%23%94%C16Azo%05%D4%E1%C1%95a%3B%8A'%A0%E8%CC%17%22%85%1D%BA%00%A2%FA%DC%0A%94%D1%D1%8D%8B%3A%84%17B%C7%60%1A%25Z%FC%8D%00%00%00%00IEND%AEB%60%82\"),\n" +
13852   "        url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%007%08%06%00%00%00%C4%DD%80C%00%00%03%1EiCCPICC%20Profile%00%00x%01%85T%DFk%D3P%14%FE%DAe%9D%B0%E1%8B%3Ag%11%09%3Eh%91ndStC%9C%B6kW%BA%CDZ%EA6%B7!H%9B%A6m%5C%9A%C6%24%ED~%B0%07%D9%8Bo%3A%C5w%F1%07%3E%F9%07%0C%D9%83o%7B%92%0D%C6%14a%F8%AC%88%22L%F6%22%B3%9E%9B4M'S%03%B9%F7%BB%DF%F9%EE9'%E7%E4%5E%A0%F9qZ%D3%14%2F%0F%14USO%C5%C2%FC%C4%E4%14%DF%F2%01%5E%1CC%2B%FChM%8B%86%16J%26G%40%0F%D3%B2y%EF%B3%F3%0E%1E%C6lt%EEo%DF%AB%FEc%D5%9A%95%0C%11%F0%1C%20%BE%945%C4%22%E1Y%A0i%5C%D4t%13%E0%D6%89%EF%9D15%C2%CDLsX%A7%04%09%1Fg8oc%81%E1%8C%8D%23%96f45%40%9A%09%C2%07%C5B%3AK%B8%408%98i%E0%F3%0D%D8%CE%81%14%E4'%26%A9%92.%8B%3C%ABER%2F%E5dE%B2%0C%F6%F0%1Fs%83%F2_%B0%A8%94%E9%9B%AD%E7%10%8Dm%9A%19N%D1%7C%8A%DE%1F9%7Dp%8C%E6%00%D5%C1%3F_%18%BDA%B8%9DpX6%E3%A35~B%CD%24%AE%11%26%BD%E7%EEti%98%EDe%9A%97Y)%12%25%1C%24%BCbT%AE3li%E6%0B%03%89%9A%E6%D3%ED%F4P%92%B0%9F4%BF43Y%F3%E3%EDP%95%04%EB1%C5%F5%F6KF%F4%BA%BD%D7%DB%91%93%07%E35%3E%A7)%D6%7F%40%FE%BD%F7%F5r%8A%E5y%92%F0%EB%B4%1E%8D%D5%F4%5B%92%3AV%DB%DB%E4%CD%A6%23%C3%C4wQ%3F%03HB%82%8E%1Cd(%E0%91B%0Ca%9Ac%C4%AA%F8L%16%19%22J%A4%D2itTy%B28%D6%3B(%93%96%ED%1CGx%C9_%0E%B8%5E%16%F5%5B%B2%B8%F6%E0%FB%9E%DD%25%D7%8E%BC%15%85%C5%B7%A3%D8Q%ED%B5%81%E9%BA%B2%13%9A%1B%7Fua%A5%A3n%E17%B9%E5%9B%1Bm%AB%0B%08Q%FE%8A%E5%B1H%5Ee%CAO%82Q%D7u6%E6%90S%97%FCu%0B%CF2%94%EE%25v%12X%0C%BA%AC%F0%5E%F8*l%0AO%85%17%C2%97%BF%D4%C8%CE%DE%AD%11%CB%80q%2C%3E%AB%9ES%CD%C6%EC%25%D2L%D2%EBd%B8%BF%8A%F5B%C6%18%F9%901CZ%9D%BE%24M%9C%8A9%F2%DAP%0B'%06w%82%EB%E6%E2%5C%2F%D7%07%9E%BB%CC%5D%E1%FA%B9%08%AD.r%23%8E%C2%17%F5E%7C!%F0%BE3%BE%3E_%B7o%88a%A7%DB%BE%D3d%EB%A31Z%EB%BB%D3%91%BA%A2%B1z%94%8F%DB'%F6%3D%8E%AA%13%19%B2%B1%BE%B1~V%08%2B%B4%A2cjJ%B3tO%00%03%25mN%97%F3%05%93%EF%11%84%0B%7C%88%AE-%89%8F%ABbW%90O%2B%0Ao%99%0C%5E%97%0CI%AFH%D9.%B0%3B%8F%ED%03%B6S%D6%5D%E6i_s9%F3*p%E9%1B%FD%C3%EB.7U%06%5E%19%C0%D1s.%17%A03u%E4%09%B0%7C%5E%2C%EB%15%DB%1F%3C%9E%B7%80%91%3B%DBc%AD%3Dma%BA%8B%3EV%AB%DBt.%5B%1E%01%BB%0F%AB%D5%9F%CF%AA%D5%DD%E7%E4%7F%0Bx%A3%FC%06%A9%23%0A%D6%C2%A1_2%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%003IDAT8%11c%FC%FF%FF%7F%3E%03%1A%60%01%F2%3F%A3%891%80%04%FFQ%26%F8w%C0%B43%A1%DB%0C%E2%8F%0A%A2%85%CAh%80%8C%06%08%3C%04%E8%96%18%00%A3S%0D%CD%CF%D8%C1%9D%00%00%00%00IEND%AEB%60%82\");\n" +
13853   "    background-repeat: no-repeat, repeat-x;\n" +
13854   "    background-position: center center, top left;\n" +
13855   "}\n" +
13856   "\n" +
13857   ".ace_dragging .ace_content {\n" +
13858   "    cursor: move;\n" +
13859   "}\n" +
13860   "\n" +
13861   ".ace_gutter_tooltip {\n" +
13862   "    background-color: #FFFFD5;\n" +
13863   "    border: 1px solid gray;\n" +
13864   "    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);\n" +
13865   "    color: black;\n" +
13866   "    display: inline-block;\n" +
13867   "    padding: 4px;\n" +
13868   "    position: absolute;\n" +
13869   "    z-index: 300;\n" +
13870   "    box-sizing: border-box;\n" +
13871   "    -moz-box-sizing: border-box;\n" +
13872   "    -webkit-box-sizing: border-box;\n" +
13873   "    cursor: default;\n" +
13874   "}\n" +
13875   "\n" +
13876   ".ace_folding-enabled > .ace_gutter-cell {\n" +
13877   "    padding-right: 13px;\n" +
13878   "}\n" +
13879   "\n" +
13880   ".ace_fold-widget {\n" +
13881   "    box-sizing: border-box;\n" +
13882   "    -moz-box-sizing: border-box;\n" +
13883   "    -webkit-box-sizing: border-box;\n" +
13884   "\n" +
13885   "    margin: 0 -12px 0 1px;\n" +
13886   "    display: inline-block;\n" +
13887   "    width: 11px;\n" +
13888   "    vertical-align: top;\n" +
13889   "\n" +
13890   "    background-image: url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%00%05%08%06%00%00%00%8Do%26%E5%00%00%004IDATx%DAe%8A%B1%0D%000%0C%C2%F2%2CK%96%BC%D0%8F9%81%88H%E9%D0%0E%96%C0%10%92%3E%02%80%5E%82%E4%A9*-%EEsw%C8%CC%11%EE%96w%D8%DC%E9*Eh%0C%151(%00%00%00%00IEND%AEB%60%82\");\n" +
13891   "    background-repeat: no-repeat;\n" +
13892   "    background-position: center;\n" +
13893   "\n" +
13894   "    border-radius: 3px;\n" +
13895   "    \n" +
13896   "    border: 1px solid transparent;\n" +
13897   "}\n" +
13898   "\n" +
13899   ".ace_fold-widget.end {\n" +
13900   "    background-image: url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%05%00%00%00%05%08%06%00%00%00%8Do%26%E5%00%00%004IDATx%DAm%C7%C1%09%000%08C%D1%8C%ECE%C8E(%8E%EC%02)%1EZJ%F1%C1'%04%07I%E1%E5%EE%CAL%F5%A2%99%99%22%E2%D6%1FU%B5%FE0%D9x%A7%26Wz5%0E%D5%00%00%00%00IEND%AEB%60%82\");\n" +
13901   "}\n" +
13902   "\n" +
13903   ".ace_fold-widget.closed {\n" +
13904   "    background-image: url(\"data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%03%00%00%00%06%08%06%00%00%00%06%E5%24%0C%00%00%009IDATx%DA5%CA%C1%09%000%08%03%C0%AC*(%3E%04%C1%0D%BA%B1%23%A4Uh%E0%20%81%C0%CC%F8%82%81%AA%A2%AArGfr%88%08%11%11%1C%DD%7D%E0%EE%5B%F6%F6%CB%B8%05Q%2F%E9tai%D9%00%00%00%00IEND%AEB%60%82\");\n" +
13905   "}\n" +
13906   "\n" +
13907   ".ace_fold-widget:hover {\n" +
13908   "    border: 1px solid rgba(0, 0, 0, 0.3);\n" +
13909   "    background-color: rgba(255, 255, 255, 0.2);\n" +
13910   "    -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\n" +
13911   "    -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\n" +
13912   "    box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\n" +
13913   "}\n" +
13914   "\n" +
13915   ".ace_fold-widget:active {\n" +
13916   "    border: 1px solid rgba(0, 0, 0, 0.4);\n" +
13917   "    background-color: rgba(0, 0, 0, 0.05);\n" +
13918   "    -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\n" +
13919   "    -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\n" +
13920   "    box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\n" +
13921   "}\n" +
13922   "/**\n" +
13923   " * Dark version for fold widgets\n" +
13924   " */\n" +
13925   ".ace_dark .ace_fold-widget {\n" +
13926   "    background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\n" +
13927   "}\n" +
13928   ".ace_dark .ace_fold-widget.end {\n" +
13929   "    background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\n" +
13930   "}\n" +
13931   ".ace_dark .ace_fold-widget.closed {\n" +
13932   "    background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\n" +
13933   "}\n" +
13934   ".ace_dark .ace_fold-widget:hover {\n" +
13935   "    box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\n" +
13936   "    background-color: rgba(255, 255, 255, 0.1);\n" +
13937   "}\n" +
13938   ".ace_dark .ace_fold-widget:active {\n" +
13939   "    -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\n" +
13940   "    -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\n" +
13941   "    box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\n" +
13942   "}\n" +
13943   "    \n" +
13944   "    \n" +
13945   "    \n" +
13946   ".ace_fold-widget.invalid {\n" +
13947   "    background-color: #FFB4B4;\n" +
13948   "    border-color: #DE5555;\n" +
13949   "}\n" +
13950   "\n" +
13951   ".ace_fade-fold-widgets .ace_fold-widget {\n" +
13952   "       -moz-transition: opacity 0.4s ease 0.05s;\n" +
13953   "    -webkit-transition: opacity 0.4s ease 0.05s;\n" +
13954   "         -o-transition: opacity 0.4s ease 0.05s;\n" +
13955   "        -ms-transition: opacity 0.4s ease 0.05s;\n" +
13956   "            transition: opacity 0.4s ease 0.05s;\n" +
13957   "    opacity: 0;\n" +
13958   "}\n" +
13959   "\n" +
13960   ".ace_fade-fold-widgets:hover .ace_fold-widget {\n" +
13961   "       -moz-transition: opacity 0.05s ease 0.05s;\n" +
13962   "    -webkit-transition: opacity 0.05s ease 0.05s;\n" +
13963   "         -o-transition: opacity 0.05s ease 0.05s;\n" +
13964   "        -ms-transition: opacity 0.05s ease 0.05s;\n" +
13965   "            transition: opacity 0.05s ease 0.05s;\n" +
13966   "    opacity:1;\n" +
13967   "}\n" +
13968   "\n" +
13969   ".ace_underline {\n" +
13970   "    text-decoration: underline;\n" +
13971   "}\n" +
13972   "\n" +
13973   ".ace_bold {\n" +
13974   "    font-weight: bold;\n" +
13975   "}\n" +
13976   "\n" +
13977   ".ace_italic {\n" +
13978   "    font-style: italic;\n" +
13979   "}\n" +
13980   "");
13982 define('ace/multi_select', ['require', 'exports', 'module' , 'ace/range_list', 'ace/range', 'ace/selection', 'ace/mouse/multi_select_handler', 'ace/lib/event', 'ace/lib/lang', 'ace/commands/multi_select_commands', 'ace/search', 'ace/edit_session', 'ace/editor'], function(require, exports, module) {
13984 var RangeList = require("./range_list").RangeList;
13985 var Range = require("./range").Range;
13986 var Selection = require("./selection").Selection;
13987 var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
13988 var event = require("./lib/event");
13989 var lang = require("./lib/lang");
13990 var commands = require("./commands/multi_select_commands");
13991 exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
13993 // Todo: session.find or editor.findVolatile that returns range
13994 var Search = require("./search").Search;
13995 var search = new Search();
13997 function find(session, needle, dir) {
13998     search.$options.wrap = true;
13999     search.$options.needle = needle;
14000     search.$options.backwards = dir == -1;
14001     return search.find(session);
14004 // extend EditSession
14005 var EditSession = require("./edit_session").EditSession;
14006 (function() {
14007     this.getSelectionMarkers = function() {
14008         return this.$selectionMarkers;
14009     };
14010 }).call(EditSession.prototype);
14012 // extend Selection
14013 (function() {
14014     // list of ranges in reverse addition order
14015     this.ranges = null;
14017     // automatically sorted list of ranges
14018     this.rangeList = null;
14019     this.addRange = function(range, $blockChangeEvents) {
14020         if (!range)
14021             return;
14023         if (!this.inMultiSelectMode && this.rangeCount == 0) {
14024             var oldRange = this.toOrientedRange();
14025             if (range.intersects(oldRange))
14026                 return $blockChangeEvents || this.fromOrientedRange(range);
14028             this.rangeList.add(oldRange);
14029             this.$onAddRange(oldRange);
14030         }
14032         if (!range.cursor)
14033             range.cursor = range.end;
14035         var removed = this.rangeList.add(range);
14037         this.$onAddRange(range);
14039         if (removed.length)
14040             this.$onRemoveRange(removed);
14042         if (this.rangeCount > 1 && !this.inMultiSelectMode) {
14043             this._emit("multiSelect");
14044             this.inMultiSelectMode = true;
14045             this.session.$undoSelect = false;
14046             this.rangeList.attach(this.session);
14047         }
14049         return $blockChangeEvents || this.fromOrientedRange(range);
14050     };
14052     this.toSingleRange = function(range) {
14053         range = range || this.ranges[0];
14054         var removed = this.rangeList.removeAll();
14055         if (removed.length)
14056             this.$onRemoveRange(removed);
14058         range && this.fromOrientedRange(range);
14059     };
14060     this.substractPoint = function(pos) {
14061         var removed = this.rangeList.substractPoint(pos);
14062         if (removed) {
14063             this.$onRemoveRange(removed);
14064             return removed[0];
14065         }
14066     };
14067     this.mergeOverlappingRanges = function() {
14068         var removed = this.rangeList.merge();
14069         if (removed.length)
14070             this.$onRemoveRange(removed);
14071         else if(this.ranges[0])
14072             this.fromOrientedRange(this.ranges[0]);
14073     };
14075     this.$onAddRange = function(range) {
14076         this.rangeCount = this.rangeList.ranges.length;
14077         this.ranges.unshift(range);
14078         this._emit("addRange", {range: range});
14079     };
14081     this.$onRemoveRange = function(removed) {
14082         this.rangeCount = this.rangeList.ranges.length;
14083         if (this.rangeCount == 1 && this.inMultiSelectMode) {
14084             var lastRange = this.rangeList.ranges.pop();
14085             removed.push(lastRange);
14086             this.rangeCount = 0;
14087         }
14089         for (var i = removed.length; i--; ) {
14090             var index = this.ranges.indexOf(removed[i]);
14091             this.ranges.splice(index, 1);
14092         }
14094         this._emit("removeRange", {ranges: removed});
14096         if (this.rangeCount == 0 && this.inMultiSelectMode) {
14097             this.inMultiSelectMode = false;
14098             this._emit("singleSelect");
14099             this.session.$undoSelect = true;
14100             this.rangeList.detach(this.session);
14101         }
14103         lastRange = lastRange || this.ranges[0];
14104         if (lastRange && !lastRange.isEqual(this.getRange()))
14105             this.fromOrientedRange(lastRange);
14106     };
14108     // adds multicursor support to selection
14109     this.$initRangeList = function() {
14110         if (this.rangeList)
14111             return;
14113         this.rangeList = new RangeList();
14114         this.ranges = [];
14115         this.rangeCount = 0;
14116     };
14118     this.getAllRanges = function() {
14119         return this.rangeList.ranges.concat();
14120     };
14122     this.splitIntoLines = function () {
14123         if (this.rangeCount > 1) {
14124             var ranges = this.rangeList.ranges;
14125             var lastRange = ranges[ranges.length - 1];
14126             var range = Range.fromPoints(ranges[0].start, lastRange.end);
14128             this.toSingleRange();
14129             this.setSelectionRange(range, lastRange.cursor == lastRange.start);
14130         } else {
14131             var range = this.getRange();
14132             var isBackwards = this.isBackwards();
14133             var startRow = range.start.row;
14134             var endRow = range.end.row;
14135             if (startRow == endRow) {
14136                 if (isBackwards)
14137                     var start = range.end, end = range.start;
14138                 else
14139                     var start = range.start, end = range.end;
14140                 
14141                 this.addRange(Range.fromPoints(end, end));
14142                 this.addRange(Range.fromPoints(start, start));
14143                 return;
14144             }
14146             var rectSel = [];
14147             var r = this.getLineRange(startRow, true);
14148             r.start.column = range.start.column;
14149             rectSel.push(r);
14151             for (var i = startRow + 1; i < endRow; i++)
14152                 rectSel.push(this.getLineRange(i, true));
14154             r = this.getLineRange(endRow, true);
14155             r.end.column = range.end.column;
14156             rectSel.push(r);
14158             rectSel.forEach(this.addRange, this);
14159         }
14160     };
14162     this.toggleBlockSelection = function () {
14163         if (this.rangeCount > 1) {
14164             var ranges = this.rangeList.ranges;
14165             var lastRange = ranges[ranges.length - 1];
14166             var range = Range.fromPoints(ranges[0].start, lastRange.end);
14168             this.toSingleRange();
14169             this.setSelectionRange(range, lastRange.cursor == lastRange.start);
14170         } else {
14171             var cursor = this.session.documentToScreenPosition(this.selectionLead);
14172             var anchor = this.session.documentToScreenPosition(this.selectionAnchor);
14174             var rectSel = this.rectangularRangeBlock(cursor, anchor);
14175             rectSel.forEach(this.addRange, this);
14176         }
14177     };
14178     this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
14179         var rectSel = [];
14181         var xBackwards = screenCursor.column < screenAnchor.column;
14182         if (xBackwards) {
14183             var startColumn = screenCursor.column;
14184             var endColumn = screenAnchor.column;
14185         } else {
14186             var startColumn = screenAnchor.column;
14187             var endColumn = screenCursor.column;
14188         }
14190         var yBackwards = screenCursor.row < screenAnchor.row;
14191         if (yBackwards) {
14192             var startRow = screenCursor.row;
14193             var endRow = screenAnchor.row;
14194         } else {
14195             var startRow = screenAnchor.row;
14196             var endRow = screenCursor.row;
14197         }
14199         if (startColumn < 0)
14200             startColumn = 0;
14201         if (startRow < 0)
14202             startRow = 0;
14204         if (startRow == endRow)
14205             includeEmptyLines = true;
14207         for (var row = startRow; row <= endRow; row++) {
14208             var range = Range.fromPoints(
14209                 this.session.screenToDocumentPosition(row, startColumn),
14210                 this.session.screenToDocumentPosition(row, endColumn)
14211             );
14212             if (range.isEmpty()) {
14213                 if (docEnd && isSamePoint(range.end, docEnd))
14214                     break;
14215                 var docEnd = range.end;
14216             }
14217             range.cursor = xBackwards ? range.start : range.end;
14218             rectSel.push(range);
14219         }
14221         if (yBackwards)
14222             rectSel.reverse();
14224         if (!includeEmptyLines) {
14225             var end = rectSel.length - 1;
14226             while (rectSel[end].isEmpty() && end > 0)
14227                 end--;
14228             if (end > 0) {
14229                 var start = 0;
14230                 while (rectSel[start].isEmpty())
14231                     start++;
14232             }
14233             for (var i = end; i >= start; i--) {
14234                 if (rectSel[i].isEmpty())
14235                     rectSel.splice(i, 1);
14236             }
14237         }
14239         return rectSel;
14240     };
14241 }).call(Selection.prototype);
14243 // extend Editor
14244 var Editor = require("./editor").Editor;
14245 (function() {
14247     /** extension
14248      * Editor.updateSelectionMarkers()
14249      *
14250      * Updates the cursor and marker layers.
14251      **/
14252     this.updateSelectionMarkers = function() {
14253         this.renderer.updateCursor();
14254         this.renderer.updateBackMarkers();
14255     };
14256     this.addSelectionMarker = function(orientedRange) {
14257         if (!orientedRange.cursor)
14258             orientedRange.cursor = orientedRange.end;
14260         var style = this.getSelectionStyle();
14261         orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
14263         this.session.$selectionMarkers.push(orientedRange);
14264         this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
14265         return orientedRange;
14266     };
14267     this.removeSelectionMarker = function(range) {
14268         if (!range.marker)
14269             return;
14270         this.session.removeMarker(range.marker);
14271         var index = this.session.$selectionMarkers.indexOf(range);
14272         if (index != -1)
14273             this.session.$selectionMarkers.splice(index, 1);
14274         this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
14275     };
14277     this.removeSelectionMarkers = function(ranges) {
14278         var markerList = this.session.$selectionMarkers;
14279         for (var i = ranges.length; i--; ) {
14280             var range = ranges[i];
14281             if (!range.marker)
14282                 continue;
14283             this.session.removeMarker(range.marker);
14284             var index = markerList.indexOf(range);
14285             if (index != -1)
14286                 markerList.splice(index, 1);
14287         }
14288         this.session.selectionMarkerCount = markerList.length;
14289     };
14291     this.$onAddRange = function(e) {
14292         this.addSelectionMarker(e.range);
14293         this.renderer.updateCursor();
14294         this.renderer.updateBackMarkers();
14295     };
14297     this.$onRemoveRange = function(e) {
14298         this.removeSelectionMarkers(e.ranges);
14299         this.renderer.updateCursor();
14300         this.renderer.updateBackMarkers();
14301     };
14303     this.$onMultiSelect = function(e) {
14304         if (this.inMultiSelectMode)
14305             return;
14306         this.inMultiSelectMode = true;
14308         this.setStyle("multiselect");
14309         this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
14310         this.commands.on("exec", this.$onMultiSelectExec);
14312         this.renderer.updateCursor();
14313         this.renderer.updateBackMarkers();
14314     };
14316     this.$onSingleSelect = function(e) {
14317         if (this.session.multiSelect.inVirtualMode)
14318             return;
14319         this.inMultiSelectMode = false;
14321         this.unsetStyle("multiselect");
14322         this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
14324         this.commands.removeEventListener("exec", this.$onMultiSelectExec);
14325         this.renderer.updateCursor();
14326         this.renderer.updateBackMarkers();
14327     };
14329     this.$onMultiSelectExec = function(e) {
14330         var command = e.command;
14331         var editor = e.editor;
14332         if (!editor.multiSelect)
14333             return;
14334         if (!command.multiSelectAction) {
14335             command.exec(editor, e.args || {});
14336             editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
14337             editor.multiSelect.mergeOverlappingRanges();
14338         } else if (command.multiSelectAction == "forEach") {
14339             editor.forEachSelection(command, e.args);
14340         } else if (command.multiSelectAction == "single") {
14341             editor.exitMultiSelectMode();
14342             command.exec(editor, e.args || {});
14343         } else {
14344             command.multiSelectAction(editor, e.args || {});
14345         }
14346         e.preventDefault();
14347     };
14348     this.forEachSelection = function(cmd, args) {
14349         if (this.inVirtualSelectionMode)
14350             return;
14352         var session = this.session;
14353         var selection = this.selection;
14354         var rangeList = selection.rangeList;
14356         var reg = selection._eventRegistry;
14357         selection._eventRegistry = {};
14359         var tmpSel = new Selection(session);
14360         this.inVirtualSelectionMode = true;
14361         for (var i = rangeList.ranges.length; i--;) {
14362             tmpSel.fromOrientedRange(rangeList.ranges[i]);
14363             this.selection = session.selection = tmpSel;
14364             cmd.exec(this, args || {});
14365             tmpSel.toOrientedRange(rangeList.ranges[i]);
14366         }
14367         tmpSel.detach();
14369         this.selection = session.selection = selection;
14370         this.inVirtualSelectionMode = false;
14371         selection._eventRegistry = reg;
14372         selection.mergeOverlappingRanges();
14374         this.onCursorChange();
14375         this.onSelectionChange();
14376     };
14377     this.exitMultiSelectMode = function() {
14378         if (this.inVirtualSelectionMode)
14379             return;
14380         this.multiSelect.toSingleRange();
14381     };
14383     this.getCopyText = function() {
14384         var text = "";
14385         if (this.inMultiSelectMode) {
14386             var ranges = this.multiSelect.rangeList.ranges;
14387             text = [];
14388             for (var i = 0; i < ranges.length; i++) {
14389                 text.push(this.session.getTextRange(ranges[i]));
14390             }
14391             text = text.join(this.session.getDocument().getNewLineCharacter());
14392         } else if (!this.selection.isEmpty()) {
14393             text = this.session.getTextRange(this.getSelectionRange());
14394         }
14396         return text;
14397     };
14399     // todo this should change when paste becomes a command
14400     this.onPaste = function(text) {
14401         if (this.$readOnly)
14402             return;
14404         this._emit("paste", text);
14405         if (!this.inMultiSelectMode)
14406             return this.insert(text);
14408         var lines = text.split(/\r\n|\r|\n/);
14409         var ranges = this.selection.rangeList.ranges;
14411         if (lines.length > ranges.length || (lines.length <= 2 || !lines[1]))
14412             return this.commands.exec("insertstring", this, text);
14414         for (var i = ranges.length; i--; ) {
14415             var range = ranges[i];
14416             if (!range.isEmpty())
14417                 this.session.remove(range);
14419             this.session.insert(range.start, lines[i]);
14420         }
14421     };
14422     this.findAll = function(needle, options, additive) {
14423         options = options || {};
14424         options.needle = needle || options.needle;
14425         this.$search.set(options);
14427         var ranges = this.$search.findAll(this.session);
14428         if (!ranges.length)
14429             return 0;
14431         this.$blockScrolling += 1;
14432         var selection = this.multiSelect;
14434         if (!additive)
14435             selection.toSingleRange(ranges[0]);
14437         for (var i = ranges.length; i--; )
14438             selection.addRange(ranges[i], true);
14440         this.$blockScrolling -= 1;
14442         return ranges.length;
14443     };
14445     // commands
14446     /** extension
14447      * Editor.selectMoreLines(dir, skip)
14448      * - dir (Number): The direction of lines to select: -1 for up, 1 for down
14449      * - skip (Boolean): If `true`, removes the active selection range
14450      *
14451      * Adds a cursor above or below the active cursor.
14452      **/
14453     this.selectMoreLines = function(dir, skip) {
14454         var range = this.selection.toOrientedRange();
14455         var isBackwards = range.cursor == range.end;
14457         var screenLead = this.session.documentToScreenPosition(range.cursor);
14458         if (this.selection.$desiredColumn)
14459             screenLead.column = this.selection.$desiredColumn;
14461         var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
14463         if (!range.isEmpty()) {
14464             var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
14465             var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
14466         } else {
14467             var anchor = lead;
14468         }
14470         if (isBackwards) {
14471             var newRange = Range.fromPoints(lead, anchor);
14472             newRange.cursor = newRange.start;
14473         } else {
14474             var newRange = Range.fromPoints(anchor, lead);
14475             newRange.cursor = newRange.end;
14476         }
14478         newRange.desiredColumn = screenLead.column;
14479         if (!this.selection.inMultiSelectMode) {
14480             this.selection.addRange(range);
14481         } else {
14482             if (skip)
14483                 var toRemove = range.cursor;
14484         }
14486         this.selection.addRange(newRange);
14487         if (toRemove)
14488             this.selection.substractPoint(toRemove);
14489     };
14490     this.transposeSelections = function(dir) {
14491         var session = this.session;
14492         var sel = session.multiSelect;
14493         var all = sel.ranges;
14495         for (var i = all.length; i--; ) {
14496             var range = all[i];
14497             if (range.isEmpty()) {
14498                 var tmp = session.getWordRange(range.start.row, range.start.column);
14499                 range.start.row = tmp.start.row;
14500                 range.start.column = tmp.start.column;
14501                 range.end.row = tmp.end.row;
14502                 range.end.column = tmp.end.column;
14503             }
14504         }
14505         sel.mergeOverlappingRanges();
14507         var words = [];
14508         for (var i = all.length; i--; ) {
14509             var range = all[i];
14510             words.unshift(session.getTextRange(range));
14511         }
14513         if (dir < 0)
14514             words.unshift(words.pop());
14515         else
14516             words.push(words.shift());
14518         for (var i = all.length; i--; ) {
14519             var range = all[i];
14520             var tmp = range.clone();
14521             session.replace(range, words[i]);
14522             range.start.row = tmp.start.row;
14523             range.start.column = tmp.start.column;
14524         }
14525     }
14527     /** extension
14528      * Editor.selectMore(dir, skip)
14529      * - dir (Number): The direction of lines to select: -1 for up, 1 for down
14530      * - skip (Boolean): If `true`, removes the active selection range
14531      *
14532      * Finds the next occurence of text in an active selection and adds it to the selections.
14533      **/
14534     this.selectMore = function(dir, skip) {
14535         var session = this.session;
14536         var sel = session.multiSelect;
14538         var range = sel.toOrientedRange();
14539         if (range.isEmpty()) {
14540             var range = session.getWordRange(range.start.row, range.start.column);
14541             range.cursor = range.end;
14542             this.multiSelect.addRange(range);
14543         }
14544         var needle = session.getTextRange(range);
14546         var newRange = find(session, needle, dir);
14547         if (newRange) {
14548             newRange.cursor = dir == -1 ? newRange.start : newRange.end;
14549             this.multiSelect.addRange(newRange);
14550         }
14551         if (skip)
14552             this.multiSelect.substractPoint(range.cursor);
14553     };
14554     this.alignCursors = function() {
14555         var session = this.session;
14556         var sel = session.multiSelect;
14557         var ranges = sel.ranges;
14559         if (!ranges.length) {
14560             var range = this.selection.getRange();
14561             var fr = range.start.row, lr = range.end.row;
14562             var lines = this.session.doc.removeLines(fr, lr);
14563             lines = this.$reAlignText(lines);
14564             this.session.doc.insertLines(fr, lines);
14565             range.start.column = 0;
14566             range.end.column = lines[lines.length - 1].length;
14567             this.selection.setRange(range);
14568         } else {
14569             // filter out ranges on same row
14570             var row = -1;
14571             var sameRowRanges = ranges.filter(function(r) {
14572                 if (r.cursor.row == row)
14573                     return true;
14574                 row = r.cursor.row;
14575             });
14576             sel.$onRemoveRange(sameRowRanges);
14578             var maxCol = 0;
14579             var minSpace = Infinity;
14580             var spaceOffsets = ranges.map(function(r) {
14581                 var p = r.cursor;
14582                 var line = session.getLine(p.row);
14583                 var spaceOffset = line.substr(p.column).search(/\S/g);
14584                 if (spaceOffset == -1)
14585                     spaceOffset = 0;
14587                 if (p.column > maxCol)
14588                     maxCol = p.column;
14589                 if (spaceOffset < minSpace)
14590                     minSpace = spaceOffset;
14591                 return spaceOffset;
14592             });
14593             ranges.forEach(function(r, i) {
14594                 var p = r.cursor;
14595                 var l = maxCol - p.column;
14596                 var d = spaceOffsets[i] - minSpace;
14597                 if (l > d)
14598                     session.insert(p, lang.stringRepeat(" ", l - d));
14599                 else
14600                     session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
14602                 r.start.column = r.end.column = maxCol;
14603                 r.start.row = r.end.row = p.row;
14604                 r.cursor = r.end;
14605             });
14606             sel.fromOrientedRange(ranges[0]);
14607             this.renderer.updateCursor();
14608             this.renderer.updateBackMarkers();
14609         }
14610     };
14612     this.$reAlignText = function(lines) {
14613         var isLeftAligned = true, isRightAligned = true;
14614         var startW, textW, endW;
14616         return lines.map(function(line) {
14617             var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
14618             if (!m)
14619                 return [line];
14621             if (startW == null) {
14622                 startW = m[1].length;
14623                 textW = m[2].length;
14624                 endW = m[3].length;
14625                 return m;
14626             }
14628             if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
14629                 isRightAligned = false;
14630             if (startW != m[1].length)
14631                 isLeftAligned = false;
14633             if (startW > m[1].length)
14634                 startW = m[1].length;
14635             if (textW < m[2].length)
14636                 textW = m[2].length;
14637             if (endW > m[3].length)
14638                 endW = m[3].length;
14640             return m;
14641         }).map(isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
14643         function strRepeat(n, ch) {
14644             return Array(n + 1).join(ch)
14645         }
14647         function alignLeft(m) {
14648             return !m[2] ? m[0] : strRepeat(startW, " ") + m[2]
14649                 + strRepeat(textW - m[2].length + endW, " ")
14650                 + m[4].replace(/^([=:])\s+/, "$1 ")
14651         }
14652         function alignRight(m) {
14653             return !m[2] ? m[0] : strRepeat(startW + textW - m[2].length, " ") + m[2]
14654                 + strRepeat(endW, " ")
14655                 + m[4].replace(/^([=:])\s+/, "$1 ")
14656         }
14657         function unAlign(m) {
14658             return !m[2] ? m[0] : strRepeat(startW, " ") + m[2]
14659                 + strRepeat(endW, " ")
14660                 + m[4].replace(/^([=:])\s+/, "$1 ")
14661         }
14662     }
14663 }).call(Editor.prototype);
14666 function isSamePoint(p1, p2) {
14667     return p1.row == p2.row && p1.column == p2.column;
14670 // patch
14671 // adds multicursor support to a session
14672 exports.onSessionChange = function(e) {
14673     var session = e.session;
14674     if (!session.multiSelect) {
14675         session.$selectionMarkers = [];
14676         session.selection.$initRangeList();
14677         session.multiSelect = session.selection;
14678     }
14679     this.multiSelect = session.multiSelect;
14681     var oldSession = e.oldSession;
14682     if (oldSession) {
14683         // todo use events
14684         if (oldSession.multiSelect && oldSession.multiSelect.editor == this)
14685             oldSession.multiSelect.editor = null;
14687         session.multiSelect.removeEventListener("addRange", this.$onAddRange);
14688         session.multiSelect.removeEventListener("removeRange", this.$onRemoveRange);
14689         session.multiSelect.removeEventListener("multiSelect", this.$onMultiSelect);
14690         session.multiSelect.removeEventListener("singleSelect", this.$onSingleSelect);
14691     }
14693     session.multiSelect.on("addRange", this.$onAddRange);
14694     session.multiSelect.on("removeRange", this.$onRemoveRange);
14695     session.multiSelect.on("multiSelect", this.$onMultiSelect);
14696     session.multiSelect.on("singleSelect", this.$onSingleSelect);
14698     // this.$onSelectionChange = this.onSelectionChange.bind(this);
14700     if (this.inMultiSelectMode != session.selection.inMultiSelectMode) {
14701         if (session.selection.inMultiSelectMode)
14702             this.$onMultiSelect();
14703         else
14704             this.$onSingleSelect();
14705     }
14708 // MultiSelect(editor)
14709 // adds multiple selection support to the editor
14710 // (note: should be called only once for each editor instance)
14711 function MultiSelect(editor) {
14712     editor.$onAddRange = editor.$onAddRange.bind(editor);
14713     editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
14714     editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
14715     editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
14717     exports.onSessionChange.call(editor, editor);
14718     editor.on("changeSession", exports.onSessionChange.bind(editor));
14720     editor.on("mousedown", onMouseDown);
14721     editor.commands.addCommands(commands.defaultCommands);
14723     addAltCursorListeners(editor);
14726 function addAltCursorListeners(editor){
14727     var el = editor.textInput.getElement();
14728     var altCursor = false;
14729     var contentEl = editor.renderer.content;
14730     event.addListener(el, "keydown", function(e) {
14731         if (e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey)) {
14732             if (!altCursor) {
14733                 contentEl.style.cursor = "crosshair";
14734                 altCursor = true;
14735             }
14736         } else if (altCursor) {
14737             contentEl.style.cursor = "";
14738         }
14739     });
14741     event.addListener(el, "keyup", reset);
14742     event.addListener(el, "blur", reset);
14743     function reset() {
14744         if (altCursor) {
14745             contentEl.style.cursor = "";
14746             altCursor = false;
14747         }
14748     }
14751 exports.MultiSelect = MultiSelect;
14755 define('ace/range_list', ['require', 'exports', 'module' ], function(require, exports, module) {
14759 var RangeList = function() {
14760     this.ranges = [];
14763 (function() {
14764     this.comparePoints = function(p1, p2) {
14765         return p1.row - p2.row || p1.column - p2.column;
14766     };
14768     this.pointIndex = function(pos, startIndex) {
14769         var list = this.ranges;
14771         for (var i = startIndex || 0; i < list.length; i++) {
14772             var range = list[i];
14773             var cmp = this.comparePoints(pos, range.end);
14775             if (cmp > 0)
14776                 continue;
14777             if (cmp == 0)
14778                 return i;
14779             cmp = this.comparePoints(pos, range.start);
14780             if (cmp >= 0)
14781                 return i;
14783             return -i-1;
14784         }
14785         return -i - 1;
14786     };
14788     this.add = function(range) {
14789         var startIndex = this.pointIndex(range.start);
14790         if (startIndex < 0)
14791             startIndex = -startIndex - 1;
14793         var endIndex = this.pointIndex(range.end, startIndex);
14795         if (endIndex < 0)
14796             endIndex = -endIndex - 1;
14797         else
14798             endIndex++;
14800         return this.ranges.splice(startIndex, endIndex - startIndex, range);
14801     };
14803     this.addList = function(list) {
14804         var removed = [];
14805         for (var i = list.length; i--; ) {
14806             removed.push.call(removed, this.add(list[i]));
14807         }
14808         return removed;
14809     };
14811     this.substractPoint = function(pos) {
14812         var i = this.pointIndex(pos);
14814         if (i >= 0)
14815             return this.ranges.splice(i, 1);
14816     };
14818     // merge overlapping ranges
14819     this.merge = function() {
14820         var removed = [];
14821         var list = this.ranges;
14822         var next = list[0], range;
14823         for (var i = 1; i < list.length; i++) {
14824             range = next;
14825             next = list[i];
14826             var cmp = this.comparePoints(range.end, next.start);
14827             if (cmp < 0)
14828                 continue;
14830             if (cmp == 0 && !(range.isEmpty() || next.isEmpty()))
14831                 continue;
14833             if (this.comparePoints(range.end, next.end) < 0) {
14834                 range.end.row = next.end.row;
14835                 range.end.column = next.end.column;
14836             }
14838             list.splice(i, 1);
14839             removed.push(next);
14840             next = range;
14841             i--;
14842         }
14844         return removed;
14845     };
14847     this.contains = function(row, column) {
14848         return this.pointIndex({row: row, column: column}) >= 0;
14849     };
14851     this.containsPoint = function(pos) {
14852         return this.pointIndex(pos) >= 0;
14853     };
14855     this.rangeAtPoint = function(pos) {
14856         var i = this.pointIndex(pos);
14857         if (i >= 0)
14858             return this.ranges[i];
14859     };
14862     this.clipRows = function(startRow, endRow) {
14863         var list = this.ranges;
14864         if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
14865             return [];
14867         var startIndex = this.pointIndex({row: startRow, column: 0});
14868         if (startIndex < 0)
14869             startIndex = -startIndex - 1;
14870         var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
14871         if (endIndex < 0)
14872             endIndex = -endIndex - 1;
14874         var clipped = [];
14875         for (var i = startIndex; i < endIndex; i++) {
14876             clipped.push(list[i]);
14877         }
14878         return clipped;
14879     };
14881     this.removeAll = function() {
14882         return this.ranges.splice(0, this.ranges.length);
14883     };
14885     this.attach = function(session) {
14886         if (this.session)
14887             this.detach();
14889         this.session = session;
14890         this.onChange = this.$onChange.bind(this);
14892         this.session.on('change', this.onChange);
14893     };
14895     this.detach = function() {
14896         if (!this.session)
14897             return;
14898         this.session.removeListener('change', this.onChange);
14899         this.session = null;
14900     };
14902     this.$onChange = function(e) {
14903         var changeRange = e.data.range;
14904         if (e.data.action[0] == "i"){
14905             var start = changeRange.start;
14906             var end = changeRange.end;
14907         } else {
14908             var end = changeRange.start;
14909             var start = changeRange.end;
14910         }
14911         var startRow = start.row;
14912         var endRow = end.row;
14913         var lineDif = endRow - startRow;
14915         var colDiff = -start.column + end.column;
14916         var ranges = this.ranges;
14918         for (var i = 0, n = ranges.length; i < n; i++) {
14919             var r = ranges[i];
14920             if (r.end.row < startRow)
14921                 continue;
14922             if (r.start.row > startRow)
14923                 break;
14925             if (r.start.row == startRow && r.start.column >= start.column ) {
14926                 r.start.column += colDiff;
14927                 r.start.row += lineDif;
14928             }
14929             if (r.end.row == startRow && r.end.column >=  start.column) {
14930                 r.end.column += colDiff;
14931                 r.end.row += lineDif;
14932             }
14933         }
14935         if (lineDif != 0 && i < n) {
14936             for (; i < n; i++) {
14937                 var r = ranges[i];
14938                 r.start.row += lineDif;
14939                 r.end.row += lineDif;
14940             }
14941         }
14942     };
14944 }).call(RangeList.prototype);
14946 exports.RangeList = RangeList;
14949 define('ace/mouse/multi_select_handler', ['require', 'exports', 'module' , 'ace/lib/event'], function(require, exports, module) {
14951 var event = require("../lib/event");
14954 // mouse
14955 function isSamePoint(p1, p2) {
14956     return p1.row == p2.row && p1.column == p2.column;
14959 function onMouseDown(e) {
14960     var ev = e.domEvent;
14961     var alt = ev.altKey;
14962     var shift = ev.shiftKey;
14963     var ctrl = e.getAccelKey();
14964     var button = e.getButton();
14966     if (e.editor.inMultiSelectMode && button == 2) {
14967         e.editor.textInput.onContextMenu(e.domEvent);
14968         return;
14969     }
14970     
14971     if (!ctrl && !alt) {
14972         if (button == 0 && e.editor.inMultiSelectMode)
14973             e.editor.exitMultiSelectMode();
14974         return;
14975     }
14977     var editor = e.editor;
14978     var selection = editor.selection;
14979     var isMultiSelect = editor.inMultiSelectMode;
14980     var pos = e.getDocumentPosition();
14981     var cursor = selection.getCursor();
14982     var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
14985     var mouseX = e.x, mouseY = e.y;
14986     var onMouseSelection = function(e) {
14987         mouseX = e.clientX;
14988         mouseY = e.clientY;
14989     };
14991     var blockSelect = function() {
14992         var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
14993         var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
14995         if (isSamePoint(screenCursor, newCursor)
14996             && isSamePoint(cursor, selection.selectionLead))
14997             return;
14998         screenCursor = newCursor;
15000         editor.selection.moveCursorToPosition(cursor);
15001         editor.selection.clearSelection();
15002         editor.renderer.scrollCursorIntoView();
15004         editor.removeSelectionMarkers(rectSel);
15005         rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
15006         rectSel.forEach(editor.addSelectionMarker, editor);
15007         editor.updateSelectionMarkers();
15008     };
15009     
15010     var session = editor.session;
15011     var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
15012     var screenCursor = screenAnchor;
15014     
15016     if (ctrl && !shift && !alt && button == 0) {
15017         if (!isMultiSelect && inSelection)
15018             return; // dragging
15020         if (!isMultiSelect) {
15021             var range = selection.toOrientedRange();
15022             editor.addSelectionMarker(range);
15023         }
15025         var oldRange = selection.rangeList.rangeAtPoint(pos);
15027         event.capture(editor.container, function(){}, function() {
15028             var tmpSel = selection.toOrientedRange();
15030             if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
15031                 selection.substractPoint(tmpSel.cursor);
15032             else {
15033                 if (range) {
15034                     editor.removeSelectionMarker(range);
15035                     selection.addRange(range);
15036                 }
15037                 selection.addRange(tmpSel);
15038             }
15039         });
15041     } else if (!shift && alt && button == 0) {
15042         e.stop();
15044         if (isMultiSelect && !ctrl)
15045             selection.toSingleRange();
15046         else if (!isMultiSelect && ctrl)
15047             selection.addRange();
15049         selection.moveCursorToPosition(pos);
15050         selection.clearSelection();
15052         var rectSel = [];
15054         var onMouseSelectionEnd = function(e) {
15055             clearInterval(timerId);
15056             editor.removeSelectionMarkers(rectSel);
15057             for (var i = 0; i < rectSel.length; i++)
15058                 selection.addRange(rectSel[i]);
15059         };
15061         var onSelectionInterval = blockSelect;
15063         event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
15064         var timerId = setInterval(function() {onSelectionInterval();}, 20);
15066         return e.preventDefault();
15067     }
15071 exports.onMouseDown = onMouseDown;
15075 define('ace/commands/multi_select_commands', ['require', 'exports', 'module' , 'ace/keyboard/hash_handler'], function(require, exports, module) {
15077 // commands to enter multiselect mode
15078 exports.defaultCommands = [{
15079     name: "addCursorAbove",
15080     exec: function(editor) { editor.selectMoreLines(-1); },
15081     bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
15082     readonly: true
15083 }, {
15084     name: "addCursorBelow",
15085     exec: function(editor) { editor.selectMoreLines(1); },
15086     bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
15087     readonly: true
15088 }, {
15089     name: "addCursorAboveSkipCurrent",
15090     exec: function(editor) { editor.selectMoreLines(-1, true); },
15091     bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
15092     readonly: true
15093 }, {
15094     name: "addCursorBelowSkipCurrent",
15095     exec: function(editor) { editor.selectMoreLines(1, true); },
15096     bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
15097     readonly: true
15098 }, {
15099     name: "selectMoreBefore",
15100     exec: function(editor) { editor.selectMore(-1); },
15101     bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
15102     readonly: true
15103 }, {
15104     name: "selectMoreAfter",
15105     exec: function(editor) { editor.selectMore(1); },
15106     bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
15107     readonly: true
15108 }, {
15109     name: "selectNextBefore",
15110     exec: function(editor) { editor.selectMore(-1, true); },
15111     bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
15112     readonly: true
15113 }, {
15114     name: "selectNextAfter",
15115     exec: function(editor) { editor.selectMore(1, true); },
15116     bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
15117     readonly: true
15118 }, {
15119     name: "splitIntoLines",
15120     exec: function(editor) { editor.multiSelect.splitIntoLines(); },
15121     bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
15122     readonly: true
15123 }, {
15124     name: "alignCursors",
15125     exec: function(editor) { editor.alignCursors(); },
15126     bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"}
15129 // commands active only in multiselect mode
15130 exports.multiSelectCommands = [{
15131     name: "singleSelection",
15132     bindKey: "esc",
15133     exec: function(editor) { editor.exitMultiSelectMode(); },
15134     readonly: true,
15135     isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
15138 var HashHandler = require("../keyboard/hash_handler").HashHandler;
15139 exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
15143 define('ace/worker/worker_client', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter', 'ace/config'], function(require, exports, module) {
15146 var oop = require("../lib/oop");
15147 var EventEmitter = require("../lib/event_emitter").EventEmitter;
15148 var config = require("../config");
15150 var WorkerClient = function(topLevelNamespaces, mod, classname) {
15152     this.changeListener = this.changeListener.bind(this);
15154     if (config.get("packaged")) {
15155         this.$worker = new Worker(config.moduleUrl(mod, "worker"));
15156     }
15157     else {
15158         var workerUrl;
15159         if (typeof require.supports !== "undefined" && require.supports.indexOf("ucjs2-pinf-0") >= 0) {
15160             // We are running in the sourcemint loader.
15161             workerUrl = require.nameToUrl("ace/worker/worker_sourcemint");
15162         } else {
15163             // We are running in RequireJS.
15164             // nameToUrl is renamed to toUrl in requirejs 2
15165             if (require.nameToUrl && !require.toUrl)
15166                 require.toUrl = require.nameToUrl;
15167             workerUrl = this.$normalizePath(require.toUrl("ace/worker/worker", null, "_"));
15168         }
15169         this.$worker = new Worker(workerUrl);
15171         var tlns = {};
15172         for (var i=0; i<topLevelNamespaces.length; i++) {
15173             var ns = topLevelNamespaces[i];
15174             var path = this.$normalizePath(require.toUrl(ns, null, "_").replace(/.js(\?.*)?$/, ""));
15176             tlns[ns] = path;
15177         }
15178     }
15180     this.$worker.postMessage({
15181         init : true,
15182         tlns: tlns,
15183         module: mod,
15184         classname: classname
15185     });
15187     this.callbackId = 1;
15188     this.callbacks = {};
15190     var _self = this;
15191     this.$worker.onerror = function(e) {
15192         window.console && console.log && console.log(e);
15193         throw e;
15194     };
15195     this.$worker.onmessage = function(e) {
15196         var msg = e.data;
15197         switch(msg.type) {
15198             case "log":
15199                 window.console && console.log && console.log(msg.data);
15200                 break;
15202             case "event":
15203                 _self._emit(msg.name, {data: msg.data});
15204                 break;
15206             case "call":
15207                 var callback = _self.callbacks[msg.id];
15208                 if (callback) {
15209                     callback(msg.data);
15210                     delete _self.callbacks[msg.id];
15211                 }
15212                 break;
15213         }
15214     };
15217 (function(){
15219     oop.implement(this, EventEmitter);
15221     this.$normalizePath = function(path) {
15222         if (!location.host) // needed for file:// protocol
15223             return path;
15224         path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); // Remove domain name and rebuild it
15225         path = location.protocol + "//" + location.host
15226             // paths starting with a slash are relative to the root (host)
15227             + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, ""))
15228             + "/" + path.replace(/^[\/]+/, "");
15229         return path;
15230     };
15232     this.terminate = function() {
15233         this._emit("terminate", {});
15234         this.$worker.terminate();
15235         this.$worker = null;
15236         this.$doc.removeEventListener("change", this.changeListener);
15237         this.$doc = null;
15238     };
15240     this.send = function(cmd, args) {
15241         this.$worker.postMessage({command: cmd, args: args});
15242     };
15244     this.call = function(cmd, args, callback) {
15245         if (callback) {
15246             var id = this.callbackId++;
15247             this.callbacks[id] = callback;
15248             args.push(id);
15249         }
15250         this.send(cmd, args);
15251     };
15253     this.emit = function(event, data) {
15254         try {
15255             // firefox refuses to clone objects which have function properties
15256             // TODO: cleanup event
15257             this.$worker.postMessage({event: event, data: {data: data.data}});
15258         }
15259         catch(ex) {}
15260     };
15262     this.attachToDocument = function(doc) {
15263         if(this.$doc)
15264             this.terminate();
15266         this.$doc = doc;
15267         this.call("setValue", [doc.getValue()]);
15268         doc.on("change", this.changeListener);
15269     };
15271     this.changeListener = function(e) {
15272         e.range = {
15273             start: e.data.range.start,
15274             end: e.data.range.end
15275         };
15276         this.emit("change", e);
15277     };
15279 }).call(WorkerClient.prototype);
15281 exports.WorkerClient = WorkerClient;
15285 define('ace/keyboard/state_handler', ['require', 'exports', 'module' ], function(require, exports, module) {
15288 // If you're developing a new keymapping and want to get an idea what's going
15289 // on, then enable debugging.
15290 var DEBUG = false;
15292 function StateHandler(keymapping) {
15293     this.keymapping = this.$buildKeymappingRegex(keymapping);
15296 StateHandler.prototype = {
15297     /*
15298      * Build the RegExp from the keymapping as RegExp can't stored directly
15299      * in the metadata JSON and as the RegExp used to match the keys/buffer
15300      * need to be adapted.
15301      */
15302     $buildKeymappingRegex: function(keymapping) {
15303         for (var state in keymapping) {
15304             this.$buildBindingsRegex(keymapping[state]);
15305         }
15306         return keymapping;
15307     },
15309     $buildBindingsRegex: function(bindings) {
15310         // Escape a given Regex string.
15311         bindings.forEach(function(binding) {
15312             if (binding.key) {
15313                 binding.key = new RegExp('^' + binding.key + '$');
15314             } else if (Array.isArray(binding.regex)) {
15315                 if (!('key' in binding))
15316                   binding.key = new RegExp('^' + binding.regex[1] + '$');
15317                 binding.regex = new RegExp(binding.regex.join('') + '$');
15318             } else if (binding.regex) {
15319                 binding.regex = new RegExp(binding.regex + '$');
15320             }
15321         });
15322     },
15324     $composeBuffer: function(data, hashId, key, e) {
15325         // Initialize the data object.
15326         if (data.state == null || data.buffer == null) {
15327             data.state = "start";
15328             data.buffer = "";
15329         }
15331         var keyArray = [];
15332         if (hashId & 1) keyArray.push("ctrl");
15333         if (hashId & 8) keyArray.push("command");
15334         if (hashId & 2) keyArray.push("option");
15335         if (hashId & 4) keyArray.push("shift");
15336         if (key)        keyArray.push(key);
15338         var symbolicName = keyArray.join("-");
15339         var bufferToUse = data.buffer + symbolicName;
15341         // Don't add the symbolic name to the key buffer if the alt_ key is
15342         // part of the symbolic name. If it starts with alt_, this means
15343         // that the user hit an alt keycombo and there will be a single,
15344         // new character detected after this event, which then will be
15345         // added to the buffer (e.g. alt_j will result in âˆ†).
15346         //
15347         // We test for 2 and not for & 2 as we only want to exclude the case where
15348         // the option key is pressed alone.
15349         if (hashId != 2) {
15350             data.buffer = bufferToUse;
15351         }
15353         var bufferObj = {
15354             bufferToUse: bufferToUse,
15355             symbolicName: symbolicName
15356         };
15358         if (e) {
15359             bufferObj.keyIdentifier = e.keyIdentifier;
15360         }
15362         return bufferObj;
15363     },
15365     $find: function(data, buffer, symbolicName, hashId, key, keyIdentifier) {
15366         // Holds the command to execute and the args if a command matched.
15367         var result = {};
15369         // Loop over all the bindings of the keymap until a match is found.
15370         this.keymapping[data.state].some(function(binding) {
15371             var match;
15373             // Check if the key matches.
15374             if (binding.key && !binding.key.test(symbolicName)) {
15375                 return false;
15376             }
15378             // Check if the regex matches.
15379             if (binding.regex && !(match = binding.regex.exec(buffer))) {
15380                 return false;
15381             }
15383             // Check if the match function matches.
15384             if (binding.match && !binding.match(buffer, hashId, key, symbolicName, keyIdentifier)) {
15385                 return false;
15386             }
15388             // Check for disallowed matches.
15389             if (binding.disallowMatches) {
15390                 for (var i = 0; i < binding.disallowMatches.length; i++) {
15391                     if (!!match[binding.disallowMatches[i]]) {
15392                         return false;
15393                     }
15394                 }
15395             }
15397             // If there is a command to execute, then figure out the
15398             // command and the arguments.
15399             if (binding.exec) {
15400                 result.command = binding.exec;
15402                 // Build the arguments.
15403                 if (binding.params) {
15404                     var value;
15405                     result.args = {};
15406                     binding.params.forEach(function(param) {
15407                         if (param.match != null && match != null) {
15408                             value = match[param.match] || param.defaultValue;
15409                         } else {
15410                             value = param.defaultValue;
15411                         }
15413                         if (param.type === 'number') {
15414                             value = parseInt(value);
15415                         }
15417                         result.args[param.name] = value;
15418                     });
15419                 }
15420                 data.buffer = "";
15421             }
15423             // Handle the 'then' property.
15424             if (binding.then) {
15425                 data.state = binding.then;
15426                 data.buffer = "";
15427             }
15429             // If no command is set, then execute the "null" fake command.
15430             if (result.command == null) {
15431                 result.command = "null";
15432             }
15434             if (DEBUG) {
15435                 console.log("KeyboardStateMapper#find", binding);
15436             }
15437             return true;
15438         });
15440         if (result.command) {
15441             return result;
15442         } else {
15443             data.buffer = "";
15444             return false;
15445         }
15446     },
15448     /*
15449      * This function is called by keyBinding.
15450      */
15451     handleKeyboard: function(data, hashId, key, keyCode, e) {
15452         if (hashId == -1)
15453             hashId = 0
15454         // If we pressed any command key but no other key, then ignore the input.
15455         // Otherwise "shift-" is added to the buffer, and later on "shift-g"
15456         // which results in "shift-shift-g" which doesn't make sense.
15457         if (hashId != 0 && (key == "" || key == String.fromCharCode(0))) {
15458             return null;
15459         }
15461         // Compute the current value of the keyboard input buffer.
15462         var r = this.$composeBuffer(data, hashId, key, e);
15463         var buffer = r.bufferToUse;
15464         var symbolicName = r.symbolicName;
15465         var keyId = r.keyIdentifier;
15467         r = this.$find(data, buffer, symbolicName, hashId, key, keyId);
15468         if (DEBUG) {
15469             console.log("KeyboardStateMapper#match", buffer, symbolicName, r);
15470         }
15472         return r;
15473     }
15477  * This is a useful matching function and therefore is defined here so that
15478  * users of KeyboardStateMapper can use it.
15480  * @return boolean
15481  *          If no command key (Command|Option|Shift|Ctrl) is pressed, it
15482  *          returns true. If the only the Shift key is pressed + a character
15483  *          true is returned as well. Otherwise, false is returned.
15484  *          Summing up, the function returns true whenever the user typed
15485  *          a normal character on the keyboard and no shortcut.
15486  */
15487 exports.matchCharacterOnly = function(buffer, hashId, key, symbolicName) {
15488     // If no command keys are pressed, then catch the input.
15489     if (hashId == 0) {
15490         return true;
15491     }
15492     // If only the shift key is pressed and a character key, then
15493     // catch that input as well.
15494     else if ((hashId == 4) && key.length == 1) {
15495         return true;
15496     }
15497     // Otherwise, we let the input got through.
15498     else {
15499         return false;
15500     }
15503 exports.StateHandler = StateHandler;
15505 define('ace/placeholder', ['require', 'exports', 'module' , 'ace/range', 'ace/lib/event_emitter', 'ace/lib/oop'], function(require, exports, module) {
15508 var Range = require('./range').Range;
15509 var EventEmitter = require("./lib/event_emitter").EventEmitter;
15510 var oop = require("./lib/oop");
15513  * new PlaceHolder(session, length, pos, others, mainClass, othersClass)
15514  * - session (Document): The document to associate with the anchor
15515  * - length (Number): The starting row position
15516  * - pos (Number): The starting column position
15517  * - others (String):
15518  * - mainClass (String):
15519  * - othersClass (String):
15521  *  TODO
15523  **/
15525 var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
15526     var _self = this;
15527     this.length = length;
15528     this.session = session;
15529     this.doc = session.getDocument();
15530     this.mainClass = mainClass;
15531     this.othersClass = othersClass;
15532     this.$onUpdate = this.onUpdate.bind(this);
15533     this.doc.on("change", this.$onUpdate);
15534     this.$others = others;
15535     
15536     this.$onCursorChange = function() {
15537         setTimeout(function() {
15538             _self.onCursorChange();
15539         });
15540     };
15541     
15542     this.$pos = pos;
15543     // Used for reset
15544     var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
15545     this.$undoStackDepth =  undoStack.length;
15546     this.setup();
15548     session.selection.on("changeCursor", this.$onCursorChange);
15551 (function() {
15553     oop.implement(this, EventEmitter);
15554     this.setup = function() {
15555         var _self = this;
15556         var doc = this.doc;
15557         var session = this.session;
15558         var pos = this.$pos;
15560         this.pos = doc.createAnchor(pos.row, pos.column);
15561         this.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
15562         this.pos.on("change", function(event) {
15563             session.removeMarker(_self.markerId);
15564             _self.markerId = session.addMarker(new Range(event.value.row, event.value.column, event.value.row, event.value.column+_self.length), _self.mainClass, null, false);
15565         });
15566         this.others = [];
15567         this.$others.forEach(function(other) {
15568             var anchor = doc.createAnchor(other.row, other.column);
15569             _self.others.push(anchor);
15570         });
15571         session.setUndoSelect(false);
15572     };
15573     this.showOtherMarkers = function() {
15574         if(this.othersActive) return;
15575         var session = this.session;
15576         var _self = this;
15577         this.othersActive = true;
15578         this.others.forEach(function(anchor) {
15579             anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
15580             anchor.on("change", function(event) {
15581                 session.removeMarker(anchor.markerId);
15582                 anchor.markerId = session.addMarker(new Range(event.value.row, event.value.column, event.value.row, event.value.column+_self.length), _self.othersClass, null, false);
15583             });
15584         });
15585     };
15586     this.hideOtherMarkers = function() {
15587         if(!this.othersActive) return;
15588         this.othersActive = false;
15589         for (var i = 0; i < this.others.length; i++) {
15590             this.session.removeMarker(this.others[i].markerId);
15591         }
15592     };
15593     this.onUpdate = function(event) {
15594         var delta = event.data;
15595         var range = delta.range;
15596         if(range.start.row !== range.end.row) return;
15597         if(range.start.row !== this.pos.row) return;
15598         if (this.$updating) return;
15599         this.$updating = true;
15600         var lengthDiff = delta.action === "insertText" ? range.end.column - range.start.column : range.start.column - range.end.column;
15601         
15602         if(range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1) {
15603             var distanceFromStart = range.start.column - this.pos.column;
15604             this.length += lengthDiff;
15605             if(!this.session.$fromUndo) {
15606                 if(delta.action === "insertText") {
15607                     for (var i = this.others.length - 1; i >= 0; i--) {
15608                         var otherPos = this.others[i];
15609                         var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
15610                         if(otherPos.row === range.start.row && range.start.column < otherPos.column)
15611                             newPos.column += lengthDiff;
15612                         this.doc.insert(newPos, delta.text);
15613                     }
15614                 } else if(delta.action === "removeText") {
15615                     for (var i = this.others.length - 1; i >= 0; i--) {
15616                         var otherPos = this.others[i];
15617                         var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
15618                         if(otherPos.row === range.start.row && range.start.column < otherPos.column)
15619                             newPos.column += lengthDiff;
15620                         this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
15621                     }
15622                 }
15623                 // Special case: insert in beginning
15624                 if(range.start.column === this.pos.column && delta.action === "insertText") {
15625                     setTimeout(function() {
15626                         this.pos.setPosition(this.pos.row, this.pos.column - lengthDiff);
15627                         for (var i = 0; i < this.others.length; i++) {
15628                             var other = this.others[i];
15629                             var newPos = {row: other.row, column: other.column - lengthDiff};
15630                             if(other.row === range.start.row && range.start.column < other.column)
15631                                 newPos.column += lengthDiff;
15632                             other.setPosition(newPos.row, newPos.column);
15633                         }
15634                     }.bind(this), 0);
15635                 }
15636                 else if(range.start.column === this.pos.column && delta.action === "removeText") {
15637                     setTimeout(function() {
15638                         for (var i = 0; i < this.others.length; i++) {
15639                             var other = this.others[i];
15640                             if(other.row === range.start.row && range.start.column < other.column) {
15641                                 other.setPosition(other.row, other.column - lengthDiff);
15642                             }
15643                         }
15644                     }.bind(this), 0);
15645                 }
15646             }
15647             this.pos._emit("change", {value: this.pos});
15648             for (var i = 0; i < this.others.length; i++) {
15649                 this.others[i]._emit("change", {value: this.others[i]});
15650             }
15651         }
15652         this.$updating = false;
15653     };
15655     this.onCursorChange = function(event) {
15656         if (this.$updating) return;
15657         var pos = this.session.selection.getCursor();
15658         if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
15659             this.showOtherMarkers();
15660             this._emit("cursorEnter", event);
15661         } else {
15662             this.hideOtherMarkers();
15663             this._emit("cursorLeave", event);
15664         }
15665     };    
15666     this.detach = function() {
15667         this.session.removeMarker(this.markerId);
15668         this.hideOtherMarkers();
15669         this.doc.removeEventListener("change", this.$onUpdate);
15670         this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
15671         this.pos.detach();
15672         for (var i = 0; i < this.others.length; i++) {
15673             this.others[i].detach();
15674         }
15675         this.session.setUndoSelect(true);
15676     };
15677     this.cancel = function() {
15678         if(this.$undoStackDepth === -1)
15679             throw Error("Canceling placeholders only supported with undo manager attached to session.");
15680         var undoManager = this.session.getUndoManager();
15681         var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
15682         for (var i = 0; i < undosRequired; i++) {
15683             undoManager.undo(true);
15684         }
15685     };
15686 }).call(PlaceHolder.prototype);
15689 exports.PlaceHolder = PlaceHolder;
15692 define('ace/theme/textmate', ['require', 'exports', 'module' , 'text!ace/theme/textmate.css', 'ace/lib/dom'], function(require, exports, module) {
15695 exports.isDark = false;
15696 exports.cssClass = "ace-tm";
15697 exports.cssText = require('text!./textmate.css');
15699 var dom = require("../lib/dom");
15700 dom.importCssString(exports.cssText, exports.cssClass);
15702 define("text!ace/theme/textmate.css", [], ".ace-tm .ace_editor {\n" +
15703   "  border: 2px solid rgb(159, 159, 159);\n" +
15704   "}\n" +
15705   "\n" +
15706   ".ace-tm .ace_editor.ace_focus {\n" +
15707   "  border: 2px solid #327fbd;\n" +
15708   "}\n" +
15709   "\n" +
15710   ".ace-tm .ace_gutter {\n" +
15711   "  background: #f0f0f0;\n" +
15712   "  color: #333;\n" +
15713   "}\n" +
15714   "\n" +
15715   ".ace-tm .ace_print_margin {\n" +
15716   "  width: 1px;\n" +
15717   "  background: #e8e8e8;\n" +
15718   "}\n" +
15719   "\n" +
15720   ".ace-tm .ace_fold {\n" +
15721   "    background-color: #6B72E6;\n" +
15722   "}\n" +
15723   "\n" +
15724   ".ace-tm .ace_scroller {\n" +
15725   "  background-color: #FFFFFF;\n" +
15726   "}\n" +
15727   "\n" +
15728   ".ace-tm .ace_cursor {\n" +
15729   "  border-left: 2px solid black;\n" +
15730   "}\n" +
15731   "\n" +
15732   ".ace-tm .ace_cursor.ace_overwrite {\n" +
15733   "  border-left: 0px;\n" +
15734   "  border-bottom: 1px solid black;\n" +
15735   "}\n" +
15736   "        \n" +
15737   ".ace-tm .ace_line .ace_invisible {\n" +
15738   "  color: rgb(191, 191, 191);\n" +
15739   "}\n" +
15740   "\n" +
15741   ".ace-tm .ace_line .ace_storage,\n" +
15742   ".ace-tm .ace_line .ace_keyword {\n" +
15743   "  color: blue;\n" +
15744   "}\n" +
15745   "\n" +
15746   ".ace-tm .ace_line .ace_constant {\n" +
15747   "  color: rgb(197, 6, 11);\n" +
15748   "}\n" +
15749   "\n" +
15750   ".ace-tm .ace_line .ace_constant.ace_buildin {\n" +
15751   "  color: rgb(88, 72, 246);\n" +
15752   "}\n" +
15753   "\n" +
15754   ".ace-tm .ace_line .ace_constant.ace_language {\n" +
15755   "  color: rgb(88, 92, 246);\n" +
15756   "}\n" +
15757   "\n" +
15758   ".ace-tm .ace_line .ace_constant.ace_library {\n" +
15759   "  color: rgb(6, 150, 14);\n" +
15760   "}\n" +
15761   "\n" +
15762   ".ace-tm .ace_line .ace_invalid {\n" +
15763   "  background-color: rgba(255, 0, 0, 0.1);\n" +
15764   "  color: red;\n" +
15765   "}\n" +
15766   "\n" +
15767   ".ace-tm .ace_line .ace_support.ace_function {\n" +
15768   "  color: rgb(60, 76, 114);\n" +
15769   "}\n" +
15770   "\n" +
15771   ".ace-tm .ace_line .ace_support.ace_constant {\n" +
15772   "  color: rgb(6, 150, 14);\n" +
15773   "}\n" +
15774   "\n" +
15775   ".ace-tm .ace_line .ace_support.ace_type,\n" +
15776   ".ace-tm .ace_line .ace_support.ace_class {\n" +
15777   "  color: rgb(109, 121, 222);\n" +
15778   "}\n" +
15779   "\n" +
15780   ".ace-tm .ace_line .ace_keyword.ace_operator {\n" +
15781   "  color: rgb(104, 118, 135);\n" +
15782   "}\n" +
15783   "\n" +
15784   ".ace-tm .ace_line .ace_string {\n" +
15785   "  color: rgb(3, 106, 7);\n" +
15786   "}\n" +
15787   "\n" +
15788   ".ace-tm .ace_line .ace_comment {\n" +
15789   "  color: rgb(76, 136, 107);\n" +
15790   "}\n" +
15791   "\n" +
15792   ".ace-tm .ace_line .ace_comment.ace_doc {\n" +
15793   "  color: rgb(0, 102, 255);\n" +
15794   "}\n" +
15795   "\n" +
15796   ".ace-tm .ace_line .ace_comment.ace_doc.ace_tag {\n" +
15797   "  color: rgb(128, 159, 191);\n" +
15798   "}\n" +
15799   "\n" +
15800   ".ace-tm .ace_line .ace_constant.ace_numeric {\n" +
15801   "  color: rgb(0, 0, 205);\n" +
15802   "}\n" +
15803   "\n" +
15804   ".ace-tm .ace_line .ace_variable {\n" +
15805   "  color: rgb(49, 132, 149);\n" +
15806   "}\n" +
15807   "\n" +
15808   ".ace-tm .ace_line .ace_xml_pe {\n" +
15809   "  color: rgb(104, 104, 91);\n" +
15810   "}\n" +
15811   "\n" +
15812   ".ace-tm .ace_entity.ace_name.ace_function {\n" +
15813   "  color: #0000A2;\n" +
15814   "}\n" +
15815   "\n" +
15816   "\n" +
15817   ".ace-tm .ace_markup.ace_heading {\n" +
15818   "  color: rgb(12, 7, 255);\n" +
15819   "}\n" +
15820   "\n" +
15821   ".ace-tm .ace_markup.ace_list {\n" +
15822   "  color:rgb(185, 6, 144);\n" +
15823   "}\n" +
15824   "\n" +
15825   ".ace-tm .ace_meta.ace_tag {\n" +
15826   "  color:rgb(0, 22, 142);\n" +
15827   "}\n" +
15828   "\n" +
15829   ".ace-tm .ace_string.ace_regex {\n" +
15830   "  color: rgb(255, 0, 0)\n" +
15831   "}\n" +
15832   "\n" +
15833   ".ace-tm .ace_marker-layer .ace_selection {\n" +
15834   "  background: rgb(181, 213, 255);\n" +
15835   "}\n" +
15836   ".ace-tm.multiselect .ace_selection.start {\n" +
15837   "  box-shadow: 0 0 3px 0px white;\n" +
15838   "  border-radius: 2px;\n" +
15839   "}\n" +
15840   ".ace-tm .ace_marker-layer .ace_step {\n" +
15841   "  background: rgb(252, 255, 0);\n" +
15842   "}\n" +
15843   "\n" +
15844   ".ace-tm .ace_marker-layer .ace_stack {\n" +
15845   "  background: rgb(164, 229, 101);\n" +
15846   "}\n" +
15847   "\n" +
15848   ".ace-tm .ace_marker-layer .ace_bracket {\n" +
15849   "  margin: -1px 0 0 -1px;\n" +
15850   "  border: 1px solid rgb(192, 192, 192);\n" +
15851   "}\n" +
15852   "\n" +
15853   ".ace-tm .ace_marker-layer .ace_active_line {\n" +
15854   "  background: rgba(0, 0, 0, 0.07);\n" +
15855   "}\n" +
15856   "\n" +
15857   ".ace-tm .ace_gutter_active_line {\n" +
15858   "    background-color : #dcdcdc;\n" +
15859   "}\n" +
15860   "\n" +
15861   ".ace-tm .ace_marker-layer .ace_selected_word {\n" +
15862   "  background: rgb(250, 250, 255);\n" +
15863   "  border: 1px solid rgb(200, 200, 250);\n" +
15864   "}\n" +
15865   "\n" +
15866   ".ace-tm .ace_indent-guide {\n" +
15867   "  background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\n" +
15868   "}\n" +
15869   "");
15872             (function() {
15873                 window.require(["ace/ace"], function(a) {
15874                     a && a.config.init();
15875                     if (!window.ace)
15876                         window.ace = {};
15877                     for (var key in a) if (a.hasOwnProperty(key))
15878                         ace[key] = a[key];
15879                 });
15880             })();
15881