(function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)})(function(e){function s(a,c,b,e){var d=a.getLineHandle(c.line),h=c.ch-1,d=0<=h&&r[d.text.charAt(h)]||r[d.text.charAt(++h)];if(!d)return null;var g=">"==d.charAt(1)?1:-1;if(b&&0<g!=(h==c.ch))return null;b=a.getTokenTypeAt(l(c.line,h+1));a=t(a,l(c.line,h+(0<g?1:0)),g,b||null,e);return null==a?null:{from:l(c.line,h),
to:a&&a.pos,match:a&&a.ch==d.charAt(0),forward:0<g}}function t(a,c,b,e,d){var h=d&&d.maxScanLineLength||1E4,g=d&&d.maxScanLines||1E3,f=[];d=d&&d.bracketRegex?d.bracketRegex:/[(){}[\]]/;for(var g=0<b?Math.min(c.line+g,a.lastLine()+1):Math.max(a.firstLine()-1,c.line-g),k=c.line;k!=g;k+=b){var p=a.getLine(k);if(p){var m=0<b?0:p.length-1,n=0<b?p.length:-1;if(!(p.length>h))for(k==c.line&&(m=c.ch-(0>b?1:0));m!=n;m+=b){var q=p.charAt(m);if(d.test(q)&&(void 0===e||a.getTokenTypeAt(l(k,m+1))==e))if(">"==r[q].charAt(1)==
0<b)f.push(q);else if(f.length)f.pop();else return{pos:l(k,m),ch:q}}}}return k-b==(0<b?a.lastLine():a.firstLine())?!1:null}function u(a,c,b){for(var e=a.state.matchBrackets.maxHighlightLineLength||1E3,d=[],h=a.listSelections(),g=0;g<h.length;g++){var f=h[g].empty()&&s(a,h[g].head,!1,b);if(f&&a.getLine(f.from.line).length<=e){var k=f.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket";d.push(a.markText(f.from,l(f.from.line,f.from.ch+1),{className:k}));f.to&&a.getLine(f.to.line).length<=
e&&d.push(a.markText(f.to,l(f.to.line,f.to.ch+1),{className:k}))}}if(d.length)if(w&&a.state.focused&&a.focus(),b=function(){a.operation(function(){for(var a=0;a<d.length;a++)d[a].clear()})},c)setTimeout(b,800);else return b}function v(a){a.operation(function(){n&&(n(),n=null);n=u(a,!1,a.state.matchBrackets)})}var w=/MSIE \d/.test(navigator.userAgent)&&(null==document.documentMode||8>document.documentMode),l=e.Pos,r={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},n=null;e.defineOption("matchBrackets",
!1,function(a,c,b){b&&b!=e.Init&&a.off("cursorActivity",v);c&&(a.state.matchBrackets="object"==typeof c?c:{},a.on("cursorActivity",v))});e.defineExtension("matchBrackets",function(){u(this,!0)});e.defineExtension("findMatchingBracket",function(a,c,b){return s(this,a,c,b)});e.defineExtension("scanForBracket",function(a,c,b,e){return t(this,a,c,b,e)})});
