Skip to content

Commit

Permalink
feat(wikieditor-highlight): default addons
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Jan 13, 2024
1 parent 2d8b60c commit 08a4081
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
// 本页面大部分内容均直接或间接修改自[[MW:Extension:CodeMirror]]
(async () => {
await $.ready;
if (!["edit", "submit"].includes(mw.config.get("wgAction")) || mw.config.get("wgPageContentModel") !== "wikitext") {
return;
}
await $.ready;

const localObjectStorage = new LocalObjectStorage("wikieditor-highlight");
let cm, state = localObjectStorage.getItem("wikieditor-codemirror", false);
Expand All @@ -15,32 +15,32 @@
await import("https://testingcf.jsdelivr.net/npm/@bhsd/[email protected]/mw/dist/base.min.js");
cm = await CodeMirror.fromTextArea($textarea[0], lang);
cm.defaultLint(true);
cm.prefer([
"highlightSpecialChars",
"highlightActiveLine",
"highlightWhitespace",
"bracketMatching",
"closeBrackets",
]);
};
if (state === null || !isAdvanced) {
state = true;
}
if (!isAdvanced) {
init();
return;
} else if (state === null || !isAdvanced) {
state = true;
}
const btn = new OO.ui.ButtonWidget({
classes: ["tool"], icon: "highlight", framed: false, title: "代码高亮开关",
}).on("click", async () => {
if (!cm) {
if (cm) {
cm.toggle();
} else {
await init();
}
// eslint-disable-next-line no-use-before-define
update();
});
const shared = () => {
btn.$element.toggleClass("tool-active");
cm.toggle();
};
const update = () => {
state = !state;
localObjectStorage.setItem("wikieditor-codemirror", state);
shared();
};
});
const group = $("#wikiEditor-section-main > .group-insert")[0];
$textarea.on("wikiEditor-toolbar-doneInitialSections", () => {
btn.$element.appendTo("#wikiEditor-section-main > .group-insert");
Expand All @@ -51,6 +51,6 @@
if (state) {
await mw.loader.using("ext.wikiEditor");
await init();
shared();
btn.$element.addClass("tool-active");
}
})();

0 comments on commit 08a4081

Please sign in to comment.