Upgrade CodeMirror to 5.59.2

This should fix the following issue:
- https://www.reddit.com/r/uBlockOrigin/comments/lnfyer/

CodeMirror was detecting Windows as iOS:
- https://github.com/codemirror/CodeMirror/issues/6532
This commit is contained in:
Raymond Hill 2021-02-19 13:07:34 -05:00
parent 427eabb628
commit 0dfafc3bd3
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
5 changed files with 49 additions and 28 deletions

View file

@ -76,7 +76,7 @@
};
function initPanels(cm) {
var wrap = cm.getWrapperElement();
var wrap = cm.getWrapperElement()
var style = window.getComputedStyle ? window.getComputedStyle(wrap) : wrap.currentStyle;
var height = parseInt(style.height);
var info = cm.state.panels = {
@ -84,9 +84,10 @@
panels: [],
wrapper: document.createElement("div")
};
var hasFocus = cm.hasFocus(), scrollPos = cm.getScrollInfo()
wrap.parentNode.insertBefore(info.wrapper, wrap);
var hasFocus = cm.hasFocus();
info.wrapper.appendChild(wrap);
cm.scrollTo(scrollPos.left, scrollPos.top)
if (hasFocus) cm.focus();
cm._setSize = cm.setSize;
@ -114,8 +115,11 @@
var info = cm.state.panels;
cm.state.panels = null;
var wrap = cm.getWrapperElement();
var wrap = cm.getWrapperElement()
var hasFocus = cm.hasFocus(), scrollPos = cm.getScrollInfo()
info.wrapper.parentNode.replaceChild(wrap, info.wrapper);
cm.scrollTo(scrollPos.left, scrollPos.top)
if (hasFocus) cm.focus();
wrap.style.height = info.setHeight;
cm.setSize = cm._setSize;
cm.setSize();

View file

@ -87,7 +87,7 @@
cm.operation(function() {
var linesep = cm.lineSeparator() || "\n";
cm.replaceSelection(linesep + linesep, null);
cm.execCommand("goCharLeft");
moveSel(cm, -1)
ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var line = ranges[i].head.line;
@ -97,6 +97,17 @@
});
}
function moveSel(cm, dir) {
var newRanges = [], ranges = cm.listSelections(), primary = 0
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i]
if (range.head == cm.getCursor()) primary = i
var pos = range.head.ch || dir > 0 ? {line: range.head.line, ch: range.head.ch + dir} : {line: range.head.line - 1}
newRanges.push({anchor: pos, head: pos})
}
cm.setSelections(newRanges, primary)
}
function contractSelection(sel) {
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
@ -153,10 +164,9 @@
var right = pos % 2 ? ch : pairs.charAt(pos + 1);
cm.operation(function() {
if (type == "skip") {
cm.execCommand("goCharRight");
moveSel(cm, 1)
} else if (type == "skipThree") {
for (var i = 0; i < 3; i++)
cm.execCommand("goCharRight");
moveSel(cm, 3)
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++)
@ -169,10 +179,10 @@
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.triggerElectric(left + right);
cm.execCommand("goCharLeft");
moveSel(cm, -1)
} else if (type == "addFour") {
cm.replaceSelection(left + left + left + left, "before");
cm.execCommand("goCharRight");
moveSel(cm, 1)
}
});
}

View file

@ -38,7 +38,7 @@
if (config && config.strict && (dir > 0) != (pos == where.ch)) return null;
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style, config);
if (found == null) return null;
return {from: Pos(where.line, pos), to: found && found.pos,
match: found && found.ch == match.charAt(0), forward: dir > 0};
@ -67,7 +67,8 @@
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
for (; pos != end; pos += dir) {
var ch = line.charAt(pos);
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
if (re.test(ch) && (style === undefined ||
(cm.getTokenTypeAt(Pos(lineNo, pos + 1)) || "") == (style || ""))) {
var match = matching[ch];
if (match && (match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
@ -80,11 +81,12 @@
function matchBrackets(cm, autoclear, config) {
// Disable brace matching in long lines, since it'll cause hugely slow updates
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000,
highlightNonMatching = config && config.highlightNonMatching;
var marks = [], ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config);
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
if (match && (match.match || highlightNonMatching !== false) && cm.getLine(match.from.line).length <= maxHighlightLen) {
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
@ -94,7 +96,7 @@
if (marks.length) {
// Kludge to work around the IE bug from issue #1193, where text
// input stops going to the textare whever this fires.
// input stops going to the textarea whenever this fires.
if (ie_lt8 && cm.state.focused) cm.focus();
var clear = function() {

View file

@ -61,8 +61,10 @@
this.startPos = this.cm.getCursor("start");
this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
var self = this;
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
if (this.options.updateOnCursorActivity) {
var self = this;
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
}
}
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
@ -75,7 +77,9 @@
if (!this.active()) return;
this.cm.state.completionActive = null;
this.tick = null;
this.cm.off("cursorActivity", this.activityFunc);
if (this.options.updateOnCursorActivity) {
this.cm.off("cursorActivity", this.activityFunc);
}
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
if (this.widget) this.widget.close();
@ -117,9 +121,7 @@
if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
pos.ch < identStart.ch || this.cm.somethingSelected() ||
(!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
if (this.options.closeOnCursorActivity) {
this.close();
}
this.close();
} else {
var self = this;
this.debounce = requestAnimationFrame(function() {self.update();});
@ -492,9 +494,9 @@
completeSingle: true,
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeOnCursorActivity: true,
closeOnPick: true,
closeOnUnfocus: true,
updateOnCursorActivity: true,
completeOnSingleClick: true,
container: null,
customKeys: null,

View file

@ -32,7 +32,7 @@
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
var phantom = /PhantomJS/.test(userAgent);
var ios = !edge && /AppleWebKit/.test(userAgent) && (/Mobile\/\w+/.test(userAgent) || navigator.maxTouchPoints > 2);
var ios = safari && (/Mobile\/\w+/.test(userAgent) || navigator.maxTouchPoints > 2);
var android = /Android/.test(userAgent);
// This is woefully incomplete. Suggestions for alternative methods welcome.
var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
@ -5115,7 +5115,7 @@
(cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
if (!(options && options.scroll === false) && doc.cm)
if (!(options && options.scroll === false) && doc.cm && doc.cm.getOption("readOnly") != "nocursor")
{ ensureCursorVisible(doc.cm); }
}
@ -8675,10 +8675,13 @@
function moveOnce(boundToLine) {
var next;
if (unit == "codepoint") {
var ch = lineObj.text.charCodeAt(pos.ch + (unit > 0 ? 0 : -1));
if (isNaN(ch)) { next = null; }
else { next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (ch >= 0xD800 && ch < 0xDC00 ? 2 : 1))),
-dir); }
var ch = lineObj.text.charCodeAt(pos.ch + (dir > 0 ? 0 : -1));
if (isNaN(ch)) {
next = null;
} else {
var astral = dir > 0 ? ch >= 0xD800 && ch < 0xDC00 : ch >= 0xDC00 && ch < 0xDFFF;
next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (astral ? 2 : 1))), -dir);
}
} else if (visually) {
next = moveVisually(doc.cm, lineObj, pos, dir);
} else {
@ -9790,7 +9793,7 @@
addLegacyProps(CodeMirror);
CodeMirror.version = "5.59.0";
CodeMirror.version = "5.59.2";
return CodeMirror;