(function(a){if(typeof exports=="object"&&typeof module=="object"){a(require("../../lib/codemirror"),require("../fold/xml-fold"))}else{if(typeof define=="function"&&define.amd){define(["../../lib/codemirror","../fold/xml-fold"],a)}else{a(CodeMirror)}}})(function(c){c.defineOption("matchTags",false,function(e,g,f){if(f&&f!=c.Init){e.off("cursorActivity",b);e.off("viewportChange",d);a(e)}if(g){e.state.matchBothTags=typeof g=="object"&&g.bothTags;e.on("cursorActivity",b);e.on("viewportChange",d);b(e)}});function a(e){if(e.state.tagHit){e.state.tagHit.clear()}if(e.state.tagOther){e.state.tagOther.clear()}e.state.tagHit=e.state.tagOther=null}function b(e){e.state.failedTagMatch=false;e.operation(function(){a(e);if(e.somethingSelected()){return}var j=e.getCursor(),g=e.getViewport();g.from=Math.min(g.from,j.line);g.to=Math.max(j.line+1,g.to);var h=c.findMatchingTag(e,j,g);if(!h){return}if(e.state.matchBothTags){var i=h.at=="open"?h.open:h.close;if(i){e.state.tagHit=e.markText(i.from,i.to,{className:"CodeMirror-matchingtag"})}}var f=h.at=="close"?h.open:h.close;if(f){e.state.tagOther=e.markText(f.from,f.to,{className:"CodeMirror-matchingtag"})}else{e.state.failedTagMatch=true}})}function d(e){if(e.state.failedTagMatch){b(e)}}c.commands.toMatchingTag=function(f){var g=c.findMatchingTag(f,f.getCursor());if(g){var e=g.at=="close"?g.open:g.close;if(e){f.extendSelection(e.to,e.from)}}}});(function(a){if(typeof exports=="object"&&typeof module=="object"){a(require("../../lib/codemirror"))}else{if(typeof define=="function"&&define.amd){define(["../../lib/codemirror"],a)}else{a(CodeMirror)}}})(function(e){var d=/MSIE \d/.test(navigator.userAgent)&&(document.documentMode==null||document.documentMode<8);var i=e.Pos;var a={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"};function f(q,m,p,k){var s=q.getLineHandle(m.line),o=m.ch-1;var n=(o>=0&&a[s.text.charAt(o)])||a[s.text.charAt(++o)];if(!n){return null}var l=n.charAt(1)==">"?1:-1;if(p&&(l>0)!=(o==m.ch)){return null}var j=q.getTokenTypeAt(i(m.line,o+1));var r=g(q,i(m.line,o+(l>0?1:0)),l,j||null,k);if(r==null){return null}return{from:i(m.line,o),to:r&&r.pos,match:r&&r.ch==n.charAt(0),forward:l>0}}function g(w,r,n,k,m){var l=(m&&m.maxScanLineLength)||10000;var t=(m&&m.maxScanLines)||1000;var v=[];var x=m&&m.bracketRegex?m.bracketRegex:/[(){}[\]]/;var q=n>0?Math.min(r.line+t,w.lastLine()+1):Math.max(w.firstLine()-1,r.line-t);for(var o=r.line;o!=q;o+=n){var y=w.getLine(o);if(!y){continue}var u=n>0?0:y.length-1,p=n>0?y.length:-1;if(y.length>l){continue}if(o==r.line){u=r.ch-(n<0?1:0)}for(;u!=p;u+=n){var j=y.charAt(u);if(x.test(j)&&(k===undefined||w.getTokenTypeAt(i(o,u+1))==k)){var s=a[j];if((s.charAt(1)==">")==(n>0)){v.push(j)}else{if(!v.length){return{pos:i(o,u),ch:j}}else{v.pop()}}}}}return o-n==(n>0?w.lastLine():w.firstLine())?false:null}function b(s,n,m){var k=s.state.matchBrackets.maxHighlightLineLength||1000;var r=[],l=s.listSelections();for(var o=0;o<l.length;o++){var q=l[o].empty()&&f(s,l[o].head,false,m);if(q&&s.getLine(q.from.line).length<=k){var j=q.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket";r.push(s.markText(q.from,i(q.from.line,q.from.ch+1),{className:j}));if(q.to&&s.getLine(q.to.line).length<=k){r.push(s.markText(q.to,i(q.to.line,q.to.ch+1),{className:j}))}}}if(r.length){if(d&&s.state.focused){s.focus()}var p=function(){s.operation(function(){for(var t=0;t<r.length;t++){r[t].clear()}})};if(n){setTimeout(p,800)}else{return p}}}var c=null;function h(j){j.operation(function(){if(c){c();c=null}c=b(j,false,j.state.matchBrackets)})}e.defineOption("matchBrackets",false,function(j,l,k){if(k&&k!=e.Init){j.off("cursorActivity",h);if(c){c();c=null}}if(l){j.state.matchBrackets=typeof l=="object"?l:{};j.on("cursorActivity",h)}});e.defineExtension("matchBrackets",function(){b(this,true)});e.defineExtension("findMatchingBracket",function(l,j,k){return f(this,l,j,k)});e.defineExtension("scanForBracket",function(m,k,l,j){return g(this,m,k,l,j)})});