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