From 0e392c9deaff6ef7cf95c18c7c77f14d32e404b5 Mon Sep 17 00:00:00 2001 From: MassiveBox Date: Sun, 19 Oct 2025 21:50:42 +0200 Subject: [PATCH] Reorganize document menus --- public/i18n/en_US.json | 1 + src/menus.ts | 45 ++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/public/i18n/en_US.json b/public/i18n/en_US.json index 1e4a48f..ab4e6f6 100644 --- a/public/i18n/en_US.json +++ b/public/i18n/en_US.json @@ -1,4 +1,5 @@ { + "syspell": "SySpell", "settings":{ "info": { "title": "Information", diff --git a/src/menus.ts b/src/menus.ts index 6e89181..0651e1b 100644 --- a/src/menus.ts +++ b/src/menus.ts @@ -3,6 +3,7 @@ import SpellCheckPlugin from "@/index"; import {getBlockAttrs, setBlockAttrs} from "@/api"; import {Settings} from "@/settings"; import {ProtyleHelper} from "@/protyleHelper"; +import {Analytics} from "@/analytics"; export class Menus { @@ -67,7 +68,9 @@ export class Menus { public async addSettingsToDocMenu(docID: string, menu: subMenu) { - menu.addItem({ + let submenu = [] + + submenu.push({ icon: 'info', label: this.plugin.i18nx.docMenu.documentStatus, click: async () => { @@ -86,7 +89,7 @@ export class Menus { } }) - menu.addItem({ + submenu.push({ icon: 'toggle', label: this.plugin.i18nx.docMenu.toggleSpellCheck, click: async () => { @@ -104,7 +107,17 @@ export class Menus { } }) - menu.addItem({ + async function setLang(lang: string, analytics: Analytics) { + const attrs = await getBlockAttrs(docID) + attrs[SpellCheckPlugin.LANGUAGE_ATTR] = lang + await setBlockAttrs(docID, attrs) + void analytics.sendEvent('docmenu-click-setlang-2', { + 'language': lang + }); + location.reload() + } + + submenu.push({ icon: 'language', label: this.plugin.i18nx.docMenu.setDocumentLanguage, click: async (_, ev: MouseEvent) => { @@ -114,29 +127,13 @@ export class Menus { langMenu.addItem({ icon: 'autodetect', label: this.plugin.i18nx.docMenu.autodetectLanguage, - click: async () => { - const attrs = await getBlockAttrs(docID) - attrs[SpellCheckPlugin.LANGUAGE_ATTR] = 'auto' - await setBlockAttrs(docID, attrs) - void this.plugin.analytics.sendEvent('docmenu-click-setlang-2', { - 'language': 'auto' - }); - location.reload() - } + click: async () => setLang('auto', this.plugin.analytics) }); languages.forEach(language => { langMenu.addItem({ icon: 'language', label: language.name + ' [' + language.longCode + ']', - click: async () => { - const attrs = await getBlockAttrs(docID) - attrs[SpellCheckPlugin.LANGUAGE_ATTR] = language.longCode - await setBlockAttrs(docID, attrs) - void this.plugin.analytics.sendEvent('docmenu-click-setlang-2', { - 'language': language.longCode - }); - location.reload() - } + click: async () => setLang(language.longCode, this.plugin.analytics) }); }); langMenu.open({ x: ev.clientX, y: ev.clientY }); @@ -144,6 +141,12 @@ export class Menus { } }) + menu.addItem({ + icon: 'spellcheck', + label: this.plugin.i18nx.syspell, + submenu: submenu + }) + } } \ No newline at end of file