Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wikieditor-highlight-cm6): avoid reusing global CodeMirror #397

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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