CodeMirror 5.59.2

This commit is contained in:
tophf 2021-01-20 14:59:31 +03:00
parent 02bd682135
commit 8cabf8a8aa
11 changed files with 71 additions and 48 deletions

14
package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "1.5.14", "version": "1.5.14",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"dependencies": { "dependencies": {
"codemirror": "5.59.0", "codemirror": "5.59.2",
"db-to-cloud": "^0.4.5", "db-to-cloud": "^0.4.5",
"jsonlint": "^1.6.3", "jsonlint": "^1.6.3",
"less-bundle": "github:openstyles/less-bundle#v0.1.0", "less-bundle": "github:openstyles/less-bundle#v0.1.0",
@ -2364,9 +2364,9 @@
} }
}, },
"node_modules/codemirror": { "node_modules/codemirror": {
"version": "5.59.0", "version": "5.59.2",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.59.0.tgz", "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.59.2.tgz",
"integrity": "sha512-UGzSkCacY9z0rSpQ3wnTWRN2nvRE6foDXnJltWW8pazInR/R+3gXHrao4IFQMv/bSBvFBxt8/HPpkpKAS54x5Q==" "integrity": "sha512-/D5PcsKyzthtSy2NNKCyJi3b+htRkoKv3idswR/tR6UAvMNKA7SrmyZy6fOONJxSRs1JlUWEDAbxqfdArbK8iA=="
}, },
"node_modules/collection-visit": { "node_modules/collection-visit": {
"version": "1.0.0", "version": "1.0.0",
@ -13958,9 +13958,9 @@
} }
}, },
"codemirror": { "codemirror": {
"version": "5.59.0", "version": "5.59.2",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.59.0.tgz", "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.59.2.tgz",
"integrity": "sha512-UGzSkCacY9z0rSpQ3wnTWRN2nvRE6foDXnJltWW8pazInR/R+3gXHrao4IFQMv/bSBvFBxt8/HPpkpKAS54x5Q==" "integrity": "sha512-/D5PcsKyzthtSy2NNKCyJi3b+htRkoKv3idswR/tR6UAvMNKA7SrmyZy6fOONJxSRs1JlUWEDAbxqfdArbK8iA=="
}, },
"collection-visit": { "collection-visit": {
"version": "1.0.0", "version": "1.0.0",

View File

@ -6,7 +6,7 @@
"repository": "openstyles/stylus", "repository": "openstyles/stylus",
"author": "Stylus Team", "author": "Stylus Team",
"dependencies": { "dependencies": {
"codemirror": "5.59.0", "codemirror": "5.59.2",
"db-to-cloud": "^0.4.5", "db-to-cloud": "^0.4.5",
"jsonlint": "^1.6.3", "jsonlint": "^1.6.3",
"less-bundle": "github:openstyles/less-bundle#v0.1.0", "less-bundle": "github:openstyles/less-bundle#v0.1.0",

View File

@ -1,4 +1,4 @@
## codemirror v5.59.0 ## codemirror v5.59.2
Following files are copied from npm (node_modules): Following files are copied from npm (node_modules):

View File

@ -87,7 +87,7 @@
cm.operation(function() { cm.operation(function() {
var linesep = cm.lineSeparator() || "\n"; var linesep = cm.lineSeparator() || "\n";
cm.replaceSelection(linesep + linesep, null); cm.replaceSelection(linesep + linesep, null);
cm.execCommand("goCharLeft"); moveSel(cm, -1)
ranges = cm.listSelections(); ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) { for (var i = 0; i < ranges.length; i++) {
var line = ranges[i].head.line; 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) { function contractSelection(sel) {
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0; var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)), 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); var right = pos % 2 ? ch : pairs.charAt(pos + 1);
cm.operation(function() { cm.operation(function() {
if (type == "skip") { if (type == "skip") {
cm.execCommand("goCharRight"); moveSel(cm, 1)
} else if (type == "skipThree") { } else if (type == "skipThree") {
for (var i = 0; i < 3; i++) moveSel(cm, 3)
cm.execCommand("goCharRight");
} else if (type == "surround") { } else if (type == "surround") {
var sels = cm.getSelections(); var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++) for (var i = 0; i < sels.length; i++)
@ -169,10 +179,10 @@
} else if (type == "both") { } else if (type == "both") {
cm.replaceSelection(left + right, null); cm.replaceSelection(left + right, null);
cm.triggerElectric(left + right); cm.triggerElectric(left + right);
cm.execCommand("goCharLeft"); moveSel(cm, -1)
} else if (type == "addFour") { } else if (type == "addFour") {
cm.replaceSelection(left + left + left + left, "before"); 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; if (config && config.strict && (dir > 0) != (pos == where.ch)) return null;
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1)); 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; if (found == null) return null;
return {from: Pos(where.line, pos), to: found && found.pos, return {from: Pos(where.line, pos), to: found && found.pos,
match: found && found.ch == match.charAt(0), forward: dir > 0}; 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); if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
for (; pos != end; pos += dir) { for (; pos != end; pos += dir) {
var ch = line.charAt(pos); 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]; var match = matching[ch];
if (match && (match.charAt(1) == ">") == (dir > 0)) stack.push(ch); if (match && (match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch}; else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
@ -80,11 +81,12 @@
function matchBrackets(cm, autoclear, config) { function matchBrackets(cm, autoclear, config) {
// Disable brace matching in long lines, since it'll cause hugely slow updates // 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(); var marks = [], ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) { for (var i = 0; i < ranges.length; i++) {
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config); 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"; var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style})); 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) if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
@ -94,7 +96,7 @@
if (marks.length) { if (marks.length) {
// Kludge to work around the IE bug from issue #1193, where text // 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(); if (ie_lt8 && cm.state.focused) cm.focus();
var clear = function() { var clear = function() {

View File

@ -31,13 +31,16 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
} }
} }
var startToken = "{", endToken = "}", startCh = findOpening("{"); var startBrace = findOpening("{"), startBracket = findOpening("[")
if (startCh == null) { var startToken, endToken, startCh
startToken = "[", endToken = "]"; if (startBrace != null && (startBracket == null || startBracket > startBrace)) {
startCh = findOpening("["); startCh = startBrace; startToken = "{"; endToken = "}"
} else if (startBracket != null) {
startCh = startBracket; startToken = "["; endToken = "]"
} else {
return
} }
if (startCh == null) return;
var count = 1, lastLine = cm.lastLine(), end, endCh; var count = 1, lastLine = cm.lastLine(), end, endCh;
outer: for (var i = line; i <= lastLine; ++i) { outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0; var text = cm.getLine(i), pos = i == line ? startCh : 0;

View File

@ -61,9 +61,11 @@
this.startPos = this.cm.getCursor("start"); this.startPos = this.cm.getCursor("start");
this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length; this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
if (this.options.updateOnCursorActivity) {
var self = this; var self = this;
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); }); cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
} }
}
var requestAnimationFrame = window.requestAnimationFrame || function(fn) { var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
return setTimeout(fn, 1000/60); return setTimeout(fn, 1000/60);
@ -75,7 +77,9 @@
if (!this.active()) return; if (!this.active()) return;
this.cm.state.completionActive = null; this.cm.state.completionActive = null;
this.tick = null; this.tick = null;
if (this.options.updateOnCursorActivity) {
this.cm.off("cursorActivity", this.activityFunc); this.cm.off("cursorActivity", this.activityFunc);
}
if (this.widget && this.data) CodeMirror.signal(this.data, "close"); if (this.widget && this.data) CodeMirror.signal(this.data, "close");
if (this.widget) this.widget.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 || if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
pos.ch < identStart.ch || this.cm.somethingSelected() || pos.ch < identStart.ch || this.cm.somethingSelected() ||
(!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) { (!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
if (this.options.closeOnCursorActivity) {
this.close(); this.close();
}
} else { } else {
var self = this; var self = this;
this.debounce = requestAnimationFrame(function() {self.update();}); this.debounce = requestAnimationFrame(function() {self.update();});
@ -492,9 +494,9 @@
completeSingle: true, completeSingle: true,
alignWithWord: true, alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/, closeCharacters: /[\s()\[\]{};:>,]/,
closeOnCursorActivity: true,
closeOnPick: true, closeOnPick: true,
closeOnUnfocus: true, closeOnUnfocus: true,
updateOnCursorActivity: true,
completeOnSingleClick: true, completeOnSingleClick: true,
container: null, container: null,
customKeys: 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 mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
var phantom = /PhantomJS/.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); var android = /Android/.test(userAgent);
// This is woefully incomplete. Suggestions for alternative methods welcome. // This is woefully incomplete. Suggestions for alternative methods welcome.
var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent); 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); (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true)); 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); } { ensureCursorVisible(doc.cm); }
} }
@ -8675,10 +8675,13 @@
function moveOnce(boundToLine) { function moveOnce(boundToLine) {
var next; var next;
if (unit == "codepoint") { if (unit == "codepoint") {
var ch = lineObj.text.charCodeAt(pos.ch + (unit > 0 ? 0 : -1)); var ch = lineObj.text.charCodeAt(pos.ch + (dir > 0 ? 0 : -1));
if (isNaN(ch)) { next = null; } if (isNaN(ch)) {
else { next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (ch >= 0xD800 && ch < 0xDC00 ? 2 : 1))), next = null;
-dir); } } 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) { } else if (visually) {
next = moveVisually(doc.cm, lineObj, pos, dir); next = moveVisually(doc.cm, lineObj, pos, dir);
} else { } else {
@ -9790,7 +9793,7 @@
addLegacyProps(CodeMirror); addLegacyProps(CodeMirror);
CodeMirror.version = "5.59.0"; CodeMirror.version = "5.59.2";
return CodeMirror; return CodeMirror;

View File

@ -78,8 +78,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
return ret("qualifier", "qualifier"); return ret("qualifier", "qualifier");
} else if (/[:;{}\[\]\(\)]/.test(ch)) { } else if (/[:;{}\[\]\(\)]/.test(ch)) {
return ret(null, ch); return ret(null, ch);
} else if (stream.match(/[\w-.]+(?=\()/)) { } else if (stream.match(/^[\w-.]+(?=\()/)) {
if (/^(url(-prefix)?|domain|regexp)$/.test(stream.current().toLowerCase())) { if (/^(url(-prefix)?|domain|regexp)$/i.test(stream.current())) {
state.tokenize = tokenParenthesized; state.tokenize = tokenParenthesized;
} }
return ret("variable callee", "variable"); return ret("variable callee", "variable");
@ -108,7 +108,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
function tokenParenthesized(stream, state) { function tokenParenthesized(stream, state) {
stream.next(); // Must be '(' stream.next(); // Must be '('
if (!stream.match(/\s*[\"\')]/, false)) if (!stream.match(/^\s*[\"\')]/, false))
state.tokenize = tokenString(")"); state.tokenize = tokenString(")");
else else
state.tokenize = null; state.tokenize = null;
@ -781,7 +781,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
} }
}, },
":": function(stream) { ":": function(stream) {
if (stream.match(/\s*\{/, false)) if (stream.match(/^\s*\{/, false))
return [null, null] return [null, null]
return false; return false;
}, },

View File

@ -624,7 +624,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == "=>") return cont(typeexpr) if (type == "=>") return cont(typeexpr)
} }
function typeprops(type) { function typeprops(type) {
if (type == "}") return cont() if (type.match(/[\}\)\]]/)) return cont()
if (type == "," || type == ";") return cont(typeprops) if (type == "," || type == ";") return cont(typeprops)
return pass(typeprop, typeprops) return pass(typeprop, typeprops)
} }
@ -640,6 +640,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
return cont(expect("variable"), maybetypeOrIn, expect("]"), typeprop) return cont(expect("variable"), maybetypeOrIn, expect("]"), typeprop)
} else if (type == "(") { } else if (type == "(") {
return pass(functiondecl, typeprop) return pass(functiondecl, typeprop)
} else if (!type.match(/[;\}\)\],]/)) {
return cont()
} }
} }
function typearg(type, value) { function typearg(type, value) {
@ -932,6 +934,7 @@ CodeMirror.defineMIME("application/x-javascript", "javascript");
CodeMirror.defineMIME("application/ecmascript", "javascript"); CodeMirror.defineMIME("application/ecmascript", "javascript");
CodeMirror.defineMIME("application/json", { name: "javascript", json: true }); CodeMirror.defineMIME("application/json", { name: "javascript", json: true });
CodeMirror.defineMIME("application/x-json", { name: "javascript", json: true }); CodeMirror.defineMIME("application/x-json", { name: "javascript", json: true });
CodeMirror.defineMIME("application/manifest+json", { name: "javascript", json: true })
CodeMirror.defineMIME("application/ld+json", { name: "javascript", jsonld: true }); CodeMirror.defineMIME("application/ld+json", { name: "javascript", jsonld: true });
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true }); CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });

View File

@ -138,7 +138,7 @@
// Variable // Variable
if (stream.match(/^(\.|\[)[\w-\'\"\]]+/i, false)) { if (stream.match(/^(\.|\[)[\w-\'\"\]]+/i, false)) {
if (!wordIsTag(stream.current())) { if (!wordIsTag(stream.current())) {
stream.match(/\./); stream.match('.');
return ["variable-2", "variable-name"]; return ["variable-2", "variable-name"];
} }
} }