Skip to content

Commit

Permalink
fix(wikieditor-highlight-cm6): avoid reusing global CodeMirror
Browse files Browse the repository at this point in the history
- 对Widget模式进行了一些更新
- 忽略一些false positive的语法错误
  • Loading branch information
bhsd-harry committed Jan 15, 2024
1 parent 5fbcee9 commit 5d4ee96
Showing 1 changed file with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@
const isAdvanced = ["loading", "loaded", "executing", "ready"].includes(mw.loader.getState("ext.wikiEditor"));
const ns = mw.config.get("wgNamespaceNumber");
const lang = ns === 274 ? "html" : "mediawiki";
const init = () => new Promise((resolve) => {
const script = document.createElement("script");
script.addEventListener("load", async () => {
cm = await CodeMirror.fromTextArea($textarea[0], lang);
cm.prefer([
"highlightSpecialChars",
"highlightActiveLine",
"highlightWhitespace",
"bracketMatching",
"closeBrackets",
]);
const [config] = await Promise.all([
libCachedCode.getCachedCode("https://testingcf.jsdelivr.net/npm/wikiparser-node/config/moegirl.json"),
cm.defaultLint(true, {include: ns === 10}),
]);
try {
window.wikiparse.setConfig(JSON.parse(config));
} catch (e) {
console.error(e);
}
resolve();
});
script.type = "module";
script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/[email protected]/mw/dist/base.min.js";
document.head.append(script);
});
const init = async () => {
if (!window.CodeMirror6) {
await new Promise((resolve) => {
const script = document.createElement("script");
script.addEventListener("load", resolve);
script.type = "module";
script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/[email protected]/mw/dist/base.min.js";
document.head.append(script);
});
}
cm = await window.CodeMirror6.fromTextArea($textarea[0], lang);
cm.prefer([
"highlightSpecialChars",
"highlightActiveLine",
"highlightWhitespace",
"bracketMatching",
"closeBrackets",
]);
const [config] = await Promise.all([
libCachedCode.getCachedCode("https://testingcf.jsdelivr.net/npm/wikiparser-node/config/moegirl.json"),
cm.defaultLint(true, {include: ns === 10}),
]);
try {
window.wikiparse?.setConfig(JSON.parse(config));
} catch (e) {
console.error(e);
}
};
if (!isAdvanced) {
init();
return;
Expand Down

0 comments on commit 5d4ee96

Please sign in to comment.