Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Hide mobile font toolbar entries by default while respecting configuration https://github.com/siyuan-note/siyuan/issues/19273

Daniele7524533a6b6
diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.ts
index d41280b75a..0519e93129 100644
--- a/app/src/config/entryVisibility/catalog.ts
+++ b/app/src/config/entryVisibility/catalog.ts
@@ -476,7 +476,10 @@ const toolbarBuiltinChildren = DESKTOP_TOOLBAR_ENTRIES.map((item) => {
}
const fontControl = ["font-family", "font-size"].includes(item.key);
return node(item.key, lang(item.lang), !fontControl, undefined, undefined,
- fontControl ? {customDefaultVisible: false} : undefined);
+ fontControl ? {
+ defaultVisible: () => typeof window === "undefined" || !window.siyuan.mobile,
+ customDefaultVisible: false,
+ } : undefined);
});
const toolbarBuiltinNodeMap = new Map(toolbarBuiltinChildren.map((item) => [item.key, item]));
diff --git a/app/src/config/entryVisibility/profile.test.ts b/app/src/config/entryVisibility/profile.test.ts
index b96ac2d676..d92b423cb1 100644
--- a/app/src/config/entryVisibility/profile.test.ts
+++ b/app/src/config/entryVisibility/profile.test.ts
@@ -27,6 +27,32 @@ test("font toolbar entries are visible in Full, hidden in Simple and preserve ex
assert.equal(getEntryCatalogCustomDefaultVisibility(`${TOOLBAR_ENTRY_ROOT_PATH}.text`), true);
});
+test("mobile font entries default to hidden and preserve explicit profile choices", () => {
+ const descriptor = Object.getOwnPropertyDescriptor(globalThis, "window");
+ Object.defineProperty(globalThis, "window", {configurable: true, value: {siyuan: {mobile: {}}}});
+ try {
+ for (const key of ["font-family", "font-size"]) {
+ const path = `${TOOLBAR_ENTRY_ROOT_PATH}.${key}`;
+ const defaultVisible = getEntryCatalogDefaultVisibility(path);
+ const entry = getEntryCatalogNode(path);
+ assert.equal(defaultVisible, false);
+ assert.equal(getBuiltinProfileEntryVisibility("full", entry.simple, defaultVisible), false);
+ assert.equal(getBuiltinProfileEntryVisibility("simple", entry.simple, defaultVisible), false);
+ const customDefaultVisible = getEntryCatalogCustomDefaultVisibility(path);
+ assert.equal(getProfileEntryVisibility({entries: {}}, path, customDefaultVisible), false);
+ assert.equal(getProfileEntryVisibility({entries: {[path]: true}}, path, customDefaultVisible), true);
+ assert.equal(getProfileEntryVisibility({entries: {[path]: false}}, path, customDefaultVisible), false);
+ }
+ assert.equal(getEntryCatalogDefaultVisibility(`${TOOLBAR_ENTRY_ROOT_PATH}.text`), true);
+ } finally {
+ if (descriptor) {
+ Object.defineProperty(globalThis, "window", descriptor);
+ } else {
+ Reflect.deleteProperty(globalThis, "window");
+ }
+ }
+});
+
test("built-in profiles honor entry defaults", () => {
assert.equal(getBuiltinProfileEntryVisibility("full", false, true), true);
assert.equal(getBuiltinProfileEntryVisibility("full", true, false), false);
diff --git a/app/src/mobile/util/toolbarEntries.test.ts b/app/src/mobile/util/toolbarEntries.test.ts
index 39d1a03b02..558c6f2cee 100644
--- a/app/src/mobile/util/toolbarEntries.test.ts
+++ b/app/src/mobile/util/toolbarEntries.test.ts
@@ -46,6 +46,28 @@ test("mobile toolbar keeps navigation reachable and removes empty separators", (
assert.deepEqual(root.children.filter(item => !item.classList.contains("fn__none")), [back, size, first, family]);
});
+test("mobile toolbar follows font visibility changes while preserving formatting entries", () => {
+ const root = new ToolbarElement();
+ const back = new ToolbarElement("goback");
+ const family = new ToolbarElement("font-family");
+ const size = new ToolbarElement("font-size");
+ const appearance = new ToolbarElement("text");
+ const bold = new ToolbarElement("strong");
+ const separator = new ToolbarElement(undefined, "separator_1");
+ root.children = [back, family, size, separator, appearance, bold];
+ applyMobileToolbarEntries(root as unknown as HTMLElement, getDefaultToolbar(true), {
+ order: ["font-family", "font-size", "separator_1", "text", "strong"],
+ isVisible: key => !["font-family", "font-size"].includes(key),
+ });
+ assert.deepEqual(root.children.filter(item => !item.classList.contains("fn__none")), [back, appearance, bold]);
+ applyMobileToolbarEntries(root as unknown as HTMLElement, getDefaultToolbar(true), {
+ order: ["font-family", "font-size", "separator_1", "text", "strong"],
+ isVisible: () => true,
+ });
+ assert.deepEqual(root.children.filter(item => !item.classList.contains("fn__none")),
+ [back, family, size, separator, appearance, bold]);
+});
+
test("mobile toolbar applies plugin visibility and restores its configured order", () => {
const defaults = getDefaultToolbar(true);
const plugin = {name: "plugin-action"};