'use strict';(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 q(a,c,b){var k=a.getLineHandle(c.line),d=c.ch-1,g=b&&b.afterCursor;null==g&&(g=/(^| )cm-fat-cursor($| )/.test(a.getWrapperElement().className));var h=b&&b.bracketRegex||/[(){}[\]]/;k=!g&&0<=d&&h.test(k.text.charAt(d))&&t[k.text.charAt(d)]||h.test(k.text.charAt(d+1))&&t[k.text.charAt(++d)];
if(!k)return null;g=">"==k.charAt(1)?1:-1;if(b&&b.strict&&0<g!=(d==c.ch))return null;h=a.getTokenTypeAt(m(c.line,d+1));a=l(a,m(c.line,d+(0<g?1:0)),g,h||null,b);return null==a?null:{from:m(c.line,d),to:a&&a.pos,match:a&&a.ch==k.charAt(0),forward:0<g}}function l(a,c,b,k,d){var g=d&&d.maxScanLineLength||1E4,h=d&&d.maxScanLines||1E3,f=[];d=d&&d.bracketRegex||/[(){}[\]]/;h=0<b?Math.min(c.line+h,a.lastLine()+1):Math.max(a.firstLine()-1,c.line-h);for(var e=c.line;e!=h;e+=b){var p=a.getLine(e);if(p){var n=
0<b?0:p.length-1,q=0<b?p.length:-1;if(!(p.length>g))for(e==c.line&&(n=c.ch-(0>b?1:0));n!=q;n+=b){var r=p.charAt(n);if(d.test(r)&&(void 0===k||a.getTokenTypeAt(m(e,n+1))==k)){var l=t[r];if(l&&">"==l.charAt(1)==0<b)f.push(r);else if(f.length)f.pop();else return{pos:m(e,n),ch:r}}}}}return e-b==(0<b?a.lastLine():a.firstLine())?!1:null}function u(a,c,b){for(var e=a.state.matchBrackets.maxHighlightLineLength||1E3,d=[],g=a.listSelections(),h=0;h<g.length;h++){var f=g[h].empty()&&q(a,g[h].head,b);if(f&&a.getLine(f.from.line).length<=
e){var l=f.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket";d.push(a.markText(f.from,m(f.from.line,f.from.ch+1),{className:l}));f.to&&a.getLine(f.to.line).length<=e&&d.push(a.markText(f.to,m(f.to.line,f.to.ch+1),{className:l}))}}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(){a.state.matchBrackets.currentlyHighlighted&&(a.state.matchBrackets.currentlyHighlighted(),
a.state.matchBrackets.currentlyHighlighted=null);a.state.matchBrackets.currentlyHighlighted=u(a,!1,a.state.matchBrackets)})}var w=/MSIE \d/.test(navigator.userAgent)&&(null==document.documentMode||8>document.documentMode),m=e.Pos,t={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<","<":">>",">":"<<"};e.defineOption("matchBrackets",!1,function(a,c,b){b&&b!=e.Init&&(a.off("cursorActivity",v),a.state.matchBrackets&&a.state.matchBrackets.currentlyHighlighted&&(a.state.matchBrackets.currentlyHighlighted(),
a.state.matchBrackets.currentlyHighlighted=null));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){if(b||"boolean"==typeof c)b?(b.strict=c,c=b):c=c?{strict:!0}:null;return q(this,a,c)});e.defineExtension("scanForBracket",function(a,c,b,e){return l(this,a,c,b,e)})});
