Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0838d4

Browse files
committed
Upgrade CodeMirror to version 5.3.0
Signed-off-by: Madhura Jayaratne <[email protected]>
1 parent f2720fa commit f0838d4

10 files changed

Lines changed: 679 additions & 546 deletions

File tree

js/codemirror/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (C) 2014 by Marijn Haverbeke <[email protected]> and others
1+
Copyright (C) 2015 by Marijn Haverbeke <[email protected]> and others
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.CodeMirror-hints {
2+
position: absolute;
3+
z-index: 10;
4+
overflow: hidden;
5+
list-style: none;
6+
7+
margin: 0;
8+
padding: 2px;
9+
10+
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
11+
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
12+
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
13+
border-radius: 3px;
14+
border: 1px solid silver;
15+
16+
background: white;
17+
font-size: 90%;
18+
font-family: monospace;
19+
20+
max-height: 20em;
21+
overflow-y: auto;
22+
}
23+
24+
.CodeMirror-hint {
25+
margin: 0;
26+
padding: 0 4px;
27+
border-radius: 2px;
28+
max-width: 19em;
29+
overflow: hidden;
30+
white-space: pre;
31+
color: black;
32+
cursor: pointer;
33+
}
34+
35+
li.CodeMirror-hint-active {
36+
background: #08f;
37+
color: white;
38+
}

js/codemirror/addon/hint/show-hint.js

Lines changed: 61 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,45 @@
2424
return cm.showHint(newOpts);
2525
};
2626

27-
var asyncRunID = 0;
28-
function retrieveHints(getter, cm, options, then) {
29-
if (getter.async) {
30-
var id = ++asyncRunID;
31-
getter(cm, function(hints) {
32-
if (asyncRunID == id) then(hints);
33-
}, options);
34-
} else {
35-
then(getter(cm, options));
36-
}
37-
}
38-
3927
CodeMirror.defineExtension("showHint", function(options) {
4028
// We want a single cursor position.
4129
if (this.listSelections().length > 1 || this.somethingSelected()) return;
4230

4331
if (this.state.completionActive) this.state.completionActive.close();
4432
var completion = this.state.completionActive = new Completion(this, options);
45-
var getHints = completion.options.hint;
46-
if (!getHints) return;
33+
if (!completion.options.hint) return;
4734

4835
CodeMirror.signal(this, "startCompletion", this);
49-
return retrieveHints(getHints, this, completion.options, function(hints) { completion.showHints(hints); });
36+
completion.update(true);
5037
});
5138

5239
function Completion(cm, options) {
5340
this.cm = cm;
5441
this.options = this.buildOptions(options);
55-
this.widget = this.onClose = null;
42+
this.widget = null;
43+
this.debounce = 0;
44+
this.tick = 0;
45+
this.startPos = this.cm.getCursor();
46+
this.startLen = this.cm.getLine(this.startPos.line).length;
47+
48+
var self = this;
49+
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
5650
}
5751

52+
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
53+
return setTimeout(fn, 1000/60);
54+
};
55+
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
56+
5857
Completion.prototype = {
5958
close: function() {
6059
if (!this.active()) return;
6160
this.cm.state.completionActive = null;
61+
this.tick = null;
62+
this.cm.off("cursorActivity", this.activityFunc);
6263

64+
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
6365
if (this.widget) this.widget.close();
64-
if (this.onClose) this.onClose();
6566
CodeMirror.signal(this.cm, "endCompletion", this.cm);
6667
},
6768

@@ -78,70 +79,50 @@
7879
this.close();
7980
},
8081

81-
showHints: function(data) {
82-
if (!data || !data.list.length || !this.active()) return this.close();
83-
84-
if (this.options.completeSingle && data.list.length == 1)
85-
this.pick(data, 0);
86-
else
87-
this.showWidget(data);
88-
},
89-
90-
showWidget: function(data) {
91-
this.widget = new Widget(this, data);
92-
CodeMirror.signal(data, "shown");
93-
94-
var debounce = 0, completion = this, finished;
95-
var closeOn = this.options.closeCharacters;
96-
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
97-
98-
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
99-
return setTimeout(fn, 1000/60);
100-
};
101-
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
102-
103-
function done() {
104-
if (finished) return;
105-
finished = true;
106-
completion.close();
107-
completion.cm.off("cursorActivity", activity);
108-
if (data) CodeMirror.signal(data, "close");
82+
cursorActivity: function() {
83+
if (this.debounce) {
84+
cancelAnimationFrame(this.debounce);
85+
this.debounce = 0;
10986
}
11087

111-
function update() {
112-
if (finished) return;
113-
CodeMirror.signal(data, "update");
114-
retrieveHints(completion.options.hint, completion.cm, completion.options, finishUpdate);
115-
}
116-
function finishUpdate(data_) {
117-
data = data_;
118-
if (finished) return;
119-
if (!data || !data.list.length) return done();
120-
if (completion.widget) completion.widget.close();
121-
completion.widget = new Widget(completion, data);
88+
var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
89+
if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
90+
pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
91+
(pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
92+
this.close();
93+
} else {
94+
var self = this;
95+
this.debounce = requestAnimationFrame(function() {self.update();});
96+
if (this.widget) this.widget.disable();
12297
}
98+
},
12399

124-
function clearDebounce() {
125-
if (debounce) {
126-
cancelAnimationFrame(debounce);
127-
debounce = 0;
128-
}
100+
update: function(first) {
101+
if (this.tick == null) return;
102+
if (this.data) CodeMirror.signal(this.data, "update");
103+
if (!this.options.hint.async) {
104+
this.finishUpdate(this.options.hint(this.cm, this.options), first);
105+
} else {
106+
var myTick = ++this.tick, self = this;
107+
this.options.hint(this.cm, function(data) {
108+
if (self.tick == myTick) self.finishUpdate(data, first);
109+
}, this.options);
129110
}
111+
},
112+
113+
finishUpdate: function(data, first) {
114+
this.data = data;
130115

131-
function activity() {
132-
clearDebounce();
133-
var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line);
134-
if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch ||
135-
pos.ch < startPos.ch || completion.cm.somethingSelected() ||
136-
(pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) {
137-
completion.close();
116+
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
117+
if (this.widget) this.widget.close();
118+
if (data && data.list.length) {
119+
if (picked && data.list.length == 1) {
120+
this.pick(data, 0);
138121
} else {
139-
debounce = requestAnimationFrame(update);
140-
if (completion.widget) completion.widget.close();
122+
this.widget = new Widget(this, data);
123+
CodeMirror.signal(data, "shown");
141124
}
142125
}
143-
this.cm.on("cursorActivity", activity);
144-
this.onClose = done;
145126
},
146127

147128
buildOptions: function(options) {
@@ -206,6 +187,7 @@
206187
function Widget(completion, data) {
207188
this.completion = completion;
208189
this.data = data;
190+
this.picked = false;
209191
var widget = this, cm = completion.cm;
210192

211193
var hints = this.hints = document.createElement("ul");
@@ -320,6 +302,13 @@
320302
cm.off("scroll", this.onScroll);
321303
},
322304

305+
disable: function() {
306+
this.completion.cm.removeKeyMap(this.keyMap);
307+
var widget = this;
308+
this.keyMap = {Enter: function() { widget.picked = true; }};
309+
this.completion.cm.addKeyMap(this.keyMap);
310+
},
311+
323312
pick: function() {
324313
this.completion.pick(this.data, this.selectedHint);
325314
},

js/codemirror/addon/hint/sql-hint.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@
5252
function addMatches(result, search, wordlist, formatter) {
5353
for (var word in wordlist) {
5454
if (!wordlist.hasOwnProperty(word)) continue;
55-
if (Array.isArray(wordlist)) {
56-
word = wordlist[word];
57-
}
58-
if (match(search, word)) {
59-
result.push(formatter(word));
60-
}
55+
if (wordlist.slice) word = wordlist[word];
56+
57+
if (match(search, word)) result.push(formatter(word));
6158
}
6259
}
6360

@@ -115,18 +112,25 @@
115112
string = nameParts.pop();
116113
var table = nameParts.join(".");
117114

115+
var alias = false;
116+
var aliasTable = table;
118117
// Check if table is available. If not, find table by Alias
119-
if (!getItem(tables, table))
118+
if (!getItem(tables, table)) {
119+
var oldTable = table;
120120
table = findTableByAlias(table, editor);
121+
if (table !== oldTable) alias = true;
122+
}
121123

122124
var columns = getItem(tables, table);
123-
if (columns && Array.isArray(tables) && columns.columns)
125+
if (columns && columns.columns)
124126
columns = columns.columns;
125127

126128
if (columns) {
127129
addMatches(result, string, columns, function(w) {
128130
if (typeof w == "string") {
129-
w = table + "." + w;
131+
var tableInsert = table;
132+
if (alias == true) tableInsert = aliasTable;
133+
w = tableInsert + "." + w;
130134
} else {
131135
w = shallowClone(w);
132136
w.text = table + "." + w.text;
@@ -208,6 +212,7 @@
208212
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
209213
tables = (options && options.tables) || {};
210214
var defaultTableName = options && options.defaultTable;
215+
var disableKeywords = options && options.disableKeywords;
211216
defaultTable = defaultTableName && getItem(tables, defaultTableName);
212217
keywords = keywords || getKeywords(editor);
213218

@@ -216,7 +221,7 @@
216221

217222
defaultTable = defaultTable || [];
218223

219-
if (Array.isArray(tables) && defaultTable.columns)
224+
if (defaultTable.columns)
220225
defaultTable = defaultTable.columns;
221226

222227
var cur = editor.getCursor();
@@ -240,7 +245,8 @@
240245
} else {
241246
addMatches(result, search, tables, function(w) {return w;});
242247
addMatches(result, search, defaultTable, function(w) {return w;});
243-
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
248+
if (!disableKeywords)
249+
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
244250
}
245251

246252
return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)};

0 commit comments

Comments
 (0)