Skip to content

Commit

Permalink
npm: updates codemirror
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonde committed Feb 3, 2025
1 parent 8e4a37d commit 4126a96
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (C) 2017 by Marijn Haverbeke <[email protected]> and others
Copyright (C) 2017 by Marijn Haverbeke <[email protected]> and others

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@
} while (child = child.parentNode)
}

function activeElt(doc) {
function activeElt(rootNode) {
// IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
// IE < 10 will throw when accessed while the page is loading or in an iframe.
// IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
var doc = rootNode.ownerDocument || rootNode;
var activeElement;
try {
activeElement = doc.activeElement;
activeElement = rootNode.activeElement;
} catch(e) {
activeElement = doc.body || null;
}
Expand Down Expand Up @@ -146,6 +147,15 @@

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

function root(cm) {
return rootNode(cm.display.wrapper)
}

function rootNode(element) {
// Detect modern browsers (2017+).
return element.getRootNode ? element.getRootNode() : element.ownerDocument
}

function win(cm) { return doc(cm).defaultView }

function bind(f) {
Expand Down Expand Up @@ -3415,7 +3425,7 @@
}

// Compute the lines that are visible in a given viewport (defaults
// the the current scroll position). viewport may contain top,
// the current scroll position). viewport may contain top,
// height, and ensure (see op.scrollToPos) properties.
function visibleLines(display, doc, viewport) {
var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
Expand Down Expand Up @@ -3900,7 +3910,7 @@
cm.display.maxLineChanged = false;
}

var takeFocus = op.focus && op.focus == activeElt(doc(cm));
var takeFocus = op.focus && op.focus == activeElt(root(cm));
if (op.preparedSelection)
{ cm.display.input.showSelection(op.preparedSelection, takeFocus); }
if (op.updatedDisplay || op.startHeight != cm.doc.height)
Expand Down Expand Up @@ -4077,7 +4087,7 @@

function selectionSnapshot(cm) {
if (cm.hasFocus()) { return null }
var active = activeElt(doc(cm));
var active = activeElt(root(cm));
if (!active || !contains(cm.display.lineDiv, active)) { return null }
var result = {activeElt: active};
if (window.getSelection) {
Expand All @@ -4093,7 +4103,7 @@
}

function restoreSelection(snapshot) {
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(snapshot.activeElt.ownerDocument)) { return }
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(rootNode(snapshot.activeElt))) { return }
snapshot.activeElt.focus();
if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) &&
snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
Expand Down Expand Up @@ -7264,7 +7274,7 @@
function onKeyDown(e) {
var cm = this;
if (e.target && e.target != cm.display.input.getField()) { return }
cm.curOp.focus = activeElt(doc(cm));
cm.curOp.focus = activeElt(root(cm));
if (signalDOMEvent(cm, e)) { return }
// IE does strange things with escape.
if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
Expand Down Expand Up @@ -7426,7 +7436,7 @@

function leftButtonDown(cm, pos, repeat, event) {
if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
else { cm.curOp.focus = activeElt(doc(cm)); }
else { cm.curOp.focus = activeElt(root(cm)); }

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

Expand Down Expand Up @@ -7496,19 +7506,19 @@
// Normal selection, as opposed to text dragging.
function leftButtonSelect(cm, event, start, behavior) {
if (ie) { delayBlurEvent(cm); }
var display = cm.display, doc$1 = cm.doc;
var display = cm.display, doc = cm.doc;
e_preventDefault(event);

var ourRange, ourIndex, startSel = doc$1.sel, ranges = startSel.ranges;
var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
if (behavior.addNew && !behavior.extend) {
ourIndex = doc$1.sel.contains(start);
ourIndex = doc.sel.contains(start);
if (ourIndex > -1)
{ ourRange = ranges[ourIndex]; }
else
{ ourRange = new Range(start, start); }
} else {
ourRange = doc$1.sel.primary();
ourIndex = doc$1.sel.primIndex;
ourRange = doc.sel.primary();
ourIndex = doc.sel.primIndex;
}

if (behavior.unit == "rectangle") {
Expand All @@ -7525,18 +7535,18 @@

if (!behavior.addNew) {
ourIndex = 0;
setSelection(doc$1, new Selection([ourRange], 0), sel_mouse);
startSel = doc$1.sel;
setSelection(doc, new Selection([ourRange], 0), sel_mouse);
startSel = doc.sel;
} else if (ourIndex == -1) {
ourIndex = ranges.length;
setSelection(doc$1, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
{scroll: false, origin: "*mouse"});
} else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
setSelection(doc$1, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
{scroll: false, origin: "*mouse"});
startSel = doc$1.sel;
startSel = doc.sel;
} else {
replaceOneSelection(doc$1, ourIndex, ourRange, sel_mouse);
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
}

var lastPos = start;
Expand All @@ -7546,19 +7556,19 @@

if (behavior.unit == "rectangle") {
var ranges = [], tabSize = cm.options.tabSize;
var startCol = countColumn(getLine(doc$1, start.line).text, start.ch, tabSize);
var posCol = countColumn(getLine(doc$1, pos.line).text, pos.ch, tabSize);
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
line <= end; line++) {
var text = getLine(doc$1, line).text, leftPos = findColumn(text, left, tabSize);
var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
if (left == right)
{ ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
else if (text.length > leftPos)
{ ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
}
if (!ranges.length) { ranges.push(new Range(start, start)); }
setSelection(doc$1, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
{origin: "*mouse", scroll: false});
cm.scrollIntoView(pos);
} else {
Expand All @@ -7573,8 +7583,8 @@
anchor = maxPos(oldRange.to(), range.head);
}
var ranges$1 = startSel.ranges.slice(0);
ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc$1, anchor), head));
setSelection(doc$1, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
}
}

Expand All @@ -7590,9 +7600,9 @@
var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
if (!cur) { return }
if (cmp(cur, lastPos) != 0) {
cm.curOp.focus = activeElt(doc(cm));
cm.curOp.focus = activeElt(root(cm));
extendTo(cur);
var visible = visibleLines(display, doc$1);
var visible = visibleLines(display, doc);
if (cur.line >= visible.to || cur.line < visible.from)
{ setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
} else {
Expand All @@ -7617,7 +7627,7 @@
}
off(display.wrapper.ownerDocument, "mousemove", move);
off(display.wrapper.ownerDocument, "mouseup", up);
doc$1.history.lastSelOrigin = null;
doc.history.lastSelOrigin = null;
}

var move = operation(cm, function (e) {
Expand Down Expand Up @@ -8259,8 +8269,8 @@
}

function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
field.setAttribute("autocorrect", autocorrect ? "" : "off");
field.setAttribute("autocapitalize", autocapitalize ? "" : "off");
field.setAttribute("autocorrect", autocorrect ? "on" : "off");
field.setAttribute("autocapitalize", autocapitalize ? "on" : "off");
field.setAttribute("spellcheck", !!spellcheck);
}

Expand All @@ -8275,7 +8285,6 @@
else { te.setAttribute("wrap", "off"); }
// If border: 0; -- iOS fails to open keyboard (issue #1287)
if (ios) { te.style.border = "1px solid black"; }
disableBrowserMagic(te);
return div
}

Expand Down Expand Up @@ -8618,7 +8627,7 @@

signal(this, "overwriteToggle", this, this.state.overwrite);
},
hasFocus: function() { return this.display.input.getField() == activeElt(doc(this)) },
hasFocus: function() { return this.display.input.getField() == activeElt(root(this)) },
isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },

scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
Expand Down Expand Up @@ -8897,9 +8906,10 @@
}
// Old-fashioned briefly-focus-a-textarea hack
var kludge = hiddenTextarea(), te = kludge.firstChild;
disableBrowserMagic(te);
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
te.value = lastCopied.text.join("\n");
var hadFocus = activeElt(div.ownerDocument);
var hadFocus = activeElt(rootNode(div));
selectInput(te);
setTimeout(function () {
cm.display.lineSpace.removeChild(kludge);
Expand All @@ -8922,7 +8932,7 @@

ContentEditableInput.prototype.prepareSelection = function () {
var result = prepareSelection(this.cm, false);
result.focus = activeElt(this.div.ownerDocument) == this.div;
result.focus = activeElt(rootNode(this.div)) == this.div;
return result
};

Expand Down Expand Up @@ -9018,7 +9028,7 @@

ContentEditableInput.prototype.focus = function () {
if (this.cm.options.readOnly != "nocursor") {
if (!this.selectionInEditor() || activeElt(this.div.ownerDocument) != this.div)
if (!this.selectionInEditor() || activeElt(rootNode(this.div)) != this.div)
{ this.showSelection(this.prepareSelection(), true); }
this.div.focus();
}
Expand Down Expand Up @@ -9461,6 +9471,8 @@
// The semihidden textarea that is focused when the editor is
// focused, and receives input.
this.textarea = this.wrapper.firstChild;
var opts = this.cm.options;
disableBrowserMagic(this.textarea, opts.spellcheck, opts.autocorrect, opts.autocapitalize);
};

TextareaInput.prototype.screenReaderLabelChanged = function (label) {
Expand Down Expand Up @@ -9524,7 +9536,7 @@
TextareaInput.prototype.supportsTouch = function () { return false };

TextareaInput.prototype.focus = function () {
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(this.textarea.ownerDocument) != this.textarea)) {
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(rootNode(this.textarea)) != this.textarea)) {
try { this.textarea.focus(); }
catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
}
Expand Down Expand Up @@ -9731,7 +9743,7 @@
// Set autofocus to true if this textarea is focused, or if it has
// autofocus and no other element is focused.
if (options.autofocus == null) {
var hasFocus = activeElt(textarea.ownerDocument);
var hasFocus = activeElt(rootNode(textarea));
options.autofocus = hasFocus == textarea ||
textarea.getAttribute("autofocus") != null && hasFocus == document.body;
}
Expand Down Expand Up @@ -9865,7 +9877,7 @@

addLegacyProps(CodeMirror);

CodeMirror.version = "5.65.10";
CodeMirror.version = "5.65.18";

return CodeMirror;

Expand Down

0 comments on commit 4126a96

Please sign in to comment.