From 08a40819bce21db00eb5aa60c071b2736f265156 Mon Sep 17 00:00:00 2001 From: bhsd <2545473905@qq.com> Date: Sat, 13 Jan 2024 22:35:22 +0800 Subject: [PATCH] feat(wikieditor-highlight): default addons --- .../MediaWiki:Gadget-wikieditor-highlight.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js b/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js index ba9c8c71..06f52bf3 100644 --- a/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js +++ b/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js @@ -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); @@ -15,32 +15,32 @@ await import("https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.2/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"); @@ -51,6 +51,6 @@ if (state) { await mw.loader.using("ext.wikiEditor"); await init(); - shared(); + btn.$element.addClass("tool-active"); } })();