Skip to content
Snippets Groups Projects
Commit a2b3204e authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[match-highlighter addon] Don't start highlighting until the editor is focused

Issue #4162
parent fafb7dc1
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name] this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name]
this.overlay = this.timeout = null; this.overlay = this.timeout = null;
this.matchesonscroll = null; this.matchesonscroll = null;
this.active = false;
} }
CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) { CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) {
...@@ -53,16 +54,34 @@ ...@@ -53,16 +54,34 @@
clearTimeout(cm.state.matchHighlighter.timeout); clearTimeout(cm.state.matchHighlighter.timeout);
cm.state.matchHighlighter = null; cm.state.matchHighlighter = null;
cm.off("cursorActivity", cursorActivity); cm.off("cursorActivity", cursorActivity);
cm.off("focus", onFocus)
} }
if (val) { if (val) {
cm.state.matchHighlighter = new State(val); var state = cm.state.matchHighlighter = new State(val);
highlightMatches(cm); if (cm.hasFocus()) {
state.active = true
highlightMatches(cm)
} else {
cm.on("focus", onFocus)
}
cm.on("cursorActivity", cursorActivity); cm.on("cursorActivity", cursorActivity);
} }
}); });
function cursorActivity(cm) { function cursorActivity(cm) {
var state = cm.state.matchHighlighter; var state = cm.state.matchHighlighter;
if (state.active || cm.hasFocus()) scheduleHighlight(cm, state)
}
function onFocus(cm) {
var state = cm.state.matchHighlighter
if (!state.active) {
state.active = true
scheduleHighlight(cm, state)
}
}
function scheduleHighlight(cm, state) {
clearTimeout(state.timeout); clearTimeout(state.timeout);
state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay); state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment