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 --- public/vendor/codemirror/addon/comment/comment.js | 13 +++++++----- public/vendor/codemirror/addon/fold/xml-fold.js | 4 ++-- .../codemirror/addon/hint/javascript-hint.js | 11 ++++++++++- .../codemirror/addon/search/match-highlighter.js | 23 ++++++++++++++++++++-- public/vendor/codemirror/addon/search/search.js | 9 ++++++--- 5 files changed, 47 insertions(+), 13 deletions(-) (limited to 'public/vendor/codemirror/addon') diff --git a/public/vendor/codemirror/addon/comment/comment.js b/public/vendor/codemirror/addon/comment/comment.js index 2c4f975d..d71cf436 100644 --- a/public/vendor/codemirror/addon/comment/comment.js +++ b/public/vendor/codemirror/addon/comment/comment.js @@ -103,6 +103,7 @@ self.lineComment(from, to, options); return; } + if (/\bcomment\b/.test(self.getTokenTypeAt(Pos(from.line, 0)))) return var end = Math.min(to.line, self.lastLine()); if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end; @@ -140,7 +141,7 @@ var line = self.getLine(i); var found = line.indexOf(lineString); if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1; - if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment; + if (found == -1 && nonWS.test(line)) break lineComment; if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment; lines.push(line); } @@ -162,13 +163,15 @@ var endString = options.blockCommentEnd || mode.blockCommentEnd; if (!startString || !endString) return false; var lead = options.blockCommentLead || mode.blockCommentLead; - var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end); - var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString); + var startLine = self.getLine(start), open = startLine.indexOf(startString) + if (open == -1) return false + var endLine = end == start ? startLine : self.getLine(end) + var close = endLine.indexOf(endString, end == start ? open + startString.length : 0); if (close == -1 && start != end) { endLine = self.getLine(--end); - close = endLine.lastIndexOf(endString); + close = endLine.indexOf(endString); } - if (open == -1 || close == -1 || + if (close == -1 || !/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) || !/comment/.test(self.getTokenTypeAt(Pos(end, close + 1)))) return false; diff --git a/public/vendor/codemirror/addon/fold/xml-fold.js b/public/vendor/codemirror/addon/fold/xml-fold.js index f8c67b89..75a9e305 100644 --- a/public/vendor/codemirror/addon/fold/xml-fold.js +++ b/public/vendor/codemirror/addon/fold/xml-fold.js @@ -21,8 +21,8 @@ function Iter(cm, line, ch, range) { this.line = line; this.ch = ch; this.cm = cm; this.text = cm.getLine(line); - this.min = range ? range.from : cm.firstLine(); - this.max = range ? range.to - 1 : cm.lastLine(); + this.min = range ? Math.max(range.from, cm.firstLine()) : cm.firstLine(); + this.max = range ? Math.min(range.to - 1, cm.lastLine()) : cm.lastLine(); } function tagAt(iter, ch) { diff --git a/public/vendor/codemirror/addon/hint/javascript-hint.js b/public/vendor/codemirror/addon/hint/javascript-hint.js index 7bcbf4a0..d7088c19 100644 --- a/public/vendor/codemirror/addon/hint/javascript-hint.js +++ b/public/vendor/codemirror/addon/hint/javascript-hint.js @@ -97,6 +97,15 @@ var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " + "if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" "); + function forAllProps(obj, callback) { + if (!Object.getOwnPropertyNames || !Object.getPrototypeOf) { + for (var name in obj) callback(name) + } else { + for (var o = obj; o; o = Object.getPrototypeOf(o)) + Object.getOwnPropertyNames(o).forEach(callback) + } + } + function getCompletions(token, context, keywords, options) { var found = [], start = token.string, global = options && options.globalScope || window; function maybeAdd(str) { @@ -106,7 +115,7 @@ if (typeof obj == "string") forEach(stringProps, maybeAdd); else if (obj instanceof Array) forEach(arrayProps, maybeAdd); else if (obj instanceof Function) forEach(funcProps, maybeAdd); - for (var name in obj) maybeAdd(name); + forAllProps(obj, maybeAdd) } if (context && context.length) { 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