!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("./matchesonscrollbar")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./matchesonscrollbar"],t):t(CodeMirror)}(function(n){"use strict";var o={style:"matchhighlight",minChars:2,delay:100,wordsOnly:!1,annotateScrollbar:!1,showToken:!1,trim:!0};function r(t){for(var e in this.options={},o)this.options[e]=(t&&t.hasOwnProperty(e)?t:o)[e];this.overlay=this.timeout=null,this.matchesonscroll=null,this.active=!1}function a(t){var e=t.state.matchHighlighter;(e.active||t.hasFocus())&&i(t,e)}function s(t){var e=t.state.matchHighlighter;e.active||(e.active=!0,i(t,e))}function i(t,e){clearTimeout(e.timeout),e.timeout=setTimeout(function(){c(t)},e.options.delay)}function h(t,e,o,i){var n=t.state.matchHighlighter;if(t.addOverlay(n.overlay=function(e,o,i){return{token:function(t){if(t.match(e)&&(!o||function(t,e){return!(t.start&&e.test(t.string.charAt(t.start-1))||t.pos!=t.string.length&&e.test(t.string.charAt(t.pos)))}(t,o)))return i;t.next(),t.skipTo(e.charAt(0))||t.skipToEnd()}}}(e,o,i)),n.options.annotateScrollbar&&t.showMatchesOnScrollbar){var r=o?new RegExp("\\b"+e.replace(/[\\\[.+*?(){|^$]/g,"\\$&")+"\\b"):e;n.matchesonscroll=t.showMatchesOnScrollbar(r,!1,{className:"CodeMirror-selection-highlight-scrollbar"})}}function u(t){var e=t.state.matchHighlighter;e.overlay&&(t.removeOverlay(e.overlay),e.overlay=null,e.matchesonscroll&&(e.matchesonscroll.clear(),e.matchesonscroll=null))}function c(l){l.operation(function(){var t=l.state.matchHighlighter;if(u(l),l.somethingSelected()||!t.options.showToken){var e=l.getCursor("from"),o=l.getCursor("to");if(e.line==o.line&&(!t.options.wordsOnly||function(t,e,o){{if(null===t.getRange(e,o).match(/^\w+$/))return!1;if(0<e.ch){var i={line:e.line,ch:e.ch-1};if(null===t.getRange(i,e).match(/\W/))return!1}if(o.ch<t.getLine(e.line).length){i={line:o.line,ch:o.ch+1};if(null===t.getRange(o,i).match(/\W/))return!1}return!0}}(l,e,o))){var i=l.getRange(e,o);t.options.trim&&(i=i.replace(/^\s+|\s+$/g,"")),i.length>=t.options.minChars&&h(l,i,!1,t.options.style)}}else{for(var n=!0===t.options.showToken?/[\w$]/:t.options.showToken,r=l.getCursor(),a=l.getLine(r.line),s=r.ch,c=s;s&&n.test(a.charAt(s-1));)--s;for(;c<a.length&&n.test(a.charAt(c));)++c;s<c&&h(l,a.slice(s,c),n,t.options.style)}})}n.defineOption("highlightSelectionMatches",!1,function(t,e,o){if(o&&o!=n.Init&&(u(t),clearTimeout(t.state.matchHighlighter.timeout),t.state.matchHighlighter=null,t.off("cursorActivity",a),t.off("focus",s)),e){var i=t.state.matchHighlighter=new r(e);t.hasFocus()?(i.active=!0,c(t)):t.on("focus",s),t.on("cursorActivity",a)}})});