forked from cheeaun/neat-bookmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodemirror-base.js
More file actions
89 lines (89 loc) · 44.6 KB
/
codemirror-base.js
File metadata and controls
89 lines (89 loc) · 44.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function method(g,m){return function(){g[m].apply(g,arguments)}}var StopIteration={toString:function(){return"StopIteration"}};function forEach(g,m){if(g.next)try{for(;;)m(g.next())}catch(k){if(k!=StopIteration)throw k;}else for(var l=0;l<g.length;l++)m(g[l])}function map(g,m){var k=[];forEach(g,function(l){k.push(m(l))});return k}function matcher(g){return function(m){return g.test(m)}}function hasClass(g,m){var k=g.className;return k&&RegExp("(^| )"+m+"($| )").test(k)}
function removeClass(g,m){g.className=g.className.replace(RegExp(" "+m+"\\b","g"),"");return g}function insertAfter(g,m){m.parentNode.insertBefore(g,m.nextSibling);return g}function removeElement(g){g.parentNode&&g.parentNode.removeChild(g)}function clearElement(g){for(;g.firstChild;)g.removeChild(g.firstChild)}function isAncestor(g,m){for(;m=m.parentNode;)if(g==m)return true;return false}var nbsp="\u00a0",matching={"{":"}","[":"]","(":")","}":"{","]":"[",")":"("};
function normalizeEvent(g){if(!g.stopPropagation){g.stopPropagation=function(){this.cancelBubble=true};g.preventDefault=function(){this.returnValue=false}}if(!g.stop)g.stop=function(){this.stopPropagation();this.preventDefault()};if(g.type=="keypress"){g.code=g.charCode==null?g.keyCode:g.charCode;g.character=String.fromCharCode(g.code)}return g}
function addEventHandler(g,m,k,l){function p(o){k(normalizeEvent(o||window.event))}if(typeof g.addEventListener=="function"){g.addEventListener(m,p,false);if(l)return function(){g.removeEventListener(m,p,false)}}else{g.attachEvent("on"+m,p);if(l)return function(){g.detachEvent("on"+m,p)}}}function nodeText(g){return g.textContent||g.innerText||g.nodeValue||""}function nodeTop(g){for(var m=0;g.offsetParent;){m+=g.offsetTop;g=g.offsetParent}return m}
function isBR(g){g=g.nodeName;return g=="BR"||g=="br"}function isSpan(g){g=g.nodeName;return g=="SPAN"||g=="span"};var stringStream=function(g){function m(){for(;l==k.length;){p+=k;k="";l=0;try{k=g.next()}catch(o){if(o!=StopIteration)throw o;else return false}}return true}var k="",l=0,p="";return{peek:function(){if(!m())return null;return k.charAt(l)},next:function(){if(!m())if(p.length>0)throw"End of stringstream reached without emptying buffer ('"+p+"').";else throw StopIteration;return k.charAt(l++)},get:function(){var o=p;p="";if(l>0){o+=k.slice(0,l);k=k.slice(l);l=0}return o},push:function(o){k=k.slice(0,
l)+o+k.slice(l)},lookAhead:function(o,q,a,c){function f(j){return c?j.toLowerCase():j}o=f(o);var b=false,d=p,e=l;for(a&&this.nextWhileMatches(/[\s\u00a0]/);;){a=l+o.length;var h=k.length-l;if(a<=k.length){b=o==f(k.slice(l,a));l=a;break}else if(o.slice(0,h)==f(k.slice(l))){p+=k;k="";try{k=g.next()}catch(i){if(i!=StopIteration)throw i;break}l=0;o=o.slice(h)}else break}if(!(b&&q)){k=p.slice(d.length)+k;l=e;p=d}return b},lookAheadRegex:function(o,q){if(o.source.charAt(0)!="^")throw Error("Regexps passed to lookAheadRegex must start with ^");
for(;k.indexOf("\n",l)==-1;)try{k+=g.next()}catch(a){if(a!=StopIteration)throw a;break}var c=k.slice(l).match(o);if(c&&q)l+=c[0].length;return c},more:function(){return this.peek()!==null},applies:function(o){var q=this.peek();return q!==null&&o(q)},nextWhile:function(o){for(var q;(q=this.peek())!==null&&o(q);)this.next()},matches:function(o){var q=this.peek();return q!==null&&o.test(q)},nextWhileMatches:function(o){for(var q;(q=this.peek())!==null&&o.test(q);)this.next()},equals:function(o){return o===
this.peek()},endOfLine:function(){var o=this.peek();return o==null||o=="\n"}}};var select={};
(function(){function g(b,d){for(;b&&b.parentNode!=d;)b=b.parentNode;return b}function m(b,d){for(;!b.previousSibling&&b.parentNode!=d;)b=b.parentNode;return g(b.previousSibling,d)}function k(b){var d=b.nextSibling;if(d){for(;d.firstChild;)d=d.firstChild;return d.nodeType==3||isBR(d)?d:k(d)}else{for(b=b.parentNode;b&&!b.nextSibling;)b=b.parentNode;return b&&k(b)}}select.ie_selection=document.selection&&document.selection.createRangeCollection;select.scrollToNode=function(b,d){if(b){for(var e=b,h=document.body,
i=document.documentElement,j=!e.nextSibling||!e.nextSibling.nextSibling||!e.nextSibling.nextSibling.nextSibling,n=0;e&&!e.offsetTop;){n++;e=e.previousSibling}if(n==0)j=false;if(!(webkit&&e&&e.offsetTop==5&&e.offsetLeft==5)){n=n*(e?e.offsetHeight:0);var t=0,u=b?b.offsetWidth:0;for(e=e;e&&e.offsetParent;){n+=e.offsetTop;isBR(e)||(t+=e.offsetLeft);e=e.offsetParent}e=h.scrollLeft||i.scrollLeft||0;h=h.scrollTop||i.scrollTop||0;var r=false,w=window.innerWidth||i.clientWidth||0;if(d||u<w){if(d){var x=select.offsetInNode(b),
s=nodeText(b).length;if(s)t+=u*(x/s)}u=t-e;if(u<0||u>w){e=t;r=true}}t=n-h;if(t<0||j||t>(window.innerHeight||i.clientHeight||0)-50){h=j?1E6:n;r=true}r&&window.scrollTo(e,h)}}};select.scrollToCursor=function(b){select.scrollToNode(select.selectionTopNode(b,true)||b.firstChild,true)};var l=null;select.snapshotChanged=function(){if(l)l.changed=true};select.snapshotReplaceNode=function(b,d,e,h){function i(j){if(b==j.node){l.changed=true;if(e&&j.offset>e)j.offset-=e;else{j.node=d;j.offset+=h||0}}else if(select.ie_selection&&
j.offset==0&&j.node==k(b))l.changed=true}if(l){i(l.start);i(l.end)}};select.snapshotMove=function(b,d,e,h,i){function j(n){if(b==n.node&&(!i||n.offset==0)){l.changed=true;n.node=d;n.offset=h?Math.max(0,n.offset+e):e}}if(l){j(l.start);j(l.end)}};if(select.ie_selection){var p=function(){var b=document.selection;return b&&(b.createRange||b.createTextRange)()},o=function(b){function d(u){for(var r=null;!r&&u;){r=u.nextSibling;u=u.parentNode}return e(r)}function e(u){for(;u&&u.firstChild;)u=u.firstChild;
return{node:u,offset:0}}var h=p();h.collapse(b);b=h.parentElement();if(!isAncestor(document.body,b))return null;if(!b.firstChild)return e(b);var i=h.duplicate();i.moveToElementText(b);i.collapse(true);for(var j=b.firstChild;j;j=j.nextSibling){if(j.nodeType==3){var n=j.nodeValue.length;i.move("character",n)}else{i.moveToElementText(j);i.collapse(false)}var t=h.compareEndPoints("StartToStart",i);if(t==0)return d(j);if(t!=1){if(j.nodeType!=3)return e(j);i.setEndPoint("StartToEnd",h);return{node:j,offset:n-
i.text.length}}}return d(b)};select.markSelection=function(){l=null;if(document.selection){var b=o(true),d=o(false);if(b&&d)l={start:b,end:d,changed:false}}};select.selectMarked=function(){function b(h){var i=document.body.createTextRange(),j=h.node;if(j)if(j.nodeType==3){i.moveToElementText(j.parentNode);for(h=h.offset;j.previousSibling;){j=j.previousSibling;h+=(j.innerText||"").length}i.move("character",h)}else{i.moveToElementText(j);i.collapse(true)}else{i.moveToElementText(document.body);i.collapse(false)}return i}
if(l&&l.changed){var d=b(l.start),e=b(l.end);d.setEndPoint("StartToEnd",e);d.select()}};select.offsetInNode=function(b){var d=p();if(!d)return 0;var e=d.duplicate();try{e.moveToElementText(b)}catch(h){return 0}d.setEndPoint("StartToStart",e);return d.text.length};select.selectionTopNode=function(b,d){function e(r,w){if(w.nodeType==3){for(var x=0,s=w.previousSibling;s&&s.nodeType==3;){x+=s.nodeValue.length;s=s.previousSibling}if(s){try{r.moveToElementText(s)}catch(v){return false}r.collapse(false)}else r.moveToElementText(w.parentNode);
x&&r.move("character",x)}else try{r.moveToElementText(w)}catch(y){return false}return true}var h=p();if(!h)return false;var i=h.duplicate();h.collapse(d);var j=h.parentElement();if(j&&isAncestor(b,j)){i.moveToElementText(j);if(h.compareEndPoints("StartToStart",i)==1)return g(j,b)}d=0;for(j=b.childNodes.length-1;d<j;){var n=Math.ceil((j+d)/2),t=b.childNodes[n];if(!t)return false;if(!e(i,t))return false;if(h.compareEndPoints("StartToStart",i)==1)d=n;else j=n-1}if(d==0){h=p();i=h.duplicate();try{i.moveToElementText(b)}catch(u){return null}if(h.compareEndPoints("StartToStart",
i)==0)return null}return b.childNodes[d]||null};select.focusAfterNode=function(b,d){var e=document.body.createTextRange();e.moveToElementText(b||d);e.collapse(!b);e.select()};select.somethingSelected=function(){var b=p();return b&&b.text!=""};var q=function(b){var d=p();if(d){d.pasteHTML(b);d.collapse(false);d.select()}};select.insertNewlineAtCursor=function(){q("<br>")};select.insertTabAtCursor=function(){q("\u00a0\u00a0\u00a0\u00a0")};select.cursorPos=function(b,d){var e=p();if(!e)return null;for(var h=
select.selectionTopNode(b,d);h&&!isBR(h);)h=h.previousSibling;var i=e.duplicate();e.collapse(d);if(h){i.moveToElementText(h);i.collapse(false)}else{try{i.moveToElementText(b)}catch(j){return null}i.collapse(true)}e.setEndPoint("StartToStart",i);return{node:h,offset:e.text.length}};select.setCursorPos=function(b,d,e){function h(j){var n=document.body.createTextRange();if(j.node){n.moveToElementText(j.node);n.collapse(false)}else{n.moveToElementText(b);n.collapse(true)}n.move("character",j.offset);
return n}var i=h(d);e&&e!=d&&i.setEndPoint("EndToEnd",h(e));i.select()};select.getBookmark=function(b){var d=select.cursorPos(b,true);b=select.cursorPos(b,false);if(d&&b)return{from:d,to:b}};select.setBookmark=function(b,d){d&&select.setCursorPos(b,d.from,d.to)}}else{var a=function(b,d){for(;b.nodeType!=3&&!isBR(b);){var e=b.childNodes[d]||b.nextSibling;for(d=0;!e&&b.parentNode;){b=b.parentNode;e=b.nextSibling}b=e;if(!e)break}return{node:b,offset:d}};select.markSelection=function(){var b=window.getSelection();
if(!b||b.rangeCount==0)return l=null;b=b.getRangeAt(0);l={start:a(b.startContainer,b.startOffset),end:a(b.endContainer,b.endOffset),changed:false}};select.selectMarked=function(){function b(){if(e.start.node==e.end.node&&e.start.offset==e.end.offset){var i=window.getSelection();if(!i||i.rangeCount==0)return true;i=i.getRangeAt(0);i=a(i.startContainer,i.startOffset);return e.start.node!=i.node||e.start.offset!=i.offset}}function d(i,j){if(i.node)i.offset==0?h["set"+j+"Before"](i.node):h["set"+j](i.node,
i.offset);else h.setStartAfter(document.body.lastChild||document.body)}var e=l;if(e&&(e.changed||webkit&&b())){var h=document.createRange();d(e.end,"End");d(e.start,"Start");c(h)}};var c=function(b){var d=window.getSelection();if(d){d.removeAllRanges();d.addRange(b)}},f=function(){var b=window.getSelection();return!b||b.rangeCount==0?false:b.getRangeAt(0)};select.selectionTopNode=function(b,d){var e=f();if(!e)return false;var h=d?e.startContainer:e.endContainer,i=d?e.startOffset:e.endOffset;window.opera&&
!d&&e.endContainer==b&&e.endOffset==e.startOffset+1&&b.childNodes[e.startOffset]&&isBR(b.childNodes[e.startOffset])&&i--;return h.nodeType==3?i>0?g(h,b):m(h,b):h.nodeName.toUpperCase()=="HTML"?i==1?null:b.lastChild:h==b?i==0?null:h.childNodes[i-1]:i==h.childNodes.length?g(h,b):i==0?m(h,b):g(h.childNodes[i-1],b)};select.focusAfterNode=function(b,d){var e=document.createRange();e.setStartBefore(d.firstChild||d);if(b&&!b.firstChild)e.setEndAfter(b);else b?e.setEnd(b,b.childNodes.length):e.setEndBefore(d.firstChild||
d);e.collapse(false);c(e)};select.somethingSelected=function(){var b=f();return b&&!b.collapsed};select.offsetInNode=function(b){var d=f();if(!d)return 0;d=d.cloneRange();d.setStartBefore(b);return d.toString().length};select.insertNodeAtCursor=function(b){var d=f();if(d){d.deleteContents();d.insertNode(b);webkitLastLineHack(document.body);if(window.opera&&isBR(b)&&isSpan(b.parentNode)){d=b.nextSibling;var e=b.parentNode,h=e.parentNode;h.insertBefore(b,e.nextSibling);for(e="";d&&d.nodeType==3;d=d.nextSibling){e+=
d.nodeValue;removeElement(d)}h.insertBefore(makePartSpan(e,document),b.nextSibling)}d=document.createRange();d.selectNode(b);d.collapse(false);c(d)}};select.insertNewlineAtCursor=function(){select.insertNodeAtCursor(document.createElement("BR"))};select.insertTabAtCursor=function(){select.insertNodeAtCursor(document.createTextNode("\u00a0\u00a0\u00a0\u00a0"))};select.cursorPos=function(b,d){var e=f();if(e){for(var h=select.selectionTopNode(b,d);h&&!isBR(h);)h=h.previousSibling;e=e.cloneRange();e.collapse(d);
h?e.setStartAfter(h):e.setStartBefore(b);e=e.toString();return{node:h,offset:e.length}}};select.setCursorPos=function(b,d,e){function h(j,n,t){function u(s){s.nodeType==3?r.push(s):forEach(s.childNodes,u)}if(n==0&&j&&!j.nextSibling){i["set"+t+"After"](j);return true}if(j=j?j.nextSibling:b.firstChild){if(n==0){i["set"+t+"Before"](j);return true}for(var r=[];;){for(;j&&!r.length;){u(j);j=j.nextSibling}var w=r.shift();if(!w)return false;var x=w.nodeValue.length;if(x>=n){i["set"+t](w,n);return true}n-=
x}}}var i=document.createRange();e=e||d;h(e.node,e.offset,"End")&&h(d.node,d.offset,"Start")&&c(i)}}})();function UndoHistory(g,m,k,l){this.container=g;this.maxDepth=m;this.commitDelay=k;this.editor=l;this.parent=l.parent;this.last=this.first=g={text:"",from:null,to:null};this.firstTouched=false;this.history=[];this.redoHistory=[];this.touched=[]}
UndoHistory.prototype={scheduleCommit:function(){var g=this;this.parent.clearTimeout(this.commitTimeout);this.commitTimeout=this.parent.setTimeout(function(){g.tryCommit()},this.commitDelay)},touch:function(g){this.setTouched(g);this.scheduleCommit()},undo:function(){this.commit();if(this.history.length){var g=this.history.pop();this.redoHistory.push(this.updateTo(g,"applyChain"));this.notifyEnvironment();return this.chainNode(g)}},redo:function(){this.commit();if(this.redoHistory.length){var g=this.redoHistory.pop();
this.addUndoLevel(this.updateTo(g,"applyChain"));this.notifyEnvironment();return this.chainNode(g)}},clear:function(){this.history=[];this.redoHistory=[]},historySize:function(){return{undo:this.history.length,redo:this.redoHistory.length}},push:function(g,m,k){for(var l=[],p=0;p<k.length;p++){var o=p==k.length-1?m:document.createElement("br");l.push({from:g,to:o,text:cleanText(k[p])});g=o}this.pushChains([l],g==null&&m==null);this.notifyEnvironment()},pushChains:function(g,m){this.commit(m);this.addUndoLevel(this.updateTo(g,
"applyChain"));this.redoHistory=[]},chainNode:function(g){for(var m=0;m<g.length;m++){var k=g[m][0];if(k=k&&(k.from||k.to))return k}},reset:function(){this.history=[];this.redoHistory=[]},textAfter:function(g){return this.after(g).text},nodeAfter:function(g){return this.after(g).to},nodeBefore:function(g){return this.before(g).from},tryCommit:function(){!window||!window.parent||!window.UndoHistory||(this.editor.highlightDirty()?this.commit(true):this.scheduleCommit())},commit:function(g){this.parent.clearTimeout(this.commitTimeout);
g||this.editor.highlightDirty(true);g=this.touchedChains();if(g.length){this.addUndoLevel(this.updateTo(g,"linkChain"));this.redoHistory=[];this.notifyEnvironment()}},updateTo:function(g,m){for(var k=[],l=[],p=0;p<g.length;p++){k.push(this.shadowChain(g[p]));l.push(this[m](g[p]))}m=="applyChain"&&this.notifyDirty(l);return k},notifyDirty:function(g){forEach(g,method(this.editor,"addDirtyNode"));this.editor.scheduleHighlight()},notifyEnvironment:function(){this.onChange&&this.onChange();window.frameElement&&
window.frameElement.CodeMirror.updateNumbers&&window.frameElement.CodeMirror.updateNumbers()},linkChain:function(g){for(var m=0;m<g.length;m++){var k=g[m];if(k.from)k.from.historyAfter=k;else this.first=k;if(k.to)k.to.historyBefore=k;else this.last=k}},after:function(g){return g?g.historyAfter:this.first},before:function(g){return g?g.historyBefore:this.last},setTouched:function(g){if(g){if(!g.historyTouched){this.touched.push(g);g.historyTouched=true}}else this.firstTouched=true},addUndoLevel:function(g){this.history.push(g);
this.history.length>this.maxDepth&&this.history.shift()},touchedChains:function(){function g(a,c){if(a)a.historyTemp=c;else p=c}function m(a){for(var c=[],f=a?a.nextSibling:l.container.firstChild;f&&(!isBR(f)||f.hackBR);f=f.nextSibling)!f.hackBR&&f.currentText&&c.push(f.currentText);return{from:a,to:f,text:cleanText(c.join(""))}}function k(a,c){for(var f=c+"Sibling",b=a[f];b&&!isBR(b);)b=b[f];return b}var l=this,p=null,o=[];l.firstTouched&&l.touched.push(null);forEach(l.touched,function(a){if(!(a&&
(a.parentNode!=l.container||a.hackBR))){if(a)a.historyTouched=false;else l.firstTouched=false;var c=m(a),f=l.after(a);if(!f||f.text!=c.text||f.to!=c.to){o.push(c);g(a,c)}}});var q=[];l.touched=[];forEach(o,function(a){if(a.from?a.from.historyTemp:p){for(var c=[],f=a.from,b=true;;){var d=f?f.historyTemp:p;if(!d)if(b)break;else d=m(f);c.unshift(d);g(f,null);if(!f)break;b=l.after(f);f=k(f,"previous")}f=a.to;for(b=l.before(a.from);;){if(!f)break;d=f?f.historyTemp:p;if(!d)if(b)break;else d=m(f);c.push(d);
g(f,null);b=l.before(f);f=k(f,"next")}q.push(c)}});return q},shadowChain:function(g){var m=[],k=this.after(g[0].from);for(g=g[g.length-1].to;;){m.push(k);k=k.to;if(!k||k==g)break;else k=k.historyAfter||this.before(g)}return m},applyChain:function(g){var m=select.cursorPos(this.container,false),k=this,l=g[0].from,p=g[g.length-1].to;(function(b,d){for(var e=b?b.nextSibling:k.container.firstChild;e!=d;){var h=e.nextSibling;removeElement(e);e=h}})(l,p);for(var o=0;o<g.length;o++){var q=g[o];o>0&&k.container.insertBefore(q.from,
p);var a=makePartSpan(fixSpaces(q.text));k.container.insertBefore(a,p);if(m&&m.node==q.from){a=0;var c=this.after(q.from);if(c&&o==g.length-1){for(var f=0;f<m.offset&&q.text.charAt(f)==c.text.charAt(f);f++);if(m.offset>f)a=q.text.length-c.text.length}select.setCursorPos(this.container,{node:q.from,offset:Math.max(0,m.offset+a)})}else m&&o==g.length-1&&m.node&&m.node.parentNode!=this.container&&select.setCursorPos(this.container,{node:q.from,offset:q.text.length})}this.linkChain(g);return l}};var internetExplorer=document.selection&&window.ActiveXObject&&/MSIE/.test(navigator.userAgent),webkit=/AppleWebKit/.test(navigator.userAgent),safari=/Apple Computer, Inc/.test(navigator.vendor),gecko=navigator.userAgent.match(/gecko\/(\d{8})/i);if(gecko)gecko=Number(gecko[1]);var mac=/Mac/.test(navigator.platform),brokenOpera=window.opera&&/Version\/10.[56]/.test(navigator.userAgent),slowWebkit=/AppleWebKit\/533/.test(navigator.userAgent);
function makeWhiteSpace(g){for(var m=[],k=true;g>0;g--){m.push(k||g==1?nbsp:" ");k^=true}return m.join("")}function fixSpaces(g){if(g.charAt(0)==" ")g=nbsp+g.slice(1);return g.replace(/\t/g,function(){return makeWhiteSpace(indentUnit)}).replace(/[ \u00a0]{2,}/g,function(m){return makeWhiteSpace(m.length)})}function cleanText(g){return g.replace(/\u00a0/g," ").replace(/\u200b/g,"")}
function makePartSpan(g){var m=g;if(g.nodeType==3)m=g.nodeValue;else g=document.createTextNode(m);var k=document.createElement("span");k.isPart=true;k.appendChild(g);k.currentText=m;return k}function alwaysZero(){return 0}var webkitLastLineHack=webkit?function(g){var m=g.lastChild;if(!m||!m.hackBR){m=document.createElement("br");m.hackBR=true;g.appendChild(m)}}:function(){};
function asEditorLines(g){var m=makeWhiteSpace(indentUnit);return map(g.replace(/\t/g,m).replace(/\u00a0/g," ").replace(/\r\n?/g,"\n").split("\n"),fixSpaces)}
var Editor=function(){function g(a,c){function f(e,h){if(e.nodeType==3){if((e.nodeValue=fixSpaces(e.nodeValue.replace(/[\r\u200b]/g,"").replace(/\n/g," "))).length)d=false;b.push(e)}else if(isBR(e)&&e.childNodes.length==0){d=true;b.push(e)}else{for(var i=e.firstChild;i;i=i.nextSibling)f(i);if(!d&&q.hasOwnProperty(e.nodeName.toUpperCase())){d=true;if(!c||!h)b.push(document.createElement("br"))}}}var b=[],d=true;f(a,true);return b}function m(a){function c(e){var h=e.parentNode,i=e.nextSibling;return function(j){h.insertBefore(j,
i)}}var f=[],b=null,d=true;return{next:function(){if(!a)throw StopIteration;var e=a;a=e.nextSibling;var h;if(e.isPart&&e.childNodes.length==1&&e.firstChild.nodeType==3){h=e.firstChild.nodeValue;e.dirty=e.dirty||h!=e.currentText;e.currentText=h;h=!/[\n\t\r]/.test(e.currentText)}else h=false;if(h){f.push(e);d=false;return e.currentText}else if(isBR(e)){d&&window.opera&&e.parentNode.insertBefore(makePartSpan(""),e);f.push(e);d=true;return"\n"}else{h=!e.nextSibling;b=c(e);removeElement(e);e=g(e,h);for(h=
0;h<e.length;h++){var i=e,j=h,n=e[h],t="\n";if(n.nodeType==3){select.snapshotChanged();n=makePartSpan(n);t=n.currentText;d=false}else{d&&window.opera&&b(makePartSpan(""));d=true}n.dirty=true;f.push(n);b(n);i[j]=t}return e.join("")}},nodes:f}}function k(a){for(;a&&!isBR(a);)a=a.previousSibling;return a}function l(a,c){if(a){if(isBR(a))a=a.nextSibling}else a=c.firstChild;for(;a&&!isBR(a);)a=a.nextSibling;return a}function p(a,c,f,b){function d(i){i=cleanText(a.history.textAfter(i));return b?i.toLowerCase():
i}this.editor=a;this.history=a.history;this.history.commit();this.valid=!!c;this.atOccurrence=false;if(b==undefined)b=c==c.toLowerCase();var e={node:null,offset:0};if(f&&typeof f=="object"&&typeof f.character=="number"){a.checkLine(f.line);f={node:f.line,offset:f.character};this.pos={from:f,to:f}}else this.pos=f?{from:select.cursorPos(a.container,true)||e,to:select.cursorPos(a.container,false)||e}:{from:e,to:e};if(b)c=c.toLowerCase();var h=c.split("\n");this.matches=h.length==1?function(i,j,n){var t=
d(j),u=c.length,r;if(i?n>=u&&(r=t.lastIndexOf(c,n-u))!=-1:(r=t.indexOf(c,n))!=-1)return{from:{node:j,offset:r},to:{node:j,offset:r+u}}}:function(i,j,n){var t=i?h.length-1:0,u=h[t],r=d(j),w=i?r.indexOf(u)+u.length:r.lastIndexOf(u);if(!(i?w>=n||w!=u.length:w<=n||w!=r.length-u.length))for(n=j;;){if(i&&!n)break;n=i?this.history.nodeBefore(n):this.history.nodeAfter(n);if(!i&&!n)break;r=d(n);u=h[i?--t:++t];if(t>0&&t<h.length-1)if(r!=u)break;else continue;t=i?r.lastIndexOf(u):r.indexOf(u)+u.length;if(i?
t!=r.length-u.length:t!=u.length)break;return{from:{node:i?n:j,offset:i?t:w},to:{node:i?j:n,offset:i?w:t}}}}}function o(a){this.options=a;window.indentUnit=a.indentUnit;this.parent=parent;var c=this.container=document.body;this.history=new UndoHistory(c,a.undoDepth,a.undoDelay,this);var f=this;if(!o.Parser)throw"No parser loaded.";a.parserConfig&&o.Parser.configure&&o.Parser.configure(a.parserConfig);!a.readOnly&&!internetExplorer&&select.setCursorPos(c,{node:null,offset:0});this.dirty=[];this.importCode(a.content||
"");this.history.onChange=a.onChange;if(a.readOnly){if(!a.textWrapping)c.style.whiteSpace="nowrap"}else{if(a.continuousScanning!==false){this.scanner=this.documentScanner(a.passTime);this.delayScanning()}var b=function(){if(document.body.contentEditable!=undefined&&internetExplorer)document.body.contentEditable="true";else document.designMode="on";if(internetExplorer&&a.height!="dynamic")document.body.style.minHeight=window.frameElement.clientHeight-2*document.body.offsetTop-5+"px";document.documentElement.style.borderWidth=
"0";if(!a.textWrapping)c.style.whiteSpace="nowrap"};try{b()}catch(d){var e=addEventHandler(document,"focus",function(){e();b()},true)}addEventHandler(document,"keydown",method(this,"keyDown"));addEventHandler(document,"keypress",method(this,"keyPress"));addEventHandler(document,"keyup",method(this,"keyUp"));var h=function(){f.cursorActivity(false)};addEventHandler(internetExplorer?document.body:window,"mouseup",h);addEventHandler(document.body,"cut",h);gecko&&addEventHandler(window,"pagehide",function(){f.unloaded=
true});addEventHandler(document.body,"paste",function(i){h();var j=null;try{var n=i.clipboardData||window.clipboardData;if(n)j=n.getData("Text")}catch(t){}if(j!==null){i.stop();f.replaceSelection(j);select.scrollToCursor(f.container)}});this.options.autoMatchParens&&addEventHandler(document.body,"click",method(this,"scheduleParenHighlight"))}}var q={P:true,DIV:true,LI:true};p.prototype={findNext:function(){return this.find(false)},findPrevious:function(){return this.find(true)},find:function(a){function c(){var h=
{node:d,offset:e};f.pos={from:h,to:h};return f.atOccurrence=false}if(!this.valid)return false;var f=this,b=a?this.pos.from:this.pos.to,d=b.node,e=b.offset;if(d&&!d.parentNode){d=null;e=0}for(;;){if(this.pos=this.matches(a,d,e))return this.atOccurrence=true;if(a){if(!d)return c();d=this.history.nodeBefore(d);e=this.history.textAfter(d).length}else{b=this.history.nodeAfter(d);if(!b){e=this.history.textAfter(d).length;return c()}d=b;e=0}}},select:function(){if(this.atOccurrence){select.setCursorPos(this.editor.container,
this.pos.from,this.pos.to);select.scrollToCursor(this.editor.container)}},replace:function(a){if(this.atOccurrence){this.pos.to=this.editor.replaceRange(this.pos.from,this.pos.to,a);this.atOccurrence=false}},position:function(){if(this.atOccurrence)return{line:this.pos.from.node,character:this.pos.from.offset}}};o.prototype={importCode:function(a){this.history.push(null,null,asEditorLines(a));this.history.reset()},getCode:function(){if(!this.container.firstChild)return"";var a=[];select.markSelection();
forEach(m(this.container.firstChild),method(a,"push"));select.selectMarked();webkit&&this.container.lastChild.hackBR&&a.pop();webkitLastLineHack(this.container);return cleanText(a.join(""))},checkLine:function(a){if(a===false||!(a==null||a.parentNode==this.container))throw parent.CodeMirror.InvalidLineHandle;},cursorPosition:function(a){if(a==null)a=true;return(a=select.cursorPos(this.container,a))?{line:a.node,character:a.offset}:{line:null,character:0}},firstLine:function(){return null},lastLine:function(){return this.container.lastChild?
k(this.container.lastChild):null},nextLine:function(a){this.checkLine(a);return l(a,this.container)||false},prevLine:function(a){this.checkLine(a);if(a==null)return false;return k(a.previousSibling)},visibleLineCount:function(){for(var a=this.container.firstChild;a&&isBR(a);)a=a.nextSibling;if(!a)return false;return Math.floor((window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight)/a.offsetHeight)},selectLines:function(a,c,f,b){this.checkLine(a);a={node:a,offset:c};
c=null;if(b!==undefined){this.checkLine(f);c={node:f,offset:b}}select.setCursorPos(this.container,a,c);select.scrollToCursor(this.container)},lineContent:function(a){var c=[];for(a=a?a.nextSibling:this.container.firstChild;a&&!isBR(a);a=a.nextSibling)c.push(nodeText(a));return cleanText(c.join(""))},setLineContent:function(a,c){this.history.commit();this.replaceRange({node:a,offset:0},{node:a,offset:this.history.textAfter(a).length},c);this.addDirtyNode(a);this.scheduleHighlight()},removeLine:function(a){for(var c=
a?a.nextSibling:this.container.firstChild;c;){var f=c.nextSibling;removeElement(c);if(isBR(c))break;c=f}this.addDirtyNode(a);this.scheduleHighlight()},insertIntoLine:function(a,c,f){var b=null;if(c=="end")b=l(a,this.container);else for(var d=a?a.nextSibling:this.container.firstChild;d;d=d.nextSibling){if(c==0){b=d;break}var e=nodeText(d);if(e.length>c){b=d.nextSibling;f=e.slice(0,c)+f+e.slice(c);removeElement(d);break}c-=e.length}c=asEditorLines(f);for(f=0;f<c.length;f++){f>0&&this.container.insertBefore(document.createElement("BR"),
b);this.container.insertBefore(makePartSpan(c[f]),b)}this.addDirtyNode(a);this.scheduleHighlight()},selectedText:function(){var a=this.history;a.commit();var c=select.cursorPos(this.container,true),f=select.cursorPos(this.container,false);if(!c||!f)return"";if(c.node==f.node)return a.textAfter(c.node).slice(c.offset,f.offset);var b=[a.textAfter(c.node).slice(c.offset)];for(c=a.nodeAfter(c.node);c!=f.node;c=a.nodeAfter(c))b.push(a.textAfter(c));b.push(a.textAfter(f.node).slice(0,f.offset));return cleanText(b.join("\n"))},
replaceSelection:function(a){this.history.commit();var c=select.cursorPos(this.container,true),f=select.cursorPos(this.container,false);if(c&&f){f=this.replaceRange(c,f,a);select.setCursorPos(this.container,f);webkitLastLineHack(this.container)}},cursorCoords:function(a,c){function f(j,n){var t=-(document.body.scrollTop||document.documentElement.scrollTop||0),u=-(document.body.scrollLeft||document.documentElement.scrollLeft||0)+n;forEach([j,c?null:window.frameElement],function(r){for(;r;){u+=r.offsetLeft;
t+=r.offsetTop;r=r.offsetParent}});return{x:u,y:t,yBot:t+j.offsetHeight}}function b(j,n){var t=document.createElement("SPAN");t.appendChild(document.createTextNode(j));try{return n(t)}finally{t.parentNode&&t.parentNode.removeChild(t)}}var d=select.cursorPos(this.container,a);if(!d)return null;for(var e=d.offset,h=d.node,i=this;e;){h=h?h.nextSibling:this.container.firstChild;d=nodeText(h);if(e<d.length)return b(d.substr(0,e),function(j){j.style.position="absolute";j.style.visibility="hidden";j.className=
h.className;i.container.appendChild(j);return f(h,j.offsetWidth)});e-=d.length}return h&&isSpan(h)?f(h,h.offsetWidth):h&&h.nextSibling&&isSpan(h.nextSibling)?f(h.nextSibling,0):b("\u200b",function(j){h?h.parentNode.insertBefore(j,h.nextSibling):i.container.insertBefore(j,i.container.firstChild);return f(j,0)})},reroutePasteEvent:function(){if(!(this.capturingPaste||window.opera||gecko&&gecko>=20101026)){this.capturingPaste=true;var a=window.frameElement.CodeMirror.textareaHack,c=this.cursorCoords(true,
true);a.style.top=c.y+"px";if(internetExplorer)if(c=select.getBookmark(this.container))this.selectionSnapshot=c;parent.focus();a.value="";a.focus();var f=this;this.parent.setTimeout(function(){f.capturingPaste=false;window.focus();f.selectionSnapshot&&window.select.setBookmark(f.container,f.selectionSnapshot);var b=a.value;if(b){f.replaceSelection(b);select.scrollToCursor(f.container)}},10)}},replaceRange:function(a,c,f){f=asEditorLines(f);f[0]=this.history.textAfter(a.node).slice(0,a.offset)+f[0];
var b=f[f.length-1];f[f.length-1]=b+this.history.textAfter(c.node).slice(c.offset);c=this.history.nodeAfter(c.node);this.history.push(a.node,c,f);return{node:this.history.nodeBefore(c),offset:b.length}},getSearchCursor:function(a,c,f){return new p(this,a,c,f)},reindent:function(){this.container.firstChild&&this.indentRegion(null,this.container.lastChild)},reindentSelection:function(a){if(select.somethingSelected()){var c=select.selectionTopNode(this.container,true),f=select.selectionTopNode(this.container,
false);c===false||f===false||this.indentRegion(c,f,a)}else this.indentAtCursor(a)},grabKeys:function(a,c){this.frozen=a;this.keyFilter=c},ungrabKeys:function(){this.frozen="leave"},setParser:function(a,c){o.Parser=window[a];(c=c||this.options.parserConfig)&&o.Parser.configure&&o.Parser.configure(c);if(this.container.firstChild){forEach(this.container.childNodes,function(f){if(f.nodeType!=3)f.dirty=true});this.addDirtyNode(this.firstChild);this.scheduleHighlight()}},keyDown:function(a){if(this.frozen==
"leave")this.keyFilter=this.frozen=null;if(this.frozen&&(!this.keyFilter||this.keyFilter(a.keyCode,a))){a.stop();this.frozen(a)}else{var c=a.keyCode;this.delayScanning();this.options.autoMatchParens&&this.scheduleParenHighlight();if(c==13){if(a.ctrlKey&&!a.altKey)this.reparseBuffer();else{select.insertNewlineAtCursor();c=this.options.enterMode;if(c!="flat")this.indentAtCursor(c=="keep"?"keep":undefined);select.scrollToCursor(this.container)}a.stop()}else if(c==9&&this.options.tabMode!="default"&&
!a.ctrlKey){this.handleTab(!a.shiftKey);a.stop()}else if(c==32&&a.shiftKey&&this.options.tabMode=="default"){this.handleTab(true);a.stop()}else if(c==36&&!a.shiftKey&&!a.ctrlKey)this.home()&&a.stop();else if(c==35&&!a.shiftKey&&!a.ctrlKey)this.end()&&a.stop();else if(c==33&&!a.shiftKey&&!a.ctrlKey&&!gecko)this.pageUp()&&a.stop();else if(c==34&&!a.shiftKey&&!a.ctrlKey&&!gecko)this.pageDown()&&a.stop();else if((c==219||c==221)&&a.ctrlKey&&!a.altKey){this.highlightParens(a.shiftKey,true);a.stop()}else if(a.metaKey&&
!a.shiftKey&&(c==37||c==39)){var f=select.selectionTopNode(this.container);if(!(f===false||!this.container.firstChild)){if(c==37)select.focusAfterNode(k(f),this.container);else{c=l(f,this.container);select.focusAfterNode(c?c.previousSibling:this.container.lastChild,this.container)}a.stop()}}else if((a.ctrlKey||a.metaKey)&&!a.altKey)if(a.shiftKey&&c==90||c==89){select.scrollToNode(this.history.redo());a.stop()}else if(c==90||safari&&c==8){select.scrollToNode(this.history.undo());a.stop()}else if(c==
83&&this.options.saveFunction){this.options.saveFunction();a.stop()}else c==86&&!mac&&this.reroutePasteEvent()}},keyPress:function(a){var c=this.options.electricChars&&o.Parser.electricChars,f=this;if(this.frozen&&(!this.keyFilter||this.keyFilter(a.keyCode||a.code,a))||a.code==13||a.code==9&&this.options.tabMode!="default"||a.code==32&&a.shiftKey&&this.options.tabMode=="default")a.stop();else if(mac&&(a.ctrlKey||a.metaKey)&&a.character=="v")this.reroutePasteEvent();else if(c&&c.indexOf(a.character)!=
-1)this.parent.setTimeout(function(){f.indentAtCursor(null)},0);else if(brokenOpera)if(a.code==8){var b=select.selectionTopNode(this.container);f=this;var d=b?b.nextSibling:this.container.firstChild;b!==false&&d&&isBR(d)&&this.parent.setTimeout(function(){select.selectionTopNode(f.container)==d&&select.focusAfterNode(d.previousSibling,f.container)},20)}else{if(a.code==46){b=select.selectionTopNode(this.container);f=this;b&&isBR(b)&&this.parent.setTimeout(function(){select.selectionTopNode(f.container)!=
b&&select.focusAfterNode(b,f.container)},20)}}else if(slowWebkit){d=(b=select.selectionTopNode(this.container))?b.nextSibling:this.container.firstChild;if(b&&d&&isBR(d)&&!isBR(b)){var e=document.createTextNode("\u200b");this.container.insertBefore(e,d);this.parent.setTimeout(function(){if(e.nodeValue=="\u200b")removeElement(e);else e.nodeValue=e.nodeValue.replace("\u200b","")},20)}}webkit&&!this.options.textWrapping&&setTimeout(function(){var h=select.selectionTopNode(f.container,true);h&&h.nodeType==
3&&h.previousSibling&&isBR(h.previousSibling)&&h.nextSibling&&isBR(h.nextSibling)&&h.parentNode.replaceChild(document.createElement("BR"),h.previousSibling)},50)},keyUp:function(a){this.cursorActivity(a.keyCode>=16&&a.keyCode<=18||a.keyCode>=33&&a.keyCode<=40)},indentLineAfter:function(a,c){function f(n){n=n?n.nextSibling:b.container.firstChild;if(!n||!hasClass(n,"whitespace"))return null;return n}var b=this,d=f(a),e=0,h=d?d.currentText.length:0,i=d?d.nextSibling:a?a.nextSibling:this.container.firstChild;
if(c=="keep"){if(a){var j=f(k(a.previousSibling));if(j)e=j.currentText.length}}else{j=a&&i&&i.currentText?i.currentText:"";if(c!=null&&this.options.tabMode=="shift")e=c?h+indentUnit:Math.max(0,h-indentUnit);else if(a)e=a.indentation(j,h,c);else if(o.Parser.firstIndentation)e=o.Parser.firstIndentation(j,h,c)}h=e-h;if(h<0)if(e==0){if(i)select.snapshotMove(d.firstChild,i.firstChild||i,0);removeElement(d);d=null}else{select.snapshotMove(d.firstChild,d.firstChild,h,true);d.currentText=makeWhiteSpace(e);
d.firstChild.nodeValue=d.currentText}else if(h>0)if(d){d.currentText=makeWhiteSpace(e);d.firstChild.nodeValue=d.currentText;select.snapshotMove(d.firstChild,d.firstChild,h,true)}else{d=makePartSpan(makeWhiteSpace(e));d.className="whitespace";a?insertAfter(d,a):this.container.insertBefore(d,this.container.firstChild);select.snapshotMove(i&&(i.firstChild||i),d.firstChild,e,false,true)}else d&&select.snapshotMove(d.firstChild,d.firstChild,e,false);h!=0&&this.addDirtyNode(a)},highlightAtCursor:function(){var a=
select.selectionTopNode(this.container,true),c=select.selectionTopNode(this.container,false);if(a===false||c===false)return false;select.markSelection();if(this.highlight(a,l(c,this.container),true,20)===false)return false;select.selectMarked();return true},handleTab:function(a){this.options.tabMode=="spaces"?select.insertTabAtCursor():this.reindentSelection(a)},home:function(){var a=select.selectionTopNode(this.container,true),c=a;if(a===false||!(!a||a.isPart||isBR(a))||!this.container.firstChild)return false;
for(;a&&!isBR(a);)a=a.previousSibling;var f=a?a.nextSibling:this.container.firstChild;f&&f!=c&&f.isPart&&hasClass(f,"whitespace")?select.focusAfterNode(f,this.container):select.focusAfterNode(a,this.container);select.scrollToCursor(this.container);return true},end:function(){var a=select.selectionTopNode(this.container,true);if(a===false)return false;a=l(a,this.container);if(!a)return false;select.focusAfterNode(a.previousSibling,this.container);select.scrollToCursor(this.container);return true},
pageUp:function(){var a=this.cursorPosition().line,c=this.visibleLineCount();if(a===false||c===false)return false;c-=2;for(var f=0;f<c;f++){a=this.prevLine(a);if(a===false)break}if(f==0)return false;select.setCursorPos(this.container,{node:a,offset:0});select.scrollToCursor(this.container);return true},pageDown:function(){var a=this.cursorPosition().line,c=this.visibleLineCount();if(a===false||c===false)return false;c-=2;for(var f=0;f<c;f++){var b=this.nextLine(a);if(b===false)break;a=b}if(f==0)return false;
select.setCursorPos(this.container,{node:a,offset:0});select.scrollToCursor(this.container);return true},scheduleParenHighlight:function(){this.parenEvent&&this.parent.clearTimeout(this.parenEvent);var a=this;this.parenEvent=this.parent.setTimeout(function(){a.highlightParens()},300)},highlightParens:function(a,c){function f(w,x){if(w)if(i)if(i.call)i(w,x);else w.className+=" "+i[x?0:1];else{w.style.fontWeight="bold";w.style.color=x?"#8F8":"#F88"}}function b(w){if(w)if(i&&!i.call)removeClass(removeClass(w,
i[0]),i[1]);else if(h.options.unmarkParen)h.options.unmarkParen(w);else{w.style.fontWeight="";w.style.color=""}}function d(w){if(w.currentText)return(w=w.currentText.match(/^[\s\u00a0]*([\(\)\[\]{}])[\s\u00a0]*$/))&&w[1]}function e(){for(var w=[],x,s=true,v=n;v;v=u?v.nextSibling:v.previousSibling)if(v.className==t&&isSpan(v)&&(x=d(v))){if(/[\(\[\{]/.test(x)==u)w.push(x);else if(w.length){if(w.pop()!=matching[x])s=false}else s=false;if(!w.length)break}else if(v.dirty||!isSpan(v)&&!isBR(v))return{node:v,
status:"dirty"};return{node:v,status:v&&s}}var h=this,i=this.options.markParen;if(typeof i=="string")i=[i,i];if(!c&&h.highlighted){b(h.highlighted[0]);b(h.highlighted[1])}if(!(!window||!window.parent||!window.select)){this.parenEvent&&this.parent.clearTimeout(this.parenEvent);this.parenEvent=null;var j,n=select.selectionTopNode(this.container,true);if(n&&this.highlightAtCursor())if((n=select.selectionTopNode(this.container,true))&&((j=d(n))||(n=n.nextSibling)&&(j=d(n))))for(var t=n.className,u=/[\(\[\{]/.test(j);;){var r=
e();if(r.status=="dirty"){this.highlight(r.node,l(r.node));r.node.dirty=false}else{f(n,r.status);f(r.node,r.status);if(c)h.parent.setTimeout(function(){b(n);b(r.node)},500);else h.highlighted=[n,r.node];a&&r.node&&select.focusAfterNode(r.node.previousSibling,this.container);break}}}},indentAtCursor:function(a){if(this.container.firstChild)if(this.highlightAtCursor()){var c=select.selectionTopNode(this.container,false);if(c!==false){select.markSelection();this.indentLineAfter(k(c),a);select.selectMarked()}}},
indentRegion:function(a,c,f){var b=a=k(a),d=a&&k(a.previousSibling);isBR(c)||(c=l(c,this.container));this.addDirtyNode(a);do{var e=l(b,this.container);b&&this.highlight(d,e,true);this.indentLineAfter(b,f);d=b;b=e}while(b!=c);select.setCursorPos(this.container,{node:a,offset:0},{node:c,offset:0})},cursorActivity:function(a){if(this.unloaded){window.document.designMode="off";window.document.designMode="on";this.unloaded=false}if(internetExplorer){this.container.createTextRange().execCommand("unlink");
clearTimeout(this.saveSelectionSnapshot);var c=this;this.saveSelectionSnapshot=setTimeout(function(){var d=select.getBookmark(c.container);if(d)c.selectionSnapshot=d},200)}var f=this.options.onCursorActivity;if(!a||f){var b=select.selectionTopNode(this.container,false);if(!(b===false||!this.container.firstChild)){b=b||this.container.firstChild;f&&f(b);if(!a){this.scheduleHighlight();this.addDirtyNode(b)}}}},reparseBuffer:function(){forEach(this.container.childNodes,function(a){a.dirty=true});this.container.firstChild&&
this.addDirtyNode(this.container.firstChild)},addDirtyNode:function(a){if(a=a||this.container.firstChild){for(var c=0;c<this.dirty.length;c++)if(this.dirty[c]==a)return;if(a.nodeType!=3)a.dirty=true;this.dirty.push(a)}},allClean:function(){return!this.dirty.length},scheduleHighlight:function(){var a=this;this.parent.clearTimeout(this.highlightTimeout);this.highlightTimeout=this.parent.setTimeout(function(){a.highlightDirty()},this.options.passDelay)},getDirtyNode:function(){for(;this.dirty.length>
0;){var a=this.dirty.pop();try{for(;a&&a.parentNode!=this.container;)a=a.parentNode;if(a&&(a.dirty||a.nodeType==3))return a}catch(c){}}return null},highlightDirty:function(a){if(!window||!window.parent||!window.select)return false;this.options.readOnly||select.markSelection();for(var c,f=a?null:(new Date).getTime()+this.options.passTime;((new Date).getTime()<f||a)&&(c=this.getDirtyNode());){var b=this.highlight(c,f);b&&b.node&&b.dirty&&this.addDirtyNode(b.node.nextSibling)}this.options.readOnly||
select.selectMarked();c&&this.scheduleHighlight();return this.dirty.length==0},documentScanner:function(a){var c=this,f=null;return function(){if(!(!window||!window.parent||!window.select)){if(f&&f.parentNode!=c.container)f=null;select.markSelection();var b=c.highlight(f,(new Date).getTime()+a,true);select.selectMarked();b=b?b.node&&b.node.nextSibling:null;f=f==b?null:b;c.delayScanning()}}},delayScanning:function(){if(this.scanner){this.parent.clearTimeout(this.documentScan);this.documentScan=this.parent.setTimeout(this.scanner,
this.options.continuousScanning)}},highlight:function(a,c,f,b){function d(s){if(s){var v=s.oldNextSibling;if(r||v===undefined||s.nextSibling!=v)h.history.touch(s);s.oldNextSibling=s.nextSibling}else{v=h.container.oldFirstChild;if(r||v===undefined||h.container.firstChild!=v)h.history.touch(null);h.container.oldFirstChild=h.container.firstChild}}var e=this.container,h=this,i=this.options.activeTokens,j=typeof c=="number"?c:null;if(!e.firstChild)return false;for(;a&&(!a.parserFromHere||a.dirty);){if(b!=
null&&isBR(a)&&--b<0)return false;a=a.previousSibling}if(a&&!a.nextSibling)return false;var n=m(a?a.nextSibling:e.firstChild);b=stringStream(n);var t=a?a.parserFromHere(b):o.Parser.make(b),u={current:null,get:function(){if(!this.current)this.current=n.nodes.shift();return this.current},next:function(){this.current=null},remove:function(){e.removeChild(this.get());this.current=null},getNonEmpty:function(){for(var s=this.get();s&&isSpan(s)&&s.currentText=="";)if(window.opera&&(s.previousSibling==null||
isBR(s.previousSibling))&&(s.nextSibling==null||isBR(s.nextSibling))){this.next();s=this.get()}else{var v=s;this.remove();s=this.get();select.snapshotMove(v.firstChild,s&&(s.firstChild||s),0)}return s}},r=false,w=true,x=0;forEach(t,function(s){var v=u.getNonEmpty();if(s.value=="\n"){if(!isBR(v))throw"Parser out of sync. Expected BR.";if(v.dirty||!v.indentation)r=true;d(a);a=v;v.parserFromHere=t.copy();v.indentation=s.indentation||alwaysZero;v.dirty=false;if(j==null&&v==c)throw StopIteration;if(j!=
null&&(new Date).getTime()>=j||!r&&!w&&x>1&&!f)throw StopIteration;w=r;r=false;x=0;u.next()}else{if(!isSpan(v))throw"Parser out of sync. Expected SPAN.";if(v.dirty)r=true;x++;if(!v.reduced&&v.currentText==s.value&&v.className==s.style){i&&v.dirty&&i(v,s,h);v.dirty=false;u.next()}else{r=true;var y=makePartSpan(s.value);y.className=s.style;e.insertBefore(y,v);i&&i(y,s,h);s=s.value.length;for(var A=0;s>0;){v=u.get();var z=v.currentText.length;select.snapshotReplaceNode(v.firstChild,y.firstChild,s,A);
if(z>s){v=v;v.currentText=v.currentText.substring(s);v.reduced=true;s=0}else{s-=z;A+=z;u.remove()}}}}});d(a);webkitLastLineHack(this.container);return{node:u.getNonEmpty(),dirty:r}}};return o}();addEventHandler(window,"load",function(){var g=window.frameElement.CodeMirror;g.editor=new Editor(g.options);this.parent.setTimeout(method(g,"init"),0)});function tokenizer(g,m){function k(p){return p!="\n"&&/^[\s\u00a0]*$/.test(p)}var l={state:m,take:function(p){if(typeof p=="string")p={style:p,type:p};p.content=(p.content||"")+g.get();/\n$/.test(p.content)||g.nextWhile(k);p.value=p.content+g.get();return p},next:function(){if(!g.more())throw StopIteration;var p;if(g.equals("\n")){g.next();return this.take("whitespace")}if(g.applies(k))p="whitespace";else for(;!p;)p=this.state(g,function(o){l.state=o});return this.take(p)}};return l};var CSSParser=Editor.Parser=function(){function g(k,l,p){return function(o){return!k||/^\}/.test(o)?p:l?p+indentUnit*2:p+indentUnit}}var m=function(){function k(q,a){var c=q.next();if(c=="@"){q.nextWhileMatches(/\w/);return"css-at"}else if(c=="/"&&q.equals("*")){a(l);return null}else if(c=="<"&&q.equals("!")){a(p);return null}else if(c=="=")return"css-compare";else if(q.equals("=")&&(c=="~"||c=="|")){q.next();return"css-compare"}else if(c=='"'||c=="'"){a(o(c));return null}else if(c=="#"){q.nextWhileMatches(/\w/);
return"css-hash"}else if(c=="!"){q.nextWhileMatches(/[ \t]/);q.nextWhileMatches(/\w/);return"css-important"}else if(/\d/.test(c)){q.nextWhileMatches(/[\w.%]/);return"css-unit"}else if(/[,.+>*\/]/.test(c))return"css-select-op";else if(/[;{}:\[\]]/.test(c))return"css-punctuation";else{q.nextWhileMatches(/[\w\\\-_]/);return"css-identifier"}}function l(q,a){for(var c=false;!q.endOfLine();){var f=q.next();if(c&&f=="/"){a(k);break}c=f=="*"}return"css-comment"}function p(q,a){for(var c=0;!q.endOfLine();){var f=
q.next();if(c>=2&&f==">"){a(k);break}c=f=="-"?c+1:0}return"css-comment"}function o(q){return function(a,c){for(var f=false;!a.endOfLine();){var b=a.next();if(b==q&&!f)break;f=!f&&b=="\\"}f||c(k);return"css-string"}}return function(q,a){return tokenizer(q,a||k)}}();return{make:function(k,l){l=l||0;var p=m(k),o=false,q=false,a=false,c={next:function(){var f=p.next(),b=f.style,d=f.content;if(b=="css-hash")b=f.style=q?"css-colorcode":"css-identifier";if(b=="css-identifier")if(q)f.style="css-value";else if(!o&&
!a)f.style="css-selector";if(d=="\n")f.indentation=g(o,q,l);if(d=="{"&&a=="@media")a=false;else if(d=="{")o=true;else if(d=="}")o=q=a=false;else if(d==";")q=a=false;else if(o&&b!="css-comment"&&b!="whitespace")q=true;else if(!o&&b=="css-at")a=d;return f},copy:function(){var f=o,b=q,d=p.state;return function(e){p=m(e,d);o=f;q=b;return c}}};return c},electricChars:"}"}}();