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