Skip to content

Commit 8d319cd

Browse files
committed
CodeMirror 5.62.3
1 parent 74acdc4 commit 8d319cd

File tree

338 files changed

+52439
-2909
lines changed

Some content is hidden

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

338 files changed

+52439
-2909
lines changed

files/js/3rdParty/codemirror-mc/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# CodeMirror
22

3-
[![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror)
3+
[![Build Status](https://github.com/codemirror/codemirror/workflows/main/badge.svg)](https://github.com/codemirror/codemirror/actions)
44
[![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
5-
[![Join the chat at https://gitter.im/codemirror/CodeMirror](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/codemirror/CodeMirror)
65

76
CodeMirror is a versatile text editor implemented in JavaScript for
87
the browser. It is specialized for editing code, and comes with over

files/js/3rdParty/codemirror-mc/addon/comment/comment.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
var noOptions = {};
1515
var nonWS = /[^\s\u00a0]/;
16-
var Pos = CodeMirror.Pos;
16+
var Pos = CodeMirror.Pos, cmp = CodeMirror.cmpPos;
1717

1818
function firstNonWS(str) {
1919
var found = str.search(nonWS);
@@ -126,7 +126,9 @@
126126
if (i != end || lastLineHasText)
127127
self.replaceRange(lead + pad, Pos(i, 0));
128128
} else {
129+
var atCursor = cmp(self.getCursor("to"), to) == 0, empty = !self.somethingSelected()
129130
self.replaceRange(endString, to);
131+
if (atCursor) self.setSelection(empty ? to : self.getCursor("from"), to)
130132
self.replaceRange(startString, from);
131133
}
132134
});

files/js/3rdParty/codemirror-mc/addon/comment/continuecomment.js

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
else // Plain browser env
1010
mod(CodeMirror);
1111
})(function(CodeMirror) {
12+
var nonspace = /\S/g;
13+
var repeat = String.prototype.repeat || function (n) { return Array(n + 1).join(this); };
1214
function continueComment(cm) {
1315
if (cm.getOption("disableInput")) return CodeMirror.Pass;
1416
var ranges = cm.listSelections(), mode, inserts = [];
@@ -19,29 +21,57 @@
1921
if (!mode) mode = modeHere;
2022
else if (mode != modeHere) return CodeMirror.Pass;
2123

22-
var insert = null;
23-
if (mode.blockCommentStart && mode.blockCommentContinue) {
24-
var line = cm.getLine(pos.line).slice(0, pos.ch)
25-
var end = line.lastIndexOf(mode.blockCommentEnd), found
26-
if (end != -1 && end == pos.ch - mode.blockCommentEnd.length) {
27-
// Comment ended, don't continue it
28-
} else if ((found = line.lastIndexOf(mode.blockCommentStart)) > -1 && found > end) {
29-
insert = line.slice(0, found)
30-
if (/\S/.test(insert)) {
31-
insert = ""
32-
for (var j = 0; j < found; ++j) insert += " "
24+
var insert = null, line, found;
25+
var blockStart = mode.blockCommentStart, lineCmt = mode.lineComment;
26+
if (blockStart && mode.blockCommentContinue) {
27+
line = cm.getLine(pos.line);
28+
var end = line.lastIndexOf(mode.blockCommentEnd, pos.ch - mode.blockCommentEnd.length);
29+
// 1. if this block comment ended
30+
// 2. if this is actually inside a line comment
31+
if (end != -1 && end == pos.ch - mode.blockCommentEnd.length ||
32+
lineCmt && (found = line.lastIndexOf(lineCmt, pos.ch - 1)) > -1 &&
33+
/\bcomment\b/.test(cm.getTokenTypeAt({line: pos.line, ch: found + 1}))) {
34+
// ...then don't continue it
35+
} else if (pos.ch >= blockStart.length &&
36+
(found = line.lastIndexOf(blockStart, pos.ch - blockStart.length)) > -1 &&
37+
found > end) {
38+
// reuse the existing leading spaces/tabs/mixed
39+
// or build the correct indent using CM's tab/indent options
40+
if (nonspaceAfter(0, line) >= found) {
41+
insert = line.slice(0, found);
42+
} else {
43+
var tabSize = cm.options.tabSize, numTabs;
44+
found = CodeMirror.countColumn(line, found, tabSize);
45+
insert = !cm.options.indentWithTabs ? repeat.call(" ", found) :
46+
repeat.call("\t", (numTabs = Math.floor(found / tabSize))) +
47+
repeat.call(" ", found - tabSize * numTabs);
3348
}
34-
} else if ((found = line.indexOf(mode.blockCommentContinue)) > -1 && !/\S/.test(line.slice(0, found))) {
35-
insert = line.slice(0, found)
49+
} else if ((found = line.indexOf(mode.blockCommentContinue)) > -1 &&
50+
found <= pos.ch &&
51+
found <= nonspaceAfter(0, line)) {
52+
insert = line.slice(0, found);
3653
}
3754
if (insert != null) insert += mode.blockCommentContinue
3855
}
39-
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
40-
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
41-
if (found > -1) {
42-
insert = line.slice(0, found);
43-
if (/\S/.test(insert)) insert = null;
44-
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
56+
if (insert == null && lineCmt && continueLineCommentEnabled(cm)) {
57+
if (line == null) line = cm.getLine(pos.line);
58+
found = line.indexOf(lineCmt);
59+
// cursor at pos 0, line comment also at pos 0 => shift it down, don't continue
60+
if (!pos.ch && !found) insert = "";
61+
// continue only if the line starts with an optional space + line comment
62+
else if (found > -1 && nonspaceAfter(0, line) >= found) {
63+
// don't continue if there's only space(s) after cursor or the end of the line
64+
insert = nonspaceAfter(pos.ch, line) > -1;
65+
// but always continue if the next line starts with a line comment too
66+
if (!insert) {
67+
var next = cm.getLine(pos.line + 1) || '',
68+
nextFound = next.indexOf(lineCmt);
69+
insert = nextFound > -1 && nonspaceAfter(0, next) >= nextFound || null;
70+
}
71+
if (insert) {
72+
insert = line.slice(0, found) + lineCmt +
73+
line.slice(found + lineCmt.length).match(/^\s*/)[0];
74+
}
4575
}
4676
}
4777
if (insert == null) return CodeMirror.Pass;
@@ -54,6 +84,12 @@
5484
});
5585
}
5686

87+
function nonspaceAfter(ch, str) {
88+
nonspace.lastIndex = ch;
89+
var m = nonspace.exec(str);
90+
return m ? m.index : -1;
91+
}
92+
5793
function continueLineCommentEnabled(cm) {
5894
var opt = cm.getOption("continueComments");
5995
if (opt && typeof opt == "object")

files/js/3rdParty/codemirror-mc/addon/dialog/dialog.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
if (e.keyCode == 13) callback(inp.value, e);
8383
});
8484

85-
if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
85+
if (options.closeOnBlur !== false) CodeMirror.on(dialog, "focusout", function (evt) {
86+
if (evt.relatedTarget !== null) close();
87+
});
8688
} else if (button = dialog.getElementsByTagName("button")[0]) {
8789
CodeMirror.on(button, "click", function() {
8890
close();

files/js/3rdParty/codemirror-mc/addon/display/panel.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// CodeMirror, copyright (c) by Marijn Haverbeke and others
22
// Distributed under an MIT license: https://codemirror.net/LICENSE
33

4-
(function(mod) {
4+
(function (mod) {
55
if (typeof exports == "object" && typeof module == "object") // CommonJS
66
mod(require("../../lib/codemirror"));
77
else if (typeof define == "function" && define.amd) // AMD
88
define(["../../lib/codemirror"], mod);
99
else // Plain browser env
1010
mod(CodeMirror);
11-
})(function(CodeMirror) {
12-
CodeMirror.defineExtension("addPanel", function(node, options) {
11+
})(function (CodeMirror) {
12+
CodeMirror.defineExtension("addPanel", function (node, options) {
1313
options = options || {};
1414

1515
if (!this.state.panels) initPanels(this);
@@ -25,8 +25,7 @@
2525
wrapper.insertBefore(node, options.before.node);
2626
} else if (replace) {
2727
wrapper.insertBefore(node, options.replace.node);
28-
info.panels++;
29-
options.replace.clear();
28+
options.replace.clear(true);
3029
} else if (options.position == "bottom") {
3130
wrapper.appendChild(node);
3231
} else if (options.position == "before-bottom") {
@@ -38,14 +37,15 @@
3837
}
3938

4039
var height = (options && options.height) || node.offsetHeight;
41-
this._setSize(null, info.heightLeft -= height);
42-
if (!replace) {
43-
info.panels++;
44-
}
40+
41+
var panel = new Panel(this, node, options, height);
42+
info.panels.push(panel);
43+
44+
this.setSize();
4545
if (options.stable && isAtTop(this, node))
46-
this.scrollTo(null, this.getScrollInfo().top + height)
46+
this.scrollTo(null, this.getScrollInfo().top + height);
4747

48-
return new Panel(this, node, options, height);
48+
return panel;
4949
});
5050

5151
function Panel(cm, node, options, height) {
@@ -56,42 +56,43 @@
5656
this.cleared = false;
5757
}
5858

59-
Panel.prototype.clear = function() {
59+
/* when skipRemove is true, clear() was called from addPanel().
60+
* Thus removePanels() should not be called (issue 5518) */
61+
Panel.prototype.clear = function (skipRemove) {
6062
if (this.cleared) return;
6163
this.cleared = true;
6264
var info = this.cm.state.panels;
63-
this.cm._setSize(null, info.heightLeft += this.height);
65+
info.panels.splice(info.panels.indexOf(this), 1);
66+
this.cm.setSize();
6467
if (this.options.stable && isAtTop(this.cm, this.node))
6568
this.cm.scrollTo(null, this.cm.getScrollInfo().top - this.height)
6669
info.wrapper.removeChild(this.node);
67-
if (--info.panels == 0) removePanels(this.cm);
70+
if (info.panels.length == 0 && !skipRemove) removePanels(this.cm);
6871
};
6972

70-
Panel.prototype.changed = function(height) {
71-
var newHeight = height == null ? this.node.offsetHeight : height;
72-
var info = this.cm.state.panels;
73-
this.cm._setSize(null, info.heightLeft -= (newHeight - this.height));
74-
this.height = newHeight;
73+
Panel.prototype.changed = function () {
74+
this.height = this.node.getBoundingClientRect().height;
75+
this.cm.setSize();
7576
};
7677

7778
function initPanels(cm) {
78-
var wrap = cm.getWrapperElement();
79+
var wrap = cm.getWrapperElement()
7980
var style = window.getComputedStyle ? window.getComputedStyle(wrap) : wrap.currentStyle;
8081
var height = parseInt(style.height);
8182
var info = cm.state.panels = {
8283
setHeight: wrap.style.height,
83-
heightLeft: height,
84-
panels: 0,
84+
panels: [],
8585
wrapper: document.createElement("div")
8686
};
87+
var hasFocus = cm.hasFocus(), scrollPos = cm.getScrollInfo()
8788
wrap.parentNode.insertBefore(info.wrapper, wrap);
88-
var hasFocus = cm.hasFocus();
8989
info.wrapper.appendChild(wrap);
90+
cm.scrollTo(scrollPos.left, scrollPos.top)
9091
if (hasFocus) cm.focus();
9192

9293
cm._setSize = cm.setSize;
93-
if (height != null) cm.setSize = function(width, newHeight) {
94-
if (newHeight == null) return this._setSize(width, newHeight);
94+
if (height != null) cm.setSize = function (width, newHeight) {
95+
if (!newHeight) newHeight = info.wrapper.offsetHeight;
9596
info.setHeight = newHeight;
9697
if (typeof newHeight != "number") {
9798
var px = /^(\d+\.?\d*)px$/.exec(newHeight);
@@ -100,10 +101,12 @@
100101
} else {
101102
info.wrapper.style.height = newHeight;
102103
newHeight = info.wrapper.offsetHeight;
103-
info.wrapper.style.height = "";
104104
}
105105
}
106-
cm._setSize(width, info.heightLeft += (newHeight - height));
106+
var editorheight = newHeight - info.panels
107+
.map(function (p) { return p.node.getBoundingClientRect().height; })
108+
.reduce(function (a, b) { return a + b; }, 0);
109+
cm._setSize(width, editorheight);
107110
height = newHeight;
108111
};
109112
}
@@ -112,8 +115,11 @@
112115
var info = cm.state.panels;
113116
cm.state.panels = null;
114117

115-
var wrap = cm.getWrapperElement();
118+
var wrap = cm.getWrapperElement()
119+
var hasFocus = cm.hasFocus(), scrollPos = cm.getScrollInfo()
116120
info.wrapper.parentNode.replaceChild(wrap, info.wrapper);
121+
cm.scrollTo(scrollPos.left, scrollPos.top)
122+
if (hasFocus) cm.focus();
117123
wrap.style.height = info.setHeight;
118124
cm.setSize = cm._setSize;
119125
cm.setSize();

files/js/3rdParty/codemirror-mc/addon/display/placeholder.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
cm.on("blur", onBlur);
1616
cm.on("change", onChange);
1717
cm.on("swapDoc", onChange);
18+
CodeMirror.on(cm.getInputField(), "compositionupdate", cm.state.placeholderCompose = function() { onComposition(cm) })
1819
onChange(cm);
1920
} else if (!val && prev) {
2021
cm.off("blur", onBlur);
2122
cm.off("change", onChange);
2223
cm.off("swapDoc", onChange);
24+
CodeMirror.off(cm.getInputField(), "compositionupdate", cm.state.placeholderCompose)
2325
clearPlaceholder(cm);
2426
var wrapper = cm.getWrapperElement();
2527
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
@@ -39,13 +41,26 @@
3941
var elt = cm.state.placeholder = document.createElement("pre");
4042
elt.style.cssText = "height: 0; overflow: visible";
4143
elt.style.direction = cm.getOption("direction");
42-
elt.className = "CodeMirror-placeholder";
44+
elt.className = "CodeMirror-placeholder CodeMirror-line-like";
4345
var placeHolder = cm.getOption("placeholder")
4446
if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
4547
elt.appendChild(placeHolder)
4648
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
4749
}
4850

51+
function onComposition(cm) {
52+
setTimeout(function() {
53+
var empty = false
54+
if (cm.lineCount() == 1) {
55+
var input = cm.getInputField()
56+
empty = input.nodeName == "TEXTAREA" ? !cm.getLine(0).length
57+
: !/[^\u200b]/.test(input.querySelector(".CodeMirror-line").textContent)
58+
}
59+
if (empty) setPlaceholder(cm)
60+
else clearPlaceholder(cm)
61+
}, 20)
62+
}
63+
4964
function onBlur(cm) {
5065
if (isEmpty(cm)) setPlaceholder(cm);
5166
}

files/js/3rdParty/codemirror-mc/addon/edit/closebrackets.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
})(function(CodeMirror) {
1212
var defaults = {
1313
pairs: "()[]{}''\"\"",
14+
closeBefore: ")]}'\":;>",
1415
triples: "",
1516
explode: "[]{}"
1617
};
@@ -86,7 +87,7 @@
8687
cm.operation(function() {
8788
var linesep = cm.lineSeparator() || "\n";
8889
cm.replaceSelection(linesep + linesep, null);
89-
cm.execCommand("goCharLeft");
90+
moveSel(cm, -1)
9091
ranges = cm.listSelections();
9192
for (var i = 0; i < ranges.length; i++) {
9293
var line = ranges[i].head.line;
@@ -96,6 +97,17 @@
9697
});
9798
}
9899

100+
function moveSel(cm, dir) {
101+
var newRanges = [], ranges = cm.listSelections(), primary = 0
102+
for (var i = 0; i < ranges.length; i++) {
103+
var range = ranges[i]
104+
if (range.head == cm.getCursor()) primary = i
105+
var pos = range.head.ch || dir > 0 ? {line: range.head.line, ch: range.head.ch + dir} : {line: range.head.line - 1}
106+
newRanges.push({anchor: pos, head: pos})
107+
}
108+
cm.setSelections(newRanges, primary)
109+
}
110+
99111
function contractSelection(sel) {
100112
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
101113
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
@@ -109,6 +121,9 @@
109121
var pairs = getOption(conf, "pairs");
110122
var pos = pairs.indexOf(ch);
111123
if (pos == -1) return CodeMirror.Pass;
124+
125+
var closeBefore = getOption(conf,"closeBefore");
126+
112127
var triples = getOption(conf, "triples");
113128

114129
var identical = pairs.charAt(pos + 1) == ch;
@@ -136,7 +151,7 @@
136151
var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur)
137152
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both";
138153
else return CodeMirror.Pass;
139-
} else if (opening) {
154+
} else if (opening && (next.length === 0 || /\s/.test(next) || closeBefore.indexOf(next) > -1)) {
140155
curType = "both";
141156
} else {
142157
return CodeMirror.Pass;
@@ -149,10 +164,9 @@
149164
var right = pos % 2 ? ch : pairs.charAt(pos + 1);
150165
cm.operation(function() {
151166
if (type == "skip") {
152-
cm.execCommand("goCharRight");
167+
moveSel(cm, 1)
153168
} else if (type == "skipThree") {
154-
for (var i = 0; i < 3; i++)
155-
cm.execCommand("goCharRight");
169+
moveSel(cm, 3)
156170
} else if (type == "surround") {
157171
var sels = cm.getSelections();
158172
for (var i = 0; i < sels.length; i++)
@@ -165,10 +179,10 @@
165179
} else if (type == "both") {
166180
cm.replaceSelection(left + right, null);
167181
cm.triggerElectric(left + right);
168-
cm.execCommand("goCharLeft");
182+
moveSel(cm, -1)
169183
} else if (type == "addFour") {
170184
cm.replaceSelection(left + left + left + left, "before");
171-
cm.execCommand("goCharRight");
185+
moveSel(cm, 1)
172186
}
173187
});
174188
}

0 commit comments

Comments
 (0)