From 795ea21191486a80437d7c535defc503962c5968 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:15:29 +0800 Subject: Update CodeMirror to 5.19.0 and rename jade to pug --- .../codemirror/addon/search/match-highlighter.js | 23 ++++++++++++++++++++-- public/vendor/codemirror/addon/search/search.js | 9 ++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'public/vendor/codemirror/addon/search') diff --git a/public/vendor/codemirror/addon/search/match-highlighter.js b/public/vendor/codemirror/addon/search/match-highlighter.js index 2121de41..73ba0e05 100644 --- a/public/vendor/codemirror/addon/search/match-highlighter.js +++ b/public/vendor/codemirror/addon/search/match-highlighter.js @@ -45,6 +45,7 @@ this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name] this.overlay = this.timeout = null; this.matchesonscroll = null; + this.active = false; } CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) { @@ -53,16 +54,34 @@ clearTimeout(cm.state.matchHighlighter.timeout); cm.state.matchHighlighter = null; cm.off("cursorActivity", cursorActivity); + cm.off("focus", onFocus) } if (val) { - cm.state.matchHighlighter = new State(val); - highlightMatches(cm); + var state = cm.state.matchHighlighter = new State(val); + if (cm.hasFocus()) { + state.active = true + highlightMatches(cm) + } else { + cm.on("focus", onFocus) + } cm.on("cursorActivity", cursorActivity); } }); function cursorActivity(cm) { 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); state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay); } diff --git a/public/vendor/codemirror/addon/search/search.js b/public/vendor/codemirror/addon/search/search.js index c005866f..753b1afe 100644 --- a/public/vendor/codemirror/addon/search/search.js +++ b/public/vendor/codemirror/addon/search/search.js @@ -136,8 +136,11 @@ }) }; persistentDialog(cm, queryDialog, q, searchNext, function(event, query) { - var cmd = CodeMirror.keyMap[cm.getOption("keyMap")][CodeMirror.keyName(event)]; - if (cmd == "findNext" || cmd == "findPrev") { + var keyName = CodeMirror.keyName(event) + var cmd = CodeMirror.keyMap[cm.getOption("keyMap")][keyName] + if (!cmd) cmd = cm.getOption('extraKeys')[keyName] + if (cmd == "findNext" || cmd == "findPrev" || + cmd == "findPersistentNext" || cmd == "findPersistentPrev") { CodeMirror.e_stop(event); startSearch(cm, getSearchState(cm), query); cm.execCommand(cmd); @@ -146,7 +149,7 @@ searchNext(query, event); } }); - if (immediate) { + if (immediate && q) { startSearch(cm, state, q); findNext(cm, rev); } -- cgit v1.2.3