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