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