Skip to content

Commit 7adf67a

Browse files
committed
Merge pull request #5232 from okonomiyaki3000/UpdateCodeMirror
CodeMirror 4.8
2 parents 09f3ccc + c7f2395 commit 7adf67a

File tree

161 files changed

+4871
-13785
lines changed

Some content is hidden

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

161 files changed

+4871
-13785
lines changed

media/editors/codemirror/addon/comment/comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
CodeMirror.defineExtension("uncomment", function(from, to, options) {
110110
if (!options) options = noOptions;
111111
var self = this, mode = self.getModeAt(from);
112-
var end = Math.min(to.line, self.lastLine()), start = Math.min(from.line, end);
112+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);
113113

114114
// Try finding line comments
115115
var lineString = options.lineComment || mode.lineComment, lines = [];

media/editors/codemirror/addon/dialog/dialog.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656

5757
var inp = dialog.getElementsByTagName("input")[0], button;
5858
if (inp) {
59-
if (options.value) inp.value = options.value;
59+
if (options.value) {
60+
inp.value = options.value;
61+
inp.select();
62+
}
6063

6164
if (options.onInput)
6265
CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);});

media/editors/codemirror/addon/edit/closebrackets.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,32 @@
7171
};
7272
var closingBrackets = "";
7373
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
74-
if (left != right) closingBrackets += right;
74+
closingBrackets += right;
7575
map["'" + left + "'"] = function(cm) {
7676
if (cm.getOption("disableInput")) return CodeMirror.Pass;
7777
var ranges = cm.listSelections(), type, next;
7878
for (var i = 0; i < ranges.length; i++) {
7979
var range = ranges[i], cur = range.head, curType;
8080
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
81-
if (!range.empty())
81+
if (!range.empty()) {
8282
curType = "surround";
83-
else if (left == right && next == right) {
83+
} else if (left == right && next == right) {
8484
if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
8585
curType = "skipThree";
8686
else
8787
curType = "skip";
8888
} else if (left == right && cur.ch > 1 &&
8989
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
90-
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left))
90+
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left)) {
9191
curType = "addFour";
92-
else if (left == '"' || left == "'") {
92+
} else if (left == '"' || left == "'") {
9393
if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both";
9494
else return CodeMirror.Pass;
95-
} else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
95+
} else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next)) {
9696
curType = "both";
97-
else
97+
} else {
9898
return CodeMirror.Pass;
99+
}
99100
if (!type) type = curType;
100101
else if (type != curType) return CodeMirror.Pass;
101102
}

media/editors/codemirror/addon/edit/continuelist.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,39 @@
1111
})(function(CodeMirror) {
1212
"use strict";
1313

14-
var listRE = /^(\s*)([*+-]|(\d+)\.)(\s+)/,
14+
var listRE = /^(\s*)([> ]+|[*+-]|(\d+)\.)(\s+)/,
15+
emptyListRE = /^(\s*)([> ]+|[*+-]|(\d+)\.)(\s*)$/,
1516
unorderedBullets = "*+-";
1617

1718
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
1819
if (cm.getOption("disableInput")) return CodeMirror.Pass;
1920
var ranges = cm.listSelections(), replacements = [];
2021
for (var i = 0; i < ranges.length; i++) {
2122
var pos = ranges[i].head, match;
22-
var inList = cm.getStateAfter(pos.line).list !== false;
23+
var eolState = cm.getStateAfter(pos.line);
24+
var inList = eolState.list !== false;
25+
var inQuote = eolState.quote !== false;
2326

24-
if (!ranges[i].empty() || !inList || !(match = cm.getLine(pos.line).match(listRE))) {
27+
if (!ranges[i].empty() || (!inList && !inQuote) || !(match = cm.getLine(pos.line).match(listRE))) {
2528
cm.execCommand("newlineAndIndent");
2629
return;
2730
}
28-
var indent = match[1], after = match[4];
29-
var bullet = unorderedBullets.indexOf(match[2]) >= 0
30-
? match[2]
31-
: (parseInt(match[3], 10) + 1) + ".";
31+
if (cm.getLine(pos.line).match(emptyListRE)) {
32+
cm.replaceRange("", {
33+
line: pos.line, ch: 0
34+
}, {
35+
line: pos.line, ch: pos.ch + 1
36+
});
37+
replacements[i] = "\n";
3238

33-
replacements[i] = "\n" + indent + bullet + after;
39+
} else {
40+
var indent = match[1], after = match[4];
41+
var bullet = unorderedBullets.indexOf(match[2]) >= 0 || match[2].indexOf(">") >= 0
42+
? match[2]
43+
: (parseInt(match[3], 10) + 1) + ".";
44+
45+
replacements[i] = "\n" + indent + bullet + after;
46+
}
3447
}
3548

3649
cm.replaceSelections(replacements);

media/editors/codemirror/addon/hint/javascript-hint.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"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(" ");
9494

9595
function getCompletions(token, context, keywords, options) {
96-
var found = [], start = token.string;
96+
var found = [], start = token.string, global = options && options.globalScope || window;
9797
function maybeAdd(str) {
9898
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
9999
}
@@ -112,28 +112,28 @@
112112
if (options && options.additionalContext)
113113
base = options.additionalContext[obj.string];
114114
if (!options || options.useGlobalScope !== false)
115-
base = base || window[obj.string];
115+
base = base || global[obj.string];
116116
} else if (obj.type == "string") {
117117
base = "";
118118
} else if (obj.type == "atom") {
119119
base = 1;
120120
} else if (obj.type == "function") {
121-
if (window.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
122-
(typeof window.jQuery == 'function'))
123-
base = window.jQuery();
124-
else if (window._ != null && (obj.string == '_') && (typeof window._ == 'function'))
125-
base = window._();
121+
if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
122+
(typeof global.jQuery == 'function'))
123+
base = global.jQuery();
124+
else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
125+
base = global._();
126126
}
127127
while (base != null && context.length)
128128
base = base[context.pop().string];
129129
if (base != null) gatherCompletions(base);
130130
} else {
131-
// If not, just look in the window object and any local scope
131+
// If not, just look in the global object and any local scope
132132
// (reading into JS mode internals to get at the local and global variables)
133133
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
134134
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
135135
if (!options || options.useGlobalScope !== false)
136-
gatherCompletions(window);
136+
gatherCompletions(global);
137137
forEach(keywords, maybeAdd);
138138
}
139139
return found;

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

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"use strict";
1313

1414
var tables;
15+
var defaultTable;
1516
var keywords;
1617
var CONS = {
1718
QUERY_DIV: ";",
@@ -43,18 +44,55 @@
4344
}
4445
}
4546

46-
function columnCompletion(result, editor) {
47+
function nameCompletion(result, editor) {
4748
var cur = editor.getCursor();
4849
var token = editor.getTokenAt(cur);
50+
var useBacktick = (token.string.charAt(0) == "`");
4951
var string = token.string.substr(1);
50-
var prevCur = Pos(cur.line, token.start);
51-
var table = editor.getTokenAt(prevCur).string;
52-
if (!tables.hasOwnProperty(table))
53-
table = findTableByAlias(table, editor);
54-
var columns = tables[table];
55-
if (!columns) return;
56-
57-
addMatches(result, string, columns, function(w) {return "." + w;});
52+
var prevToken = editor.getTokenAt(Pos(cur.line, token.start));
53+
if (token.string.charAt(0) == "." || prevToken.string == "."){
54+
//Suggest colunm names
55+
if (prevToken.string == ".") {
56+
var prevToken = editor.getTokenAt(Pos(cur.line, token.start - 1));
57+
}
58+
var table = prevToken.string;
59+
//Check if backtick is used in table name. If yes, use it for columns too.
60+
var useBacktickTable = false;
61+
if (table.match(/`/g)) {
62+
useBacktickTable = true;
63+
table = table.replace(/`/g, "");
64+
}
65+
//Check if table is available. If not, find table by Alias
66+
if (!tables.hasOwnProperty(table))
67+
table = findTableByAlias(table, editor);
68+
var columns = tables[table];
69+
if (!columns) return;
70+
71+
if (useBacktick) {
72+
addMatches(result, string, columns, function(w) {return "`" + w + "`";});
73+
}
74+
else if(useBacktickTable) {
75+
addMatches(result, string, columns, function(w) {return ".`" + w + "`";});
76+
}
77+
else {
78+
addMatches(result, string, columns, function(w) {return "." + w;});
79+
}
80+
}
81+
else {
82+
//Suggest table names or colums in defaultTable
83+
while (token.start && string.charAt(0) == ".") {
84+
token = editor.getTokenAt(Pos(cur.line, token.start - 1));
85+
string = token.string + string;
86+
}
87+
if (useBacktick) {
88+
addMatches(result, string, tables, function(w) {return "`" + w + "`";});
89+
addMatches(result, string, defaultTable, function(w) {return "`" + w + "`";});
90+
}
91+
else {
92+
addMatches(result, string, tables, function(w) {return w;});
93+
addMatches(result, string, defaultTable, function(w) {return w;});
94+
}
95+
}
5896
}
5997

6098
function eachWord(lineText, f) {
@@ -128,30 +166,26 @@
128166

129167
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
130168
tables = (options && options.tables) || {};
169+
var defaultTableName = options && options.defaultTable;
170+
defaultTable = (defaultTableName && tables[defaultTableName] || []);
131171
keywords = keywords || getKeywords(editor);
172+
132173
var cur = editor.getCursor();
133174
var result = [];
134175
var token = editor.getTokenAt(cur), start, end, search;
135-
if (token.string.match(/^[.\w@]\w*$/)) {
176+
if (token.string.match(/^[.`\w@]\w*$/)) {
136177
search = token.string;
137178
start = token.start;
138179
end = token.end;
139180
} else {
140181
start = end = cur.ch;
141182
search = "";
142183
}
143-
if (search.charAt(0) == ".") {
144-
columnCompletion(result, editor);
145-
if (!result.length) {
146-
while (start && search.charAt(0) == ".") {
147-
token = editor.getTokenAt(Pos(cur.line, token.start - 1));
148-
start = token.start;
149-
search = token.string + search;
150-
}
151-
addMatches(result, search, tables, function(w) {return w;});
152-
}
184+
if (search.charAt(0) == "." || search.charAt(0) == "`") {
185+
nameCompletion(result, editor);
153186
} else {
154187
addMatches(result, search, tables, function(w) {return w;});
188+
addMatches(result, search, defaultTable, function(w) {return w;});
155189
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
156190
}
157191

media/editors/codemirror/addon/hint/xml-hint.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
1818
var quote = (options && options.quoteChar) || '"';
1919
if (!tags) return;
2020
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
21+
if (/^<\/?$/.test(token.string) && token.end == cur.ch) {
22+
var nextToken = cm.getTokenAt(Pos(cur.line, cur.ch + 1));
23+
if (nextToken.start == cur.ch && /\btag\b/.test(nextToken.type))
24+
token = nextToken;
25+
}
2126
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
2227
if (inner.mode.name != "xml") return;
2328
var result = [], replaceToken = false, prefix;
24-
var tag = /\btag\b/.test(token.type), tagName = tag && /^\w/.test(token.string), tagStart;
29+
var tag = /\btag\b/.test(token.type) && !/>$/.test(token.string);
30+
var tagName = tag && /^\w/.test(token.string), tagStart;
31+
2532
if (tagName) {
2633
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
2734
var tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
@@ -31,6 +38,7 @@
3138
} else if (tag && token.string == "</") {
3239
tagType = "close";
3340
}
41+
3442
if (!tag && !inner.state.tagName || tagType) {
3543
if (tagName)
3644
prefix = token.string;

media/editors/codemirror/addon/lint/lint.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@
118118

119119
function startLinting(cm) {
120120
var state = cm.state.lint, options = state.options;
121+
var passOptions = options.options || options; // Support deprecated passing of `options` property in options
121122
if (options.async)
122-
options.getAnnotations(cm, updateLinting, options);
123+
options.getAnnotations(cm.getValue(), updateLinting, passOptions, cm);
123124
else
124-
updateLinting(cm, options.getAnnotations(cm.getValue(), options.options));
125+
updateLinting(cm, options.getAnnotations(cm.getValue(), passOptions, cm));
125126
}
126127

127128
function updateLinting(cm, annotationsNotSorted) {
@@ -170,20 +171,14 @@
170171
showTooltipFor(e, annotationTooltip(ann), target);
171172
}
172173

173-
// When the mouseover fires, the cursor might not actually be over
174-
// the character itself yet. These pairs of x,y offsets are used to
175-
// probe a few nearby points when no suitable marked range is found.
176-
var nearby = [0, 0, 0, 5, 0, -5, 5, 0, -5, 0];
177-
178174
function onMouseOver(cm, e) {
179-
if (!/\bCodeMirror-lint-mark-/.test((e.target || e.srcElement).className)) return;
180-
for (var i = 0; i < nearby.length; i += 2) {
181-
var spans = cm.findMarksAt(cm.coordsChar({left: e.clientX + nearby[i],
182-
top: e.clientY + nearby[i + 1]}, "client"));
183-
for (var j = 0; j < spans.length; ++j) {
184-
var span = spans[j], ann = span.__annotation;
185-
if (ann) return popupSpanTooltip(ann, e);
186-
}
175+
var target = e.target || e.srcElement;
176+
if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
177+
var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
178+
var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
179+
for (var i = 0; i < spans.length; ++i) {
180+
var ann = spans[i].__annotation;
181+
if (ann) return popupSpanTooltip(ann, e);
187182
}
188183
}
189184

media/editors/codemirror/addon/mode/loadmode.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
(function(mod) {
55
if (typeof exports == "object" && typeof module == "object") // CommonJS
6-
mod(require("../../lib/codemirror"));
6+
mod(require("../../lib/codemirror"), "cjs");
77
else if (typeof define == "function" && define.amd) // AMD
8-
define(["../../lib/codemirror"], mod);
8+
define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); });
99
else // Plain browser env
10-
mod(CodeMirror);
11-
})(function(CodeMirror) {
10+
mod(CodeMirror, "plain");
11+
})(function(CodeMirror, env) {
1212
if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
1313

1414
var loading = {};
@@ -35,21 +35,24 @@
3535
if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
3636
if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
3737

38-
var script = document.createElement("script");
39-
script.src = CodeMirror.modeURL.replace(/%N/g, mode);
40-
var others = document.getElementsByTagName("script")[0];
41-
others.parentNode.insertBefore(script, others);
42-
var list = loading[mode] = [cont];
43-
var count = 0, poll = setInterval(function() {
44-
if (++count > 100) return clearInterval(poll);
45-
if (CodeMirror.modes.hasOwnProperty(mode)) {
46-
clearInterval(poll);
47-
loading[mode] = null;
38+
var file = CodeMirror.modeURL.replace(/%N/g, mode);
39+
if (env == "plain") {
40+
var script = document.createElement("script");
41+
script.src = file;
42+
var others = document.getElementsByTagName("script")[0];
43+
var list = loading[mode] = [cont];
44+
CodeMirror.on(script, "load", function() {
4845
ensureDeps(mode, function() {
4946
for (var i = 0; i < list.length; ++i) list[i]();
5047
});
51-
}
52-
}, 200);
48+
});
49+
others.parentNode.insertBefore(script, others);
50+
} else if (env == "cjs") {
51+
require(file);
52+
cont();
53+
} else if (env == "amd") {
54+
requirejs([file], cont);
55+
}
5356
};
5457

5558
CodeMirror.autoLoadMode = function(instance, mode) {

0 commit comments

Comments
 (0)