summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/addon/search
diff options
context:
space:
mode:
Diffstat (limited to 'public/vendor/codemirror/addon/search')
-rw-r--r--public/vendor/codemirror/addon/search/match-highlighter.js49
1 files changed, 23 insertions, 26 deletions
diff --git a/public/vendor/codemirror/addon/search/match-highlighter.js b/public/vendor/codemirror/addon/search/match-highlighter.js
index 79218c31..2c2914a9 100644
--- a/public/vendor/codemirror/addon/search/match-highlighter.js
+++ b/public/vendor/codemirror/addon/search/match-highlighter.js
@@ -29,24 +29,20 @@
})(function(CodeMirror) {
"use strict";
- var DEFAULT_MIN_CHARS = 2;
- var DEFAULT_TOKEN_STYLE = "matchhighlight";
- var DEFAULT_DELAY = 100;
- var DEFAULT_WORDS_ONLY = false;
+ var defaults = {
+ style: "matchhighlight",
+ minChars: 2,
+ delay: 100,
+ wordsOnly: false,
+ annotateScrollbar: false,
+ showToken: false,
+ trim: true
+ }
function State(options) {
- if (typeof options == "object") {
- this.minChars = options.minChars;
- this.style = options.style;
- this.showToken = options.showToken;
- this.delay = options.delay;
- this.wordsOnly = options.wordsOnly;
- this.annotateScrollbar = options.annotateScrollbar;
- }
- if (this.style == null) this.style = DEFAULT_TOKEN_STYLE;
- if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS;
- if (this.delay == null) this.delay = DEFAULT_DELAY;
- if (this.wordsOnly == null) this.wordsOnly = DEFAULT_WORDS_ONLY;
+ this.options = {}
+ for (var name in defaults)
+ this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name]
this.overlay = this.timeout = null;
this.matchesonscroll = null;
}
@@ -68,13 +64,13 @@
function cursorActivity(cm) {
var state = cm.state.matchHighlighter;
clearTimeout(state.timeout);
- state.timeout = setTimeout(function() {highlightMatches(cm);}, state.delay);
+ state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay);
}
function addOverlay(cm, query, hasBoundary, style) {
var state = cm.state.matchHighlighter;
cm.addOverlay(state.overlay = makeOverlay(query, hasBoundary, style));
- if (state.annotateScrollbar) {
+ if (state.options.annotateScrollbar && cm.showMatchesOnScrollbar) {
var searchFor = hasBoundary ? new RegExp("\\b" + query + "\\b") : query;
state.matchesonscroll = cm.showMatchesOnScrollbar(searchFor, true,
{className: "CodeMirror-selection-highlight-scrollbar"});
@@ -86,7 +82,7 @@
if (state.overlay) {
cm.removeOverlay(state.overlay);
state.overlay = null;
- if (state.annotateScrollbar) {
+ if (state.matchesonscroll) {
state.matchesonscroll.clear();
state.matchesonscroll = null;
}
@@ -97,21 +93,22 @@
cm.operation(function() {
var state = cm.state.matchHighlighter;
removeOverlay(cm);
- if (!cm.somethingSelected() && state.showToken) {
- var re = state.showToken === true ? /[\w$]/ : state.showToken;
+ if (!cm.somethingSelected() && state.options.showToken) {
+ var re = state.options.showToken === true ? /[\w$]/ : state.options.showToken;
var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;
while (start && re.test(line.charAt(start - 1))) --start;
while (end < line.length && re.test(line.charAt(end))) ++end;
if (start < end)
- addOverlay(cm, line.slice(start, end), re, state.style);
+ addOverlay(cm, line.slice(start, end), re, state.options.style);
return;
}
var from = cm.getCursor("from"), to = cm.getCursor("to");
if (from.line != to.line) return;
- if (state.wordsOnly && !isWord(cm, from, to)) return;
- var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, "");
- if (selection.length >= state.minChars)
- addOverlay(cm, selection, false, state.style);
+ if (state.options.wordsOnly && !isWord(cm, from, to)) return;
+ var selection = cm.getRange(from, to)
+ if (state.options.trim) selection = selection.replace(/^\s+|\s+$/g, "")
+ if (selection.length >= state.options.minChars)
+ addOverlay(cm, selection, false, state.options.style);
});
}