Updated codemirror to 5.4.0

This commit is contained in:
Wu Cheng-Han 2015-07-04 11:31:01 +08:00
parent 1d843c8ac2
commit 01685c255f
69 changed files with 2988 additions and 558 deletions

View file

@ -33,7 +33,7 @@
if (!completion.options.hint) return;
CodeMirror.signal(this, "startCompletion", this);
completion.update();
completion.update(true);
});
function Completion(cm, options) {
@ -61,6 +61,7 @@
this.tick = null;
this.cm.off("cursorActivity", this.activityFunc);
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
if (this.widget) this.widget.close();
CodeMirror.signal(this.cm, "endCompletion", this.cm);
},
@ -78,15 +79,6 @@
this.close();
},
showHints: function(data) {
if (!data || !data.list.length || !this.active()) return this.close();
if (this.options.completeSingle && data.list.length == 1)
this.pick(data, 0);
else
this.showWidget(data);
},
cursorActivity: function() {
if (this.debounce) {
cancelAnimationFrame(this.debounce);
@ -105,35 +97,34 @@
}
},
update: function() {
update: function(first) {
if (this.tick == null) return;
if (this.data) CodeMirror.signal(this.data, "update");
if (!this.options.hint.async) {
this.finishUpdate(this.options.hint(this.cm, this.options), myTick);
this.finishUpdate(this.options.hint(this.cm, this.options), first);
} else {
var myTick = ++this.tick, self = this;
this.options.hint(this.cm, function(data) {
if (self.tick == myTick) self.finishUpdate(data);
if (self.tick == myTick) self.finishUpdate(data, first);
}, this.options);
}
},
finishUpdate: function(data) {
finishUpdate: function(data, first) {
this.data = data;
var picked = this.widget && this.widget.picked;
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
if (this.widget) this.widget.close();
if (data && data.list.length) {
if (picked && data.list.length == 1) this.pick(data, 0);
else this.widget = new Widget(this, data);
if (picked && data.list.length == 1) {
this.pick(data, 0);
} else {
this.widget = new Widget(this, data);
CodeMirror.signal(data, "shown");
}
}
},
showWidget: function(data) {
this.data = data;
this.widget = new Widget(this, data);
CodeMirror.signal(data, "shown");
},
buildOptions: function(options) {
var editor = this.cm.options.hintOptions;
var out = {};

View file

@ -112,9 +112,14 @@
string = nameParts.pop();
var table = nameParts.join(".");
var alias = false;
var aliasTable = table;
// Check if table is available. If not, find table by Alias
if (!getItem(tables, table))
if (!getItem(tables, table)) {
var oldTable = table;
table = findTableByAlias(table, editor);
if (table !== oldTable) alias = true;
}
var columns = getItem(tables, table);
if (columns && columns.columns)
@ -122,11 +127,13 @@
if (columns) {
addMatches(result, string, columns, function(w) {
var tableInsert = table;
if (alias == true) tableInsert = aliasTable;
if (typeof w == "string") {
w = table + "." + w;
w = tableInsert + "." + w;
} else {
w = shallowClone(w);
w.text = table + "." + w.text;
w.text = tableInsert + "." + w.text;
}
return useBacktick ? insertBackticks(w) : w;
});
@ -205,6 +212,7 @@
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
tables = (options && options.tables) || {};
var defaultTableName = options && options.defaultTable;
var disableKeywords = options && options.disableKeywords;
defaultTable = defaultTableName && getItem(tables, defaultTableName);
keywords = keywords || getKeywords(editor);
@ -237,7 +245,8 @@
} else {
addMatches(result, search, tables, function(w) {return w;});
addMatches(result, search, defaultTable, function(w) {return w;});
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
if (!disableKeywords)
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
}
return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)};