Skip to content

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

:sparkles: Hide mobile font picker sheet actions https://github.com/siyuan-note/siyuan/issues/20557

Daniel164fd7ea3979
diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts
index 01c47cb65e..05640af92c 100644
--- a/app/src/menus/Menu.ts
+++ b/app/src/menus/Menu.ts
@@ -622,6 +622,7 @@ export class Menu {
setPopoverMenuOpen(this.element, false);
this.element.classList.remove("b3-menu--list", "b3-menu--fullscreen", "b3-menu--sheet", "b3-menu--fit", "b3-menu--expanded");
this.element.removeAttribute("data-sheet-expandable");
+ this.element.removeAttribute("data-sheet-actions");
this.element.removeAttribute("style"); // zIndex
this.element.removeAttribute("data-name"); // 标识再次点击不消失
this.element.removeAttribute("data-from"); // 标识菜单入口
@@ -789,7 +790,8 @@ export class Menu {
this.element.querySelectorAll(":scope > .b3-menu__items, .b3-menu__submenu > .b3-menu__items")
.forEach(updateMenuItemGroupClasses);
this.element.classList.add("b3-menu--fullscreen", "b3-menu--sheet");
- if (this.element.getAttribute("data-sheet-expandable") === "true") {
+ if (this.element.getAttribute("data-sheet-expandable") === "true" &&
+ this.element.getAttribute("data-sheet-actions") !== "false") {
this.element.firstElementChild.classList.add("b3-menu__title--actions");
if (!this.element.firstElementChild.querySelector(".b3-menu__actions")) {
this.element.firstElementChild.insertAdjacentHTML("beforeend", getSheetActionsHTML());
diff --git a/app/src/protyle/toolbar/fontFamilyMenu.test.ts b/app/src/protyle/toolbar/fontFamilyMenu.test.ts
index ff48008bef..e349774bfc 100644
--- a/app/src/protyle/toolbar/fontFamilyMenu.test.ts
+++ b/app/src/protyle/toolbar/fontFamilyMenu.test.ts
@@ -89,7 +89,6 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
const dependencies = {
getCurrentEditor: () => ({protyle: current}),
getFontNodeElements: () => [editor],
- getFontFamilyState: () => ({disabled: false, mixed: false, family: undefined as string | undefined}),
preventKeyboardToolbarRender() {},
...api,
fontEvent: (_owner: unknown, _nodes: unknown, _style: string, value: string) => applied.push(value),
@@ -119,6 +118,11 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
await settle();
};
const search = () => menuElement.querySelector<HTMLInputElement>('[data-type="font-family-search"]');
+ const swipeDown = async () => {
+ const rect = menuElement.firstElementChild.getBoundingClientRect();
+ await require("electron").ipcRenderer.invoke("font-swipe", rect.left + rect.width / 2, rect.top + rect.height / 2);
+ await settle();
+ };
for (const theme of themes) {
themeStyle.textContent = theme;
for (const size of [320, 420]) {
@@ -137,11 +141,14 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
check.ok(menuElement.classList.contains("b3-menu--sheet"));
check.equal(button.getAttribute("aria-expanded"), "true");
check.equal(menuElement.querySelector('[data-action="fontFamilyBack"]'), null);
+ check.equal(menuElement.querySelector('[data-type="sheet-expand"]'), null, "font sheet has no fullscreen button");
+ check.equal(menuElement.querySelector('[data-type="sheet-close"]'), null, "font sheet has no close button");
+ check.equal(menuElement.getAttribute("data-sheet-expandable"), "true", "gesture and viewport behavior remain enabled");
check.ok(util.contains(button), "font list opens outside the original appearance panel");
check.notEqual(document.activeElement, search(), "opening does not summon the search keyboard");
check.ok(menuElement.getBoundingClientRect().top > 100, "font sheet opens from the bottom");
- await tap(menuElement.querySelector('[data-type="sheet-close"]'));
- check.ok(menuElement.classList.contains("fn__none"), "a real touch closes the sheet");
+ await swipeDown();
+ check.ok(menuElement.classList.contains("fn__none"), "a downward touch gesture closes the font sheet");
check.ok(util.contains(button));
check.equal(button.getAttribute("aria-expanded"), "false");
await tap(button);
@@ -149,6 +156,11 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
check.equal(document.activeElement, search());
controls.showKeyboardToolbarElement();
controls.hideKeyboardToolbarUtilOnEditorClick();
+ await require("electron").ipcRenderer.invoke("font-resize", 350);
+ await settle();
+ check.equal(menuElement.style.height, "350px", "font sheet still tracks the available viewport while searching");
+ check.ok(search().getBoundingClientRect().top >= menuElement.getBoundingClientRect().top);
+ check.ok(search().getBoundingClientRect().bottom <= innerHeight);
search().value = "Font 12";
search().dispatchEvent(new InputEvent("input", {bubbles: true}));
const visible = menuElement.querySelectorAll('[role="option"]:not(.fn__none)');
@@ -159,6 +171,8 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
check.match(applied[0], /Font 12/);
check.equal(restored, 0, "appearance selection does not reopen the editor keyboard");
check.equal(button.querySelector("span").textContent, "Font 12");
+ await require("electron").ipcRenderer.invoke("font-resize", 850);
+ await settle();
await tap(button);
search().dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true}));
await settle();
@@ -170,7 +184,7 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
pendingFonts = new Promise(done => { resolve = done; });
const opening = api.openFontFamilyMenu(button, {disabled: false, mixed: false, onSelect() {}});
await settle();
- await tap(menuElement.querySelector('[data-type="sheet-close"]'));
+ await tap(scrim);
resolve({fontItems: fonts});
await opening;
check.ok(menuElement.classList.contains("fn__none"));
@@ -197,7 +211,9 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
toolbar.addEventListener("click", controls.handler);
await tap(button);
check.ok(menuElement.classList.contains("b3-menu--sheet"), "click-based mobile entry opens the same font sheet");
- await tap(menuElement.querySelector('[data-type="sheet-close"]'));
+ menuElement.dispatchEvent(new CustomEvent("click", {detail: "back"}));
+ await settle();
+ check.ok(menuElement.classList.contains("fn__none"), "system back closes the font sheet without action buttons");
toolbar.removeEventListener("click", controls.handler);
mobile = false;
fonts = [];
@@ -207,10 +223,19 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stri
search().dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true}));
check.equal(document.activeElement, button, "desktop Escape returns focus to the dropdown");
check.ok(menuElement.classList.contains("fn__none"));
+ check.equal(menuElement.hasAttribute("data-sheet-actions"), false, "closing clears the font-only action preference");
+ mobile = true;
+ menuElement.setAttribute("data-sheet-expandable", "true");
+ menu.addItem({label: "Other menu"});
+ menu.fullscreen("bottom");
+ await settle();
+ check.ok(menuElement.querySelector('[data-type="sheet-expand"]'), "other expandable menus keep their fullscreen button");
+ await tap(menuElement.querySelector('[data-type="sheet-close"]'));
+ check.ok(menuElement.classList.contains("fn__none"));
return "Font menu touch and layout cases passed";
};
-test("font menus preserve the mobile appearance panel and support real touch dismissal, search and selection", {timeout: 45000}, async () => {
+test("font menus hide action buttons while preserving gesture dismissal, search viewport and selection", {timeout: 45000}, async () => {
const names = ["menus/Menu", "menus/menuPosition", "menus/menuMouseScroll", "menus/menuGroup", "menus/sheetOpen", "menus/sheetActions",
"menus/menuToggle", "plugin/Menu", "util/setPosition", "protyle/util/hasClosest", "protyle/toolbar/fontFamilyMenu",
"protyle/toolbar/fontFamilyCore", "util/systemFontCore", "util/escape", "util/upDownHint"];
@@ -250,6 +275,12 @@ app.whenReady().then(async () => {
await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent", {type:"touchStart", touchPoints:[{x,y}]});
await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent", {type:"touchEnd", touchPoints:[]});
});
+ ipcMain.handle("font-swipe", async (_event, x, y) => {
+ await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent", {type:"touchStart", touchPoints:[{x,y}]});
+ await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent", {type:"touchMove", touchPoints:[{x,y:y+150}]});
+ await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent", {type:"touchEnd", touchPoints:[]});
+ });
+ ipcMain.handle("font-resize", (_event, height) => win.setContentSize(420, height));
try {
await win.loadURL("about:blank");
await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled", {enabled:true, maxTouchPoints:1});
diff --git a/app/src/protyle/toolbar/fontFamilyMenu.ts b/app/src/protyle/toolbar/fontFamilyMenu.ts
index 0534975680..d44332bc0e 100644
--- a/app/src/protyle/toolbar/fontFamilyMenu.ts
+++ b/app/src/protyle/toolbar/fontFamilyMenu.ts
@@ -304,6 +304,7 @@ export const openFontFamilyMenu = async (target: HTMLElement, options: IFontFami
const mobile = isMobile();
if (mobile) {
menu.element.setAttribute("data-sheet-expandable", "true");
+ menu.element.setAttribute("data-sheet-actions", "false");
pickerElement.style.height = "100%";
}
const openMenu = () => {