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(p){for(var r=[],t=true;p>0;p--){r.push(t||p==1?nbsp:" ");t^=true}return r.join("")}function fixSpaces(p){if(p.charAt(0)==" ")p=nbsp+p.slice(1);return p.replace(/\t/g,function(){return makeWhiteSpace(indentUnit)}).replace(/[ \u00a0]{2,}/g,function(r){return makeWhiteSpace(r.length)})}function cleanText(p){return p.replace(/\u00a0/g," ").replace(/\u200b/g,"")}
function makePartSpan(p){var r=p;if(p.nodeType==3)r=p.nodeValue;else p=document.createTextNode(r);var t=document.createElement("SPAN");t.isPart=true;t.appendChild(p);t.currentText=r;return t}function alwaysZero(){return 0}
var webkitLastLineHack=webkit?function(p){var r=p.lastChild;if(!r||!r.hackBR){r=document.createElement("BR");r.hackBR=true;p.appendChild(r)}}:function(){},Editor=function(){function p(a){var b=makeWhiteSpace(indentUnit);return map(a.replace(/\t/g,b).replace(/\u00a0/g," ").replace(/\r\n?/g,"\n").split("\n"),fixSpaces)}function r(a,b){function c(f,g){if(f.nodeType==3){if((f.nodeValue=fixSpaces(f.nodeValue.replace(/[\r\u200b]/g,"").replace(/\n/g," "))).length)d=false;e.push(f)}else if(isBR(f)&&f.childNodes.length==
0){d=true;e.push(f)}else{for(var h=f.firstChild;h;h=h.nextSibling)c(h);if(!d&&B.hasOwnProperty(f.nodeName.toUpperCase())){d=true;if(!b||!g)e.push(document.createElement("BR"))}}}var e=[],d=true;c(a,true);return e}function t(a){function b(f){var g=f.parentNode,h=f.nextSibling;return function(j){g.insertBefore(j,h)}}var c=[],e=null,d=true;return{next:function(){if(!a)throw StopIteration;var f=a;a=f.nextSibling;var g;if(f.isPart&&f.childNodes.length==1&&f.firstChild.nodeType==3){f.currentText=f.firstChild.nodeValue;
g=!/[\n\t\r]/.test(f.currentText)}else g=false;if(g){c.push(f);d=false;return f.currentText}else if(isBR(f)){d&&window.opera&&f.parentNode.insertBefore(makePartSpan(""),f);c.push(f);d=true;return"\n"}else{g=!f.nextSibling;e=b(f);removeElement(f);f=r(f,g);for(g=0;g<f.length;g++){var h=f,j=g,l=f[g],o="\n";if(l.nodeType==3){select.snapshotChanged();l=makePartSpan(l);o=l.currentText;d=false}else{d&&window.opera&&e(makePartSpan(""));d=true}l.dirty=true;c.push(l);e(l);h[j]=o}return f.join("")}},nodes:c}}
function v(a){for(;a&&!isBR(a);)a=a.previousSibling;return a}function u(a,b){if(a){if(isBR(a))a=a.nextSibling}else a=b.firstChild;for(;a&&!isBR(a);)a=a.nextSibling;return a}function z(a,b,c,e){function d(h){h=cleanText(a.history.textAfter(h));return e?h.toLowerCase():h}this.editor=a;this.history=a.history;this.history.commit();this.valid=!!b;this.atOccurrence=false;if(e==undefined)e=b==b.toLowerCase();var f={node:null,offset:0};if(c&&typeof c=="object"&&typeof c.character=="number"){a.checkLine(c.line);
c={node:c.line,offset:c.character};this.pos={from:c,to:c}}else this.pos=c?{from:select.cursorPos(a.container,true)||f,to:select.cursorPos(a.container,false)||f}:{from:f,to:f};if(e)b=b.toLowerCase();var g=b.split("\n");this.matches=g.length==1?function(h,j,l){var o=d(j),m=b.length,k;if(h?l>=m&&(k=o.lastIndexOf(b,l-m))!=-1:(k=o.indexOf(b,l))!=-1)return{from:{node:j,offset:k},to:{node:j,offset:k+m}}}:function(h,j,l){var o=h?g.length-1:0,m=g[o],k=d(j),q=h?k.indexOf(m)+m.length:k.lastIndexOf(m);if(!(h?
q>=l||q!=m.length:q<=l||q!=k.length-m.length))for(l=j;;){if(h&&!l)break;l=h?this.history.nodeBefore(l):this.history.nodeAfter(l);if(!h&&!l)break;k=d(l);m=g[h?--o:++o];if(o>0&&o<g.length-1)if(k!=m)break;else continue;o=h?k.lastIndexOf(m):k.indexOf(m)+m.length;if(h?o!=k.length-m.length:o!=m.length)break;return{from:{node:h?l:j,offset:h?o:q},to:{node:h?j:l,offset:h?q:o}}}}}function s(a){this.options=a;window.indentUnit=a.indentUnit;this.parent=parent;var b=this.container=document.body;this.history=new UndoHistory(b,
a.undoDepth,a.undoDelay,this);var c=this;if(!s.Parser)throw"No parser loaded.";a.parserConfig&&s.Parser.configure&&s.Parser.configure(a.parserConfig);!a.readOnly&&!internetExplorer&&select.setCursorPos(b,{node:null,offset:0});this.dirty=[];this.importCode(a.content||"");this.history.onChange=a.onChange;if(a.readOnly){if(!a.textWrapping)b.style.whiteSpace="nowrap"}else{if(a.continuousScanning!==false){this.scanner=this.documentScanner(a.passTime);this.delayScanning()}var e=function(){if(document.body.contentEditable!=
undefined&&internetExplorer)document.body.contentEditable="true";else document.designMode="on";if(internetExplorer&&a.height!="dynamic")document.body.style.minHeight=frameElement.clientHeight-2*document.body.offsetTop-5+"px";document.documentElement.style.borderWidth="0";if(!a.textWrapping)b.style.whiteSpace="nowrap"};try{e()}catch(d){var f=addEventHandler(document,"focus",function(){f();e()},true)}addEventHandler(document,"keydown",method(this,"keyDown"));addEventHandler(document,"keypress",method(this,
"keyPress"));addEventHandler(document,"keyup",method(this,"keyUp"));var g=function(){c.cursorActivity(false)};addEventHandler(internetExplorer?document.body:window,"mouseup",g);addEventHandler(document.body,"cut",g);gecko&&addEventHandler(window,"pagehide",function(){c.unloaded=true});addEventHandler(document.body,"paste",function(h){g();var j=null;try{var l=h.clipboardData||window.clipboardData;if(l)j=l.getData("Text")}catch(o){}if(j!==null){h.stop();c.replaceSelection(j);select.scrollToCursor(c.container)}});
this.options.autoMatchParens&&addEventHandler(document.body,"click",method(this,"scheduleParenHighlight"))}}var B={P:true,DIV:true,LI:true};z.prototype={findNext:function(){return this.find(false)},findPrevious:function(){return this.find(true)},find:function(a){function b(){var g={node:d,offset:f};c.pos={from:g,to:g};return c.atOccurrence=false}if(!this.valid)return false;var c=this,e=a?this.pos.from:this.pos.to,d=e.node,f=e.offset;if(d&&!d.parentNode){d=null;f=0}for(;;){if(this.pos=this.matches(a,
d,f))return this.atOccurrence=true;if(a){if(!d)return b();d=this.history.nodeBefore(d);f=this.history.textAfter(d).length}else{e=this.history.nodeAfter(d);if(!e){f=this.history.textAfter(d).length;return b()}d=e;f=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}}};s.prototype={importCode:function(a){this.history.push(null,null,p(a));this.history.reset()},getCode:function(){if(!this.container.firstChild)return"";var a=[];select.markSelection();forEach(t(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?v(this.container.lastChild):null},nextLine:function(a){this.checkLine(a);return u(a,this.container)||false},prevLine:function(a){this.checkLine(a);if(a==null)return false;return v(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,b,c,e){this.checkLine(a);a={node:a,offset:b};b=null;if(e!==undefined){this.checkLine(c);b={node:c,offset:e}}select.setCursorPos(this.container,a,b);select.scrollToCursor(this.container)},lineContent:function(a){var b=[];for(a=a?a.nextSibling:this.container.firstChild;a&&
!isBR(a);a=a.nextSibling)b.push(nodeText(a));return cleanText(b.join(""))},setLineContent:function(a,b){this.history.commit();this.replaceRange({node:a,offset:0},{node:a,offset:this.history.textAfter(a).length},b);this.addDirtyNode(a);this.scheduleHighlight()},removeLine:function(a){for(var b=a?a.nextSibling:this.container.firstChild;b;){var c=b.nextSibling;removeElement(b);if(isBR(b))break;b=c}this.addDirtyNode(a);this.scheduleHighlight()},insertIntoLine:function(a,b,c){var e=null;if(b=="end")e=
u(a,this.container);else for(var d=a?a.nextSibling:this.container.firstChild;d;d=d.nextSibling){if(b==0){e=d;break}var f=nodeText(d);if(f.length>b){e=d.nextSibling;c=f.slice(0,b)+c+f.slice(b);removeElement(d);break}b-=f.length}b=p(c);for(c=0;c<b.length;c++){c>0&&this.container.insertBefore(document.createElement("BR"),e);this.container.insertBefore(makePartSpan(b[c]),e)}this.addDirtyNode(a);this.scheduleHighlight()},selectedText:function(){var a=this.history;a.commit();var b=select.cursorPos(this.container,
true),c=select.cursorPos(this.container,false);if(!b||!c)return"";if(b.node==c.node)return a.textAfter(b.node).slice(b.offset,c.offset);var e=[a.textAfter(b.node).slice(b.offset)];for(b=a.nodeAfter(b.node);b!=c.node;b=a.nodeAfter(b))e.push(a.textAfter(b));e.push(a.textAfter(c.node).slice(0,c.offset));return cleanText(e.join("\n"))},replaceSelection:function(a){this.history.commit();var b=select.cursorPos(this.container,true),c=select.cursorPos(this.container,false);if(b&&c){c=this.replaceRange(b,
c,a);select.setCursorPos(this.container,c);webkitLastLineHack(this.container)}},cursorCoords:function(a){function b(g,h){var j=-(document.body.scrollTop||document.documentElement.scrollTop||0),l=-(document.body.scrollLeft||document.documentElement.scrollLeft||0)+h;forEach([g,window.frameElement],function(o){for(;o;){l+=o.offsetLeft;j+=o.offsetTop;o=o.offsetParent}});return{x:l,y:j,yBot:j+g.offsetHeight}}function c(g,h){var j=document.createElement("SPAN");j.appendChild(document.createTextNode(g));
try{return h(j)}finally{j.parentNode&&j.parentNode.removeChild(j)}}var e=select.cursorPos(this.container,a);if(!e)return null;a=e.offset;for(var d=e.node,f=this;a;){d=d?d.nextSibling:this.container.firstChild;e=nodeText(d);if(a<e.length)return c(e.substr(0,a),function(g){g.style.position="absolute";g.style.visibility="hidden";g.className=d.className;f.container.appendChild(g);return b(d,g.offsetWidth)});a-=e.length}return d&&isSpan(d)?b(d,d.offsetWidth):d&&d.nextSibling&&isSpan(d.nextSibling)?b(d.nextSibling,
0):c("\u200b",function(g){d?d.parentNode.insertBefore(g,d.nextSibling):f.container.insertBefore(g,f.container.firstChild);return b(g,0)})},reroutePasteEvent:function(){if(!(this.capturingPaste||window.opera||gecko&&gecko>=20101026)){this.capturingPaste=true;var a=window.frameElement.CodeMirror.textareaHack;parent.focus();a.value="";a.focus();var b=this;this.parent.setTimeout(function(){b.capturingPaste=false;window.focus();b.selectionSnapshot&&window.select.setBookmark(b.container,b.selectionSnapshot);
var c=a.value;if(c){b.replaceSelection(c);select.scrollToCursor(b.container)}},10)}},replaceRange:function(a,b,c){c=p(c);c[0]=this.history.textAfter(a.node).slice(0,a.offset)+c[0];var e=c[c.length-1];c[c.length-1]=e+this.history.textAfter(b.node).slice(b.offset);b=this.history.nodeAfter(b.node);this.history.push(a.node,b,c);return{node:this.history.nodeBefore(b),offset:e.length}},getSearchCursor:function(a,b,c){return new z(this,a,b,c)},reindent:function(){this.container.firstChild&&this.indentRegion(null,
this.container.lastChild)},reindentSelection:function(a){if(select.somethingSelected()){var b=select.selectionTopNode(this.container,true),c=select.selectionTopNode(this.container,false);b===false||c===false||this.indentRegion(b,c,a)}else this.indentAtCursor(a)},grabKeys:function(a,b){this.frozen=a;this.keyFilter=b},ungrabKeys:function(){this.frozen="leave"},setParser:function(a,b){s.Parser=window[a];(b=b||this.options.parserConfig)&&s.Parser.configure&&s.Parser.configure(b);if(this.container.firstChild){forEach(this.container.childNodes,
function(c){if(c.nodeType!=3)c.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 b=a.keyCode;this.delayScanning();this.options.autoMatchParens&&this.scheduleParenHighlight();if(b==13){if(a.ctrlKey&&!a.altKey)this.reparseBuffer();else{select.insertNewlineAtCursor();b=this.options.enterMode;if(b!="flat")this.indentAtCursor(b==
"keep"?"keep":undefined);select.scrollToCursor(this.container)}a.stop()}else if(b==9&&this.options.tabMode!="default"&&!a.ctrlKey){this.handleTab(!a.shiftKey);a.stop()}else if(b==32&&a.shiftKey&&this.options.tabMode=="default"){this.handleTab(true);a.stop()}else if(b==36&&!a.shiftKey&&!a.ctrlKey)this.home()&&a.stop();else if(b==35&&!a.shiftKey&&!a.ctrlKey)this.end()&&a.stop();else if(b==33&&!a.shiftKey&&!a.ctrlKey&&!gecko)this.pageUp()&&a.stop();else if(b==34&&!a.shiftKey&&!a.ctrlKey&&!gecko)this.pageDown()&&
a.stop();else if((b==219||b==221)&&a.ctrlKey&&!a.altKey){this.highlightParens(a.shiftKey,true);a.stop()}else if(a.metaKey&&!a.shiftKey&&(b==37||b==39)){var c=select.selectionTopNode(this.container);if(!(c===false||!this.container.firstChild)){if(b==37)select.focusAfterNode(v(c),this.container);else{b=u(c,this.container);select.focusAfterNode(b?b.previousSibling:this.container.lastChild,this.container)}a.stop()}}else if((a.ctrlKey||a.metaKey)&&!a.altKey)if(a.shiftKey&&b==90||b==89){select.scrollToNode(this.history.redo());
a.stop()}else if(b==90||safari&&b==8){select.scrollToNode(this.history.undo());a.stop()}else if(b==83&&this.options.saveFunction){this.options.saveFunction();a.stop()}else b==86&&!mac&&this.reroutePasteEvent()}},keyPress:function(a){var b=this.options.electricChars&&s.Parser.electricChars,c=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(b&&b.indexOf(a.character)!=-1)this.parent.setTimeout(function(){c.indentAtCursor(null)},0);else if(brokenOpera)if(a.code==8){var e=select.selectionTopNode(this.container);c=this;var d=e?e.nextSibling:this.container.firstChild;e!==false&&d&&isBR(d)&&this.parent.setTimeout(function(){select.selectionTopNode(c.container)==d&&select.focusAfterNode(d.previousSibling,c.container)},20)}else{if(a.code==46){e=select.selectionTopNode(this.container);
c=this;e&&isBR(e)&&this.parent.setTimeout(function(){select.selectionTopNode(c.container)!=e&&select.focusAfterNode(e,c.container)},20)}}else if(slowWebkit){d=(e=select.selectionTopNode(this.container))?e.nextSibling:this.container.firstChild;if(e&&d&&isBR(d)&&!isBR(e)){var f=document.createTextNode("\u200b");this.container.insertBefore(f,d);this.parent.setTimeout(function(){if(f.nodeValue=="\u200b")removeElement(f);else f.nodeValue=f.nodeValue.replace("\u200b","")},20)}}webkit&&!this.options.textWrapping&&
setTimeout(function(){var g=select.selectionTopNode(c.container,true);g&&g.nodeType==3&&g.previousSibling&&isBR(g.previousSibling)&&g.nextSibling&&isBR(g.nextSibling)&&g.parentNode.replaceChild(document.createElement("BR"),g.previousSibling)},50)},keyUp:function(a){this.cursorActivity(a.keyCode>=16&&a.keyCode<=18||a.keyCode>=33&&a.keyCode<=40)},indentLineAfter:function(a,b){function c(l){l=l?l.nextSibling:e.container.firstChild;if(!l||!hasClass(l,"whitespace"))return null;return l}var e=this,d=c(a),
f=0,g=d?d.currentText.length:0,h=d?d.nextSibling:a?a.nextSibling:this.container.firstChild;if(b=="keep"){if(a){var j=c(v(a.previousSibling));if(j)f=j.currentText.length}}else{j=a&&h&&h.currentText?h.currentText:"";if(b!=null&&this.options.tabMode=="shift")f=b?g+indentUnit:Math.max(0,g-indentUnit);else if(a)f=a.indentation(j,g,b);else if(s.Parser.firstIndentation)f=s.Parser.firstIndentation(j,g,b)}g=f-g;if(g<0)if(f==0){if(h)select.snapshotMove(d.firstChild,h.firstChild||h,0);removeElement(d);d=null}else{select.snapshotMove(d.firstChild,
d.firstChild,g,true);d.currentText=makeWhiteSpace(f);d.firstChild.nodeValue=d.currentText}else if(g>0)if(d){d.currentText=makeWhiteSpace(f);d.firstChild.nodeValue=d.currentText;select.snapshotMove(d.firstChild,d.firstChild,g,true)}else{d=makePartSpan(makeWhiteSpace(f));d.className="whitespace";a?insertAfter(d,a):this.container.insertBefore(d,this.container.firstChild);select.snapshotMove(h&&(h.firstChild||h),d.firstChild,f,false,true)}else d&&select.snapshotMove(d.firstChild,d.firstChild,f,false);
g!=0&&this.addDirtyNode(a)},highlightAtCursor:function(){var a=select.selectionTopNode(this.container,true),b=select.selectionTopNode(this.container,false);if(a===false||b===false)return false;select.markSelection();if(this.highlight(a,u(b,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),b=a;if(a===
false||!(!a||a.isPart||isBR(a))||!this.container.firstChild)return false;for(;a&&!isBR(a);)a=a.previousSibling;var c=a?a.nextSibling:this.container.firstChild;c&&c!=b&&c.isPart&&hasClass(c,"whitespace")?select.focusAfterNode(c,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=u(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,b=this.visibleLineCount();if(a===false||b===false)return false;b-=2;for(var c=0;c<b;c++){a=this.prevLine(a);if(a===false)break}if(c==0)return false;select.setCursorPos(this.container,{node:a,offset:0});select.scrollToCursor(this.container);return true},pageDown:function(){var a=this.cursorPosition().line,b=this.visibleLineCount();if(a===false||b===false)return false;b-=2;for(var c=
0;c<b;c++){var e=this.nextLine(a);if(e===false)break;a=e}if(c==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,b){function c(k,q){if(k)if(g.options.markParen)g.options.markParen(k,q);else{k.style.fontWeight="bold";k.style.color=
q?"#8F8":"#F88"}}function e(k){if(k)if(g.options.unmarkParen)g.options.unmarkParen(k);else{k.style.fontWeight="";k.style.color=""}}function d(k){if(k.currentText)return(k=k.currentText.match(/^[\s\u00a0]*([\(\)\[\]{}])[\s\u00a0]*$/))&&k[1]}function f(){for(var k=[],q,w=true,i=j;i;i=o?i.nextSibling:i.previousSibling)if(i.className==l&&isSpan(i)&&(q=d(i))){if(/[\(\[\{]/.test(q)==o)k.push(q);else if(k.length){if(k.pop()!=matching[q])w=false}else w=false;if(!k.length)break}else if(i.dirty||!isSpan(i)&&
!isBR(i))return{node:i,status:"dirty"};return{node:i,status:i&&w}}var g=this;if(!b&&g.highlighted){e(g.highlighted[0]);e(g.highlighted[1])}if(!(!window||!window.parent||!window.select)){this.parenEvent&&this.parent.clearTimeout(this.parenEvent);this.parenEvent=null;var h,j=select.selectionTopNode(this.container,true);if(j&&this.highlightAtCursor())if((j=select.selectionTopNode(this.container,true))&&((h=d(j))||(j=j.nextSibling)&&(h=d(j))))for(var l=j.className,o=/[\(\[\{]/.test(h);;){var m=f();if(m.status==
"dirty"){this.highlight(m.node,u(m.node));m.node.dirty=false}else{c(j,m.status);c(m.node,m.status);if(b)g.parent.setTimeout(function(){e(j);e(m.node)},500);else g.highlighted=[j,m.node];a&&m.node&&select.focusAfterNode(m.node.previousSibling,this.container);break}}}},indentAtCursor:function(a){if(this.container.firstChild)if(this.highlightAtCursor()){var b=select.selectionTopNode(this.container,false);if(b!==false){select.markSelection();this.indentLineAfter(v(b),a);select.selectMarked()}}},indentRegion:function(a,
b,c){var e=a=v(a),d=a&&v(a.previousSibling);isBR(b)||(b=u(b,this.container));this.addDirtyNode(a);do{var f=u(e,this.container);e&&this.highlight(d,f,true);this.indentLineAfter(e,c);d=e;e=f}while(e!=b);select.setCursorPos(this.container,{node:a,offset:0},{node:b,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 b=this;this.saveSelectionSnapshot=setTimeout(function(){var d=select.getBookmark(b.container);if(d)b.selectionSnapshot=d},200)}var c=this.options.cursorActivity;if(!a||c){var e=select.selectionTopNode(this.container,false);if(!(e===false||!this.container.firstChild)){e=e||this.container.firstChild;c&&c(e);if(!a){this.scheduleHighlight();this.addDirtyNode(e)}}}},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 b=0;b<this.dirty.length;b++)if(this.dirty[b]==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(b){}}return null},highlightDirty:function(a){if(!window||!window.parent||!window.select)return false;this.options.readOnly||select.markSelection();for(var b,c=a?null:(new Date).getTime()+this.options.passTime;((new Date).getTime()<c||a)&&(b=this.getDirtyNode());){var e=this.highlight(b,c);e&&e.node&&e.dirty&&this.addDirtyNode(e.node.nextSibling)}this.options.readOnly||select.selectMarked();b&&this.scheduleHighlight();return this.dirty.length==
0},documentScanner:function(a){var b=this,c=null;return function(){if(!(!window||!window.parent||!window.select)){if(c&&c.parentNode!=b.container)c=null;select.markSelection();var e=b.highlight(c,(new Date).getTime()+a,true);select.selectMarked();e=e?e.node&&e.node.nextSibling:null;c=c==e?null:e;b.delayScanning()}}},delayScanning:function(){if(this.scanner){this.parent.clearTimeout(this.documentScan);this.documentScan=this.parent.setTimeout(this.scanner,this.options.continuousScanning)}},highlight:function(a,
b,c,e){function d(i){if(i){var n=i.oldNextSibling;if(k||n===undefined||i.nextSibling!=n)g.history.touch(i);i.oldNextSibling=i.nextSibling}else{n=g.container.oldFirstChild;if(k||n===undefined||g.container.firstChild!=n)g.history.touch(null);g.container.oldFirstChild=g.container.firstChild}}var f=this.container,g=this,h=this.options.activeTokens,j=typeof b=="number"?b:null;if(!f.firstChild)return false;for(;a&&(!a.parserFromHere||a.dirty);){if(e!=null&&isBR(a)&&--e<0)return false;a=a.previousSibling}if(a&&
!a.nextSibling)return false;var l=t(a?a.nextSibling:f.firstChild);e=stringStream(l);var o=a?a.parserFromHere(e):s.Parser.make(e),m={current:null,get:function(){if(!this.current)this.current=l.nodes.shift();return this.current},next:function(){this.current=null},remove:function(){f.removeChild(this.get());this.current=null},getNonEmpty:function(){for(var i=this.get();i&&isSpan(i)&&i.currentText=="";)if(window.opera&&(i.previousSibling==null||isBR(i.previousSibling))&&(i.nextSibling==null||isBR(i.nextSibling))){this.next();
i=this.get()}else{var n=i;this.remove();i=this.get();select.snapshotMove(n.firstChild,i&&(i.firstChild||i),0)}return i}},k=false,q=true,w=0;forEach(o,function(i){var n=m.getNonEmpty();if(i.value=="\n"){if(!isBR(n))throw"Parser out of sync. Expected BR.";if(n.dirty||!n.indentation)k=true;d(a);a=n;n.parserFromHere=o.copy();n.indentation=i.indentation||alwaysZero;n.dirty=false;if(j==null&&n==b)throw StopIteration;if(j!=null&&(new Date).getTime()>=j||!k&&!q&&w>1&&!c)throw StopIteration;q=k;k=false;w=
0;m.next()}else{if(!isSpan(n))throw"Parser out of sync. Expected SPAN.";if(n.dirty)k=true;w++;if(!n.reduced&&n.currentText==i.value&&n.className==i.style){n.dirty=false;m.next()}else{k=true;var x=makePartSpan(i.value);x.className=i.style;f.insertBefore(x,n);h&&h(x,i,g);i=i.value.length;for(var A=0;i>0;){n=m.get();var y=n.currentText.length;select.snapshotReplaceNode(n.firstChild,x.firstChild,i,A);if(y>i){n=n;n.currentText=n.currentText.substring(i);n.reduced=true;i=0}else{i-=y;A+=y;m.remove()}}}}});
d(a);webkitLastLineHack(this.container);return{node:m.getNonEmpty(),dirty:k}}};return s}();addEventHandler(window,"load",function(){var p=window.frameElement.CodeMirror;p.editor=new Editor(p.options);this.parent.setTimeout(method(p,"init"),0)});