Skip to content

Commit 9b8b0f0

Browse files
authored
Merge pull request #4987 from chromoxdor/Update/EasyColorCode
[EasyColorCode] Update codemirror to 5.65.16
2 parents f46a8fb + 013fcfe commit 9b8b0f0

File tree

2 files changed

+59
-42
lines changed

2 files changed

+59
-42
lines changed

static/codemirror.js

+58-41
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@ var nameKey; //added by chromoxdor
114114
} while (child = child.parentNode)
115115
}
116116

117-
function activeElt(doc) {
117+
function activeElt(rootNode) {
118118
// IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
119119
// IE < 10 will throw when accessed while the page is loading or in an iframe.
120120
// IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
121+
var doc = rootNode.ownerDocument || rootNode;
121122
var activeElement;
122123
try {
123-
activeElement = doc.activeElement;
124+
activeElement = rootNode.activeElement;
124125
} catch(e) {
125126
activeElement = doc.body || null;
126127
}
@@ -148,6 +149,15 @@ var nameKey; //added by chromoxdor
148149

149150
function doc(cm) { return cm.display.wrapper.ownerDocument }
150151

152+
function root(cm) {
153+
return rootNode(cm.display.wrapper)
154+
}
155+
156+
function rootNode(element) {
157+
// Detect modern browsers (2017+).
158+
return element.getRootNode ? element.getRootNode() : element.ownerDocument
159+
}
160+
151161
function win(cm) { return doc(cm).defaultView }
152162

153163
function bind(f) {
@@ -540,7 +550,7 @@ var nameKey; //added by chromoxdor
540550

541551
var on = function(emitter, type, f) {
542552
if (emitter.addEventListener) {
543-
emitter.addEventListener(type, f, {passive: false});
553+
emitter.addEventListener(type, f, false);
544554
} else if (emitter.attachEvent) {
545555
emitter.attachEvent("on" + type, f);
546556
} else {
@@ -3902,7 +3912,7 @@ var nameKey; //added by chromoxdor
39023912
cm.display.maxLineChanged = false;
39033913
}
39043914

3905-
var takeFocus = op.focus && op.focus == activeElt(doc(cm));
3915+
var takeFocus = op.focus && op.focus == activeElt(root(cm));
39063916
if (op.preparedSelection)
39073917
{ cm.display.input.showSelection(op.preparedSelection, takeFocus); }
39083918
if (op.updatedDisplay || op.startHeight != cm.doc.height)
@@ -4079,7 +4089,7 @@ var nameKey; //added by chromoxdor
40794089

40804090
function selectionSnapshot(cm) {
40814091
if (cm.hasFocus()) { return null }
4082-
var active = activeElt(doc(cm));
4092+
var active = activeElt(root(cm));
40834093
if (!active || !contains(cm.display.lineDiv, active)) { return null }
40844094
var result = {activeElt: active};
40854095
if (window.getSelection) {
@@ -4095,7 +4105,7 @@ var nameKey; //added by chromoxdor
40954105
}
40964106

40974107
function restoreSelection(snapshot) {
4098-
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(snapshot.activeElt.ownerDocument)) { return }
4108+
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(rootNode(snapshot.activeElt))) { return }
40994109
snapshot.activeElt.focus();
41004110
if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) &&
41014111
snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
@@ -4417,6 +4427,8 @@ var nameKey; //added by chromoxdor
44174427
d.scroller.setAttribute("tabIndex", "-1");
44184428
// The element in which the editor lives.
44194429
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
4430+
// See #6982. FIXME remove when this has been fixed for a while in Chrome
4431+
if (chrome && chrome_version >= 105) { d.wrapper.style.clipPath = "inset(0px)"; }
44204432

44214433
// This attribute is respected by automatic translation systems such as Google Translate,
44224434
// and may also be respected by tools used by human translators.
@@ -7265,7 +7277,7 @@ var nameKey; //added by chromoxdor
72657277
function onKeyDown(e) {
72667278
var cm = this;
72677279
if (e.target && e.target != cm.display.input.getField()) { return }
7268-
cm.curOp.focus = activeElt(doc(cm));
7280+
cm.curOp.focus = activeElt(root(cm));
72697281
if (signalDOMEvent(cm, e)) { return }
72707282
// IE does strange things with escape.
72717283
if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
@@ -7427,7 +7439,7 @@ var nameKey; //added by chromoxdor
74277439

74287440
function leftButtonDown(cm, pos, repeat, event) {
74297441
if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
7430-
else { cm.curOp.focus = activeElt(doc(cm)); }
7442+
else { cm.curOp.focus = activeElt(root(cm)); }
74317443

74327444
var behavior = configureMouse(cm, repeat, event);
74337445

@@ -7497,19 +7509,19 @@ var nameKey; //added by chromoxdor
74977509
// Normal selection, as opposed to text dragging.
74987510
function leftButtonSelect(cm, event, start, behavior) {
74997511
if (ie) { delayBlurEvent(cm); }
7500-
var display = cm.display, doc$1 = cm.doc;
7512+
var display = cm.display, doc = cm.doc;
75017513
e_preventDefault(event);
75027514

7503-
var ourRange, ourIndex, startSel = doc$1.sel, ranges = startSel.ranges;
7515+
var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
75047516
if (behavior.addNew && !behavior.extend) {
7505-
ourIndex = doc$1.sel.contains(start);
7517+
ourIndex = doc.sel.contains(start);
75067518
if (ourIndex > -1)
75077519
{ ourRange = ranges[ourIndex]; }
75087520
else
75097521
{ ourRange = new Range(start, start); }
75107522
} else {
7511-
ourRange = doc$1.sel.primary();
7512-
ourIndex = doc$1.sel.primIndex;
7523+
ourRange = doc.sel.primary();
7524+
ourIndex = doc.sel.primIndex;
75137525
}
75147526

75157527
if (behavior.unit == "rectangle") {
@@ -7526,18 +7538,18 @@ var nameKey; //added by chromoxdor
75267538

75277539
if (!behavior.addNew) {
75287540
ourIndex = 0;
7529-
setSelection(doc$1, new Selection([ourRange], 0), sel_mouse);
7530-
startSel = doc$1.sel;
7541+
setSelection(doc, new Selection([ourRange], 0), sel_mouse);
7542+
startSel = doc.sel;
75317543
} else if (ourIndex == -1) {
75327544
ourIndex = ranges.length;
7533-
setSelection(doc$1, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
7545+
setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
75347546
{scroll: false, origin: "*mouse"});
75357547
} else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
7536-
setSelection(doc$1, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
7548+
setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
75377549
{scroll: false, origin: "*mouse"});
7538-
startSel = doc$1.sel;
7550+
startSel = doc.sel;
75397551
} else {
7540-
replaceOneSelection(doc$1, ourIndex, ourRange, sel_mouse);
7552+
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
75417553
}
75427554

75437555
var lastPos = start;
@@ -7547,19 +7559,19 @@ var nameKey; //added by chromoxdor
75477559

75487560
if (behavior.unit == "rectangle") {
75497561
var ranges = [], tabSize = cm.options.tabSize;
7550-
var startCol = countColumn(getLine(doc$1, start.line).text, start.ch, tabSize);
7551-
var posCol = countColumn(getLine(doc$1, pos.line).text, pos.ch, tabSize);
7562+
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
7563+
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
75527564
var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
75537565
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
75547566
line <= end; line++) {
7555-
var text = getLine(doc$1, line).text, leftPos = findColumn(text, left, tabSize);
7567+
var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
75567568
if (left == right)
75577569
{ ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
75587570
else if (text.length > leftPos)
75597571
{ ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
75607572
}
75617573
if (!ranges.length) { ranges.push(new Range(start, start)); }
7562-
setSelection(doc$1, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
7574+
setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
75637575
{origin: "*mouse", scroll: false});
75647576
cm.scrollIntoView(pos);
75657577
} else {
@@ -7574,8 +7586,8 @@ var nameKey; //added by chromoxdor
75747586
anchor = maxPos(oldRange.to(), range.head);
75757587
}
75767588
var ranges$1 = startSel.ranges.slice(0);
7577-
ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc$1, anchor), head));
7578-
setSelection(doc$1, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
7589+
ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
7590+
setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
75797591
}
75807592
}
75817593

@@ -7591,9 +7603,9 @@ var nameKey; //added by chromoxdor
75917603
var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
75927604
if (!cur) { return }
75937605
if (cmp(cur, lastPos) != 0) {
7594-
cm.curOp.focus = activeElt(doc(cm));
7606+
cm.curOp.focus = activeElt(root(cm));
75957607
extendTo(cur);
7596-
var visible = visibleLines(display, doc$1);
7608+
var visible = visibleLines(display, doc);
75977609
if (cur.line >= visible.to || cur.line < visible.from)
75987610
{ setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
75997611
} else {
@@ -7618,7 +7630,7 @@ var nameKey; //added by chromoxdor
76187630
}
76197631
off(display.wrapper.ownerDocument, "mousemove", move);
76207632
off(display.wrapper.ownerDocument, "mouseup", up);
7621-
doc$1.history.lastSelOrigin = null;
7633+
doc.history.lastSelOrigin = null;
76227634
}
76237635

76247636
var move = operation(cm, function (e) {
@@ -7775,7 +7787,7 @@ var nameKey; //added by chromoxdor
77757787
for (var i = newBreaks.length - 1; i >= 0; i--)
77767788
{ replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
77777789
});
7778-
option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, function (cm, val, old) {
7790+
option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\u202d\u202e\u2066\u2067\u2069\ufeff\ufff9-\ufffc]/g, function (cm, val, old) {
77797791
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
77807792
if (old != Init) { cm.refresh(); }
77817793
});
@@ -8260,8 +8272,8 @@ var nameKey; //added by chromoxdor
82608272
}
82618273

82628274
function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
8263-
field.setAttribute("autocorrect", autocorrect ? "" : "off");
8264-
field.setAttribute("autocapitalize", autocapitalize ? "" : "off");
8275+
field.setAttribute("autocorrect", autocorrect ? "on" : "off");
8276+
field.setAttribute("autocapitalize", autocapitalize ? "on" : "off");
82658277
field.setAttribute("spellcheck", !!spellcheck);
82668278
}
82678279

@@ -8276,7 +8288,6 @@ var nameKey; //added by chromoxdor
82768288
else { te.setAttribute("wrap", "off"); }
82778289
// If border: 0; -- iOS fails to open keyboard (issue #1287)
82788290
if (ios) { te.style.border = "1px solid black"; }
8279-
disableBrowserMagic(te);
82808291
return div
82818292
}
82828293

@@ -8619,7 +8630,7 @@ var nameKey; //added by chromoxdor
86198630

86208631
signal(this, "overwriteToggle", this, this.state.overwrite);
86218632
},
8622-
hasFocus: function() { return this.display.input.getField() == activeElt(doc(this)) },
8633+
hasFocus: function() { return this.display.input.getField() == activeElt(root(this)) },
86238634
isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
86248635

86258636
scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
@@ -8898,9 +8909,10 @@ var nameKey; //added by chromoxdor
88988909
}
88998910
// Old-fashioned briefly-focus-a-textarea hack
89008911
var kludge = hiddenTextarea(), te = kludge.firstChild;
8912+
disableBrowserMagic(te);
89018913
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
89028914
te.value = lastCopied.text.join("\n");
8903-
var hadFocus = activeElt(div.ownerDocument);
8915+
var hadFocus = activeElt(rootNode(div));
89048916
selectInput(te);
89058917
setTimeout(function () {
89068918
cm.display.lineSpace.removeChild(kludge);
@@ -8923,7 +8935,7 @@ var nameKey; //added by chromoxdor
89238935

89248936
ContentEditableInput.prototype.prepareSelection = function () {
89258937
var result = prepareSelection(this.cm, false);
8926-
result.focus = activeElt(this.div.ownerDocument) == this.div;
8938+
result.focus = activeElt(rootNode(this.div)) == this.div;
89278939
return result
89288940
};
89298941

@@ -9019,7 +9031,7 @@ var nameKey; //added by chromoxdor
90199031

90209032
ContentEditableInput.prototype.focus = function () {
90219033
if (this.cm.options.readOnly != "nocursor") {
9022-
if (!this.selectionInEditor() || activeElt(this.div.ownerDocument) != this.div)
9034+
if (!this.selectionInEditor() || activeElt(rootNode(this.div)) != this.div)
90239035
{ this.showSelection(this.prepareSelection(), true); }
90249036
this.div.focus();
90259037
}
@@ -9371,6 +9383,7 @@ var nameKey; //added by chromoxdor
93719383
// Used to work around IE issue with selection being forgotten when focus moves away from textarea
93729384
this.hasSelection = false;
93739385
this.composing = null;
9386+
this.resetting = false;
93749387
};
93759388

93769389
TextareaInput.prototype.init = function (display) {
@@ -9461,6 +9474,8 @@ var nameKey; //added by chromoxdor
94619474
// The semihidden textarea that is focused when the editor is
94629475
// focused, and receives input.
94639476
this.textarea = this.wrapper.firstChild;
9477+
var opts = this.cm.options;
9478+
disableBrowserMagic(this.textarea, opts.spellcheck, opts.autocorrect, opts.autocapitalize);
94649479
};
94659480

94669481
TextareaInput.prototype.screenReaderLabelChanged = function (label) {
@@ -9503,8 +9518,9 @@ var nameKey; //added by chromoxdor
95039518
// Reset the input to correspond to the selection (or to be empty,
95049519
// when not typing and nothing is selected)
95059520
TextareaInput.prototype.reset = function (typing) {
9506-
if (this.contextMenuPending || this.composing) { return }
9521+
if (this.contextMenuPending || this.composing && typing) { return }
95079522
var cm = this.cm;
9523+
this.resetting = true;
95089524
if (cm.somethingSelected()) {
95099525
this.prevInput = "";
95109526
var content = cm.getSelection();
@@ -9515,14 +9531,15 @@ var nameKey; //added by chromoxdor
95159531
this.prevInput = this.textarea.value = "";
95169532
if (ie && ie_version >= 9) { this.hasSelection = null; }
95179533
}
9534+
this.resetting = false;
95189535
};
95199536

95209537
TextareaInput.prototype.getField = function () { return this.textarea };
95219538

95229539
TextareaInput.prototype.supportsTouch = function () { return false };
95239540

95249541
TextareaInput.prototype.focus = function () {
9525-
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(this.textarea.ownerDocument) != this.textarea)) {
9542+
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(rootNode(this.textarea)) != this.textarea)) {
95269543
try { this.textarea.focus(); }
95279544
catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
95289545
}
@@ -9576,7 +9593,7 @@ var nameKey; //added by chromoxdor
95769593
// possible when it is clear that nothing happened. hasSelection
95779594
// will be the case when there is a lot of text in the textarea,
95789595
// in which case reading its value would be expensive.
9579-
if (this.contextMenuPending || !cm.state.focused ||
9596+
if (this.contextMenuPending || this.resetting || !cm.state.focused ||
95809597
(hasSelection(input) && !prevInput && !this.composing) ||
95819598
cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
95829599
{ return false }
@@ -9729,7 +9746,7 @@ var nameKey; //added by chromoxdor
97299746
// Set autofocus to true if this textarea is focused, or if it has
97309747
// autofocus and no other element is focused.
97319748
if (options.autofocus == null) {
9732-
var hasFocus = activeElt(textarea.ownerDocument);
9749+
var hasFocus = activeElt(rootNode(textarea));
97339750
options.autofocus = hasFocus == textarea ||
97349751
textarea.getAttribute("autofocus") != null && hasFocus == document.body;
97359752
}
@@ -9863,7 +9880,7 @@ var nameKey; //added by chromoxdor
98639880

98649881
addLegacyProps(CodeMirror);
98659882

9866-
CodeMirror.version = "5.65.7";
9883+
CodeMirror.version = "5.65.16";
98679884

98689885
return CodeMirror;
98699886

static/codemirror.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)