Skip to content

Commit 8bf5162

Browse files
committed
Update CodeMirror to 5.13.5
1 parent edc3a31 commit 8bf5162

84 files changed

Lines changed: 2835 additions & 502 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

public/vendor/codemirror/addon/comment/comment.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@
4444
}
4545
});
4646

47+
// Rough heuristic to try and detect lines that are part of multi-line string
48+
function probablyInsideString(cm, pos, line) {
49+
return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"`]/.test(line)
50+
}
51+
4752
CodeMirror.defineExtension("lineComment", function(from, to, options) {
4853
if (!options) options = noOptions;
4954
var self = this, mode = self.getModeAt(from);
55+
var firstLine = self.getLine(from.line);
56+
if (firstLine == null || probablyInsideString(self, from, firstLine)) return;
57+
5058
var commentString = options.lineComment || mode.lineComment;
5159
if (!commentString) {
5260
if (options.blockCommentStart || mode.blockCommentStart) {
@@ -55,8 +63,7 @@
5563
}
5664
return;
5765
}
58-
var firstLine = self.getLine(from.line);
59-
if (firstLine == null) return;
66+
6067
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
6168
var pad = options.padding == null ? " " : options.padding;
6269
var blankLines = options.commentBlankLines || from.line == to.line;

public/vendor/codemirror/addon/dialog/dialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
var inp = dialog.getElementsByTagName("input")[0], button;
5858
if (inp) {
59+
inp.focus();
60+
5961
if (options.value) {
6062
inp.value = options.value;
6163
if (options.selectValueOnOpen !== false) {
@@ -79,8 +81,6 @@
7981
});
8082

8183
if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
82-
83-
inp.focus();
8484
} else if (button = dialog.getElementsByTagName("button")[0]) {
8585
CodeMirror.on(button, "click", function() {
8686
close();

public/vendor/codemirror/addon/display/placeholder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
if (val && !prev) {
1515
cm.on("blur", onBlur);
1616
cm.on("change", onChange);
17+
cm.on("swapDoc", onChange);
1718
onChange(cm);
1819
} else if (!val && prev) {
1920
cm.off("blur", onBlur);
2021
cm.off("change", onChange);
22+
cm.off("swapDoc", onChange);
2123
clearPlaceholder(cm);
2224
var wrapper = cm.getWrapperElement();
2325
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@
121121

122122
finishUpdate: function(data, first) {
123123
if (this.data) CodeMirror.signal(this.data, "update");
124-
if (data && this.data && CodeMirror.cmpPos(data.from, this.data.from)) data = null;
125-
this.data = data;
126124

127125
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
128126
if (this.widget) this.widget.close();
127+
128+
if (data && this.data && isNewCompletion(this.data, data)) return;
129+
this.data = data;
130+
129131
if (data && data.list.length) {
130132
if (picked && data.list.length == 1) {
131133
this.pick(data, 0);
@@ -137,6 +139,11 @@
137139
}
138140
};
139141

142+
function isNewCompletion(old, nw) {
143+
var moved = CodeMirror.cmpPos(nw.from, old.from)
144+
return moved > 0 && old.to.ch - old.from.ch != nw.to.ch - nw.from.ch
145+
}
146+
140147
function parseOptions(cm, pos, options) {
141148
var editor = cm.options.hintOptions;
142149
var out = {};

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

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
};
2121
var Pos = CodeMirror.Pos;
2222

23+
function isArray(val) { return Object.prototype.toString.call(val) == "[object Array]" }
24+
2325
function getKeywords(editor) {
2426
var mode = editor.doc.modeOption;
2527
if (mode === "sql") mode = "text/x-sql";
@@ -30,10 +32,28 @@
3032
return typeof item == "string" ? item : item.text;
3133
}
3234

33-
function getItem(list, item) {
34-
if (!list.slice) return list[item];
35-
for (var i = list.length - 1; i >= 0; i--) if (getText(list[i]) == item)
36-
return list[i];
35+
function wrapTable(name, value) {
36+
if (isArray(value)) value = {columns: value}
37+
if (!value.text) value.text = name
38+
return value
39+
}
40+
41+
function parseTables(input) {
42+
var result = {}
43+
if (isArray(input)) {
44+
for (var i = input.length - 1; i >= 0; i--) {
45+
var item = input[i]
46+
result[getText(item).toUpperCase()] = wrapTable(getText(item), item)
47+
}
48+
} else if (input) {
49+
for (var name in input)
50+
result[name.toUpperCase()] = wrapTable(name, input[name])
51+
}
52+
return result
53+
}
54+
55+
function getTable(name) {
56+
return tables[name.toUpperCase()]
3757
}
3858

3959
function shallowClone(object) {
@@ -50,11 +70,18 @@
5070
}
5171

5272
function addMatches(result, search, wordlist, formatter) {
53-
for (var word in wordlist) {
54-
if (!wordlist.hasOwnProperty(word)) continue;
55-
if (wordlist.slice) word = wordlist[word];
56-
57-
if (match(search, word)) result.push(formatter(word));
73+
if (isArray(wordlist)) {
74+
for (var i = 0; i < wordlist.length; i++)
75+
if (match(search, wordlist[i])) result.push(formatter(wordlist[i]))
76+
} else {
77+
for (var word in wordlist) if (wordlist.hasOwnProperty(word)) {
78+
var val = wordlist[word]
79+
if (!val || val === true)
80+
val = word
81+
else
82+
val = val.displayText ? {text: val.text, displayText: val.displayText} : val.text
83+
if (match(search, val)) result.push(formatter(val))
84+
}
5885
}
5986
}
6087

@@ -78,7 +105,7 @@
78105
}
79106

80107
function nameCompletion(cur, token, result, editor) {
81-
// Try to complete table, colunm names and return start position of completion
108+
// Try to complete table, column names and return start position of completion
82109
var useBacktick = false;
83110
var nameParts = [];
84111
var start = token.start;
@@ -115,13 +142,13 @@
115142
var alias = false;
116143
var aliasTable = table;
117144
// Check if table is available. If not, find table by Alias
118-
if (!getItem(tables, table)) {
145+
if (!getTable(table)) {
119146
var oldTable = table;
120147
table = findTableByAlias(table, editor);
121148
if (table !== oldTable) alias = true;
122149
}
123150

124-
var columns = getItem(tables, table);
151+
var columns = getTable(table);
125152
if (columns && columns.columns)
126153
columns = columns.columns;
127154

@@ -184,7 +211,7 @@
184211
//find valid range
185212
var prevItem = 0;
186213
var current = convertCurToNumber(editor.getCursor());
187-
for (var i=0; i< separator.length; i++) {
214+
for (var i = 0; i < separator.length; i++) {
188215
var _v = convertCurToNumber(separator[i]);
189216
if (current > prevItem && current <= _v) {
190217
validRange = { start: convertNumberToCur(prevItem), end: convertNumberToCur(_v) };
@@ -199,7 +226,7 @@
199226
var lineText = query[i];
200227
eachWord(lineText, function(word) {
201228
var wordUpperCase = word.toUpperCase();
202-
if (wordUpperCase === aliasUpperCase && getItem(tables, previousWord))
229+
if (wordUpperCase === aliasUpperCase && getTable(previousWord))
203230
table = previousWord;
204231
if (wordUpperCase !== CONS.ALIAS_KEYWORD)
205232
previousWord = word;
@@ -210,10 +237,10 @@
210237
}
211238

212239
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
213-
tables = (options && options.tables) || {};
240+
tables = parseTables(options && options.tables)
214241
var defaultTableName = options && options.defaultTable;
215242
var disableKeywords = options && options.disableKeywords;
216-
defaultTable = defaultTableName && getItem(tables, defaultTableName);
243+
defaultTable = defaultTableName && getTable(defaultTableName);
217244
keywords = keywords || getKeywords(editor);
218245

219246
if (defaultTableName && !defaultTable)

public/vendor/codemirror/addon/lint/lint.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,27 @@
186186
state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
187187
}
188188

189-
function popupSpanTooltip(ann, e) {
189+
function popupTooltips(annotations, e) {
190190
var target = e.target || e.srcElement;
191-
showTooltipFor(e, annotationTooltip(ann), target);
191+
var tooltip = document.createDocumentFragment();
192+
for (var i = 0; i < annotations.length; i++) {
193+
var ann = annotations[i];
194+
tooltip.appendChild(annotationTooltip(ann));
195+
}
196+
showTooltipFor(e, tooltip, target);
192197
}
193198

194199
function onMouseOver(cm, e) {
195200
var target = e.target || e.srcElement;
196201
if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
197202
var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
198203
var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
204+
205+
var annotations = [];
199206
for (var i = 0; i < spans.length; ++i) {
200-
var ann = spans[i].__annotation;
201-
if (ann) return popupSpanTooltip(ann, e);
207+
annotations.push(spans[i].__annotation);
202208
}
209+
if (annotations.length) popupTooltips(annotations, e);
203210
}
204211

205212
CodeMirror.defineOption("lint", false, function(cm, val, old) {

public/vendor/codemirror/addon/merge/merge.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
position: absolute;
6161
cursor: pointer;
6262
color: #44c;
63+
z-index: 3;
6364
}
6465

6566
.CodeMirror-merge-copy-reverse {

public/vendor/codemirror/addon/merge/merge.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,9 @@
427427

428428
function copyChunk(dv, to, from, chunk) {
429429
if (dv.diffOutOfDate) return;
430-
to.replaceRange(from.getRange(Pos(chunk.origFrom, 0), Pos(chunk.origTo, 0)),
431-
Pos(chunk.editFrom, 0), Pos(chunk.editTo, 0));
430+
var editStart = chunk.editTo > to.lastLine() ? Pos(chunk.editFrom - 1) : Pos(chunk.editFrom, 0)
431+
var origStart = chunk.origTo > from.lastLine() ? Pos(chunk.origFrom - 1) : Pos(chunk.origFrom, 0)
432+
to.replaceRange(from.getRange(origStart, Pos(chunk.origTo, 0)), editStart, Pos(chunk.editTo, 0))
432433
}
433434

434435
// Merge view, containing 0, 1, or 2 diff views.

public/vendor/codemirror/addon/scroll/simplescrollbars.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@
5959
CodeMirror.on(this.node, "DOMMouseScroll", onWheel);
6060
}
6161

62-
Bar.prototype.moveTo = function(pos, update) {
62+
Bar.prototype.setPos = function(pos) {
6363
if (pos < 0) pos = 0;
6464
if (pos > this.total - this.screen) pos = this.total - this.screen;
65-
if (pos == this.pos) return;
65+
if (pos == this.pos) return false;
6666
this.pos = pos;
6767
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
6868
(pos * (this.size / this.total)) + "px";
69-
if (update !== false) this.scroll(pos, this.orientation);
69+
return true
7070
};
7171

72+
Bar.prototype.moveTo = function(pos) {
73+
if (this.setPos(pos)) this.scroll(pos, this.orientation);
74+
}
75+
7276
var minButtonSize = 10;
7377

7478
Bar.prototype.update = function(scrollSize, clientSize, barSize) {
@@ -83,8 +87,7 @@
8387
}
8488
this.inner.style[this.orientation == "horizontal" ? "width" : "height"] =
8589
buttonSize + "px";
86-
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
87-
this.pos * (this.size / this.total) + "px";
90+
this.setPos(this.pos);
8891
};
8992

9093
function SimpleScrollbars(cls, place, scroll) {
@@ -111,7 +114,6 @@
111114
if (needsV) {
112115
this.vert.update(measure.scrollHeight, measure.clientHeight,
113116
measure.viewHeight - (needsH ? width : 0));
114-
this.vert.node.style.display = "block";
115117
this.vert.node.style.bottom = needsH ? width + "px" : "0";
116118
}
117119
if (needsH) {
@@ -125,11 +127,11 @@
125127
};
126128

127129
SimpleScrollbars.prototype.setScrollTop = function(pos) {
128-
this.vert.moveTo(pos, false);
130+
this.vert.setPos(pos);
129131
};
130132

131133
SimpleScrollbars.prototype.setScrollLeft = function(pos) {
132-
this.horiz.moveTo(pos, false);
134+
this.horiz.setPos(pos);
133135
};
134136

135137
SimpleScrollbars.prototype.clear = function() {

public/vendor/codemirror/addon/search/match-highlighter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// highlighted only if the selected text is a word. showToken, when enabled,
1717
// will cause the current token to be highlighted when nothing is selected.
1818
// delay is used to specify how much time to wait, in milliseconds, before
19-
// highlighting the matches. If annotateScrollbar is enabled, the occurances
19+
// highlighting the matches. If annotateScrollbar is enabled, the occurences
2020
// will be highlighted on the scrollbar via the matchesonscrollbar addon.
2121

2222
(function(mod) {

0 commit comments

Comments
 (0)