From 8bf516263c6582771e7576e8484ca8cfaa8cb9cb Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Wed, 20 Apr 2016 18:11:40 +0800 Subject: Update CodeMirror to 5.13.5 --- public/vendor/codemirror/addon/hint/show-hint.js | 11 ++++- public/vendor/codemirror/addon/hint/sql-hint.js | 59 +++++++++++++++++------- 2 files changed, 52 insertions(+), 18 deletions(-) (limited to 'public/vendor/codemirror/addon/hint') diff --git a/public/vendor/codemirror/addon/hint/show-hint.js b/public/vendor/codemirror/addon/hint/show-hint.js index cbe3b39a..7661f6c2 100644 --- a/public/vendor/codemirror/addon/hint/show-hint.js +++ b/public/vendor/codemirror/addon/hint/show-hint.js @@ -121,11 +121,13 @@ finishUpdate: function(data, first) { if (this.data) CodeMirror.signal(this.data, "update"); - if (data && this.data && CodeMirror.cmpPos(data.from, this.data.from)) data = null; - this.data = data; var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle); if (this.widget) this.widget.close(); + + if (data && this.data && isNewCompletion(this.data, data)) return; + this.data = data; + if (data && data.list.length) { if (picked && data.list.length == 1) { this.pick(data, 0); @@ -137,6 +139,11 @@ } }; + function isNewCompletion(old, nw) { + var moved = CodeMirror.cmpPos(nw.from, old.from) + return moved > 0 && old.to.ch - old.from.ch != nw.to.ch - nw.from.ch + } + function parseOptions(cm, pos, options) { var editor = cm.options.hintOptions; var out = {}; diff --git a/public/vendor/codemirror/addon/hint/sql-hint.js b/public/vendor/codemirror/addon/hint/sql-hint.js index 22124b58..62c4f68d 100644 --- a/public/vendor/codemirror/addon/hint/sql-hint.js +++ b/public/vendor/codemirror/addon/hint/sql-hint.js @@ -20,6 +20,8 @@ }; var Pos = CodeMirror.Pos; + function isArray(val) { return Object.prototype.toString.call(val) == "[object Array]" } + function getKeywords(editor) { var mode = editor.doc.modeOption; if (mode === "sql") mode = "text/x-sql"; @@ -30,10 +32,28 @@ return typeof item == "string" ? item : item.text; } - function getItem(list, item) { - if (!list.slice) return list[item]; - for (var i = list.length - 1; i >= 0; i--) if (getText(list[i]) == item) - return list[i]; + function wrapTable(name, value) { + if (isArray(value)) value = {columns: value} + if (!value.text) value.text = name + return value + } + + function parseTables(input) { + var result = {} + if (isArray(input)) { + for (var i = input.length - 1; i >= 0; i--) { + var item = input[i] + result[getText(item).toUpperCase()] = wrapTable(getText(item), item) + } + } else if (input) { + for (var name in input) + result[name.toUpperCase()] = wrapTable(name, input[name]) + } + return result + } + + function getTable(name) { + return tables[name.toUpperCase()] } function shallowClone(object) { @@ -50,11 +70,18 @@ } function addMatches(result, search, wordlist, formatter) { - for (var word in wordlist) { - if (!wordlist.hasOwnProperty(word)) continue; - if (wordlist.slice) word = wordlist[word]; - - if (match(search, word)) result.push(formatter(word)); + if (isArray(wordlist)) { + for (var i = 0; i < wordlist.length; i++) + if (match(search, wordlist[i])) result.push(formatter(wordlist[i])) + } else { + for (var word in wordlist) if (wordlist.hasOwnProperty(word)) { + var val = wordlist[word] + if (!val || val === true) + val = word + else + val = val.displayText ? {text: val.text, displayText: val.displayText} : val.text + if (match(search, val)) result.push(formatter(val)) + } } } @@ -78,7 +105,7 @@ } function nameCompletion(cur, token, result, editor) { - // Try to complete table, colunm names and return start position of completion + // Try to complete table, column names and return start position of completion var useBacktick = false; var nameParts = []; var start = token.start; @@ -115,13 +142,13 @@ var alias = false; var aliasTable = table; // Check if table is available. If not, find table by Alias - if (!getItem(tables, table)) { + if (!getTable(table)) { var oldTable = table; table = findTableByAlias(table, editor); if (table !== oldTable) alias = true; } - var columns = getItem(tables, table); + var columns = getTable(table); if (columns && columns.columns) columns = columns.columns; @@ -184,7 +211,7 @@ //find valid range var prevItem = 0; var current = convertCurToNumber(editor.getCursor()); - for (var i=0; i< separator.length; i++) { + for (var i = 0; i < separator.length; i++) { var _v = convertCurToNumber(separator[i]); if (current > prevItem && current <= _v) { validRange = { start: convertNumberToCur(prevItem), end: convertNumberToCur(_v) }; @@ -199,7 +226,7 @@ var lineText = query[i]; eachWord(lineText, function(word) { var wordUpperCase = word.toUpperCase(); - if (wordUpperCase === aliasUpperCase && getItem(tables, previousWord)) + if (wordUpperCase === aliasUpperCase && getTable(previousWord)) table = previousWord; if (wordUpperCase !== CONS.ALIAS_KEYWORD) previousWord = word; @@ -210,10 +237,10 @@ } CodeMirror.registerHelper("hint", "sql", function(editor, options) { - tables = (options && options.tables) || {}; + tables = parseTables(options && options.tables) var defaultTableName = options && options.defaultTable; var disableKeywords = options && options.disableKeywords; - defaultTable = defaultTableName && getItem(tables, defaultTableName); + defaultTable = defaultTableName && getTable(defaultTableName); keywords = keywords || getKeywords(editor); if (defaultTableName && !defaultTable) -- cgit v1.2.3