Skip to content

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

:bug: Fix font menu initial opening and window overflow https://github.com/siyuan-note/siyuan/issues/19289

Danieled9552441b04
diff --git a/app/src/protyle/toolbar/fontControls.ts b/app/src/protyle/toolbar/fontControls.ts
index 45414924fa..4faf6d4787 100644
--- a/app/src/protyle/toolbar/fontControls.ts
+++ b/app/src/protyle/toolbar/fontControls.ts
@@ -113,6 +113,7 @@ export class FontControl extends ToolbarItem {
this.element.innerHTML = '<span class="protyle-toolbar__font-label"></span><svg aria-hidden="true"><use xlink:href="#iconDown"></use></svg>';
this.element.querySelector(".protyle-toolbar__font-label").textContent = window.siyuan.languages[item.lang];
this.element.setAttribute("aria-haspopup", "true");
+ this.element.setAttribute("data-menu", "true");
this.element.addEventListener("mousedown", event => event.preventDefault());
this.element.addEventListener("click", () => {
closeSubElement(protyle.toolbar);
diff --git a/app/src/protyle/toolbar/fontFamilyMenu.ts b/app/src/protyle/toolbar/fontFamilyMenu.ts
index 209b4f3023..0fc14b04e4 100644
--- a/app/src/protyle/toolbar/fontFamilyMenu.ts
+++ b/app/src/protyle/toolbar/fontFamilyMenu.ts
@@ -303,7 +303,7 @@ export const openFontFamilyMenu = async (target: HTMLElement, options: IFontFami
desktopMenuIDs.set(target, `inlineFontFamily${requestID}`);
}
let closed = false;
- let cleanup: () => void;
+ let cleanup: () => void = undefined;
const menu = new Menu(desktopMenuIDs.get(target), () => {
closed = true;
cleanup?.();
@@ -312,6 +312,17 @@ export const openFontFamilyMenu = async (target: HTMLElement, options: IFontFami
if (menu.isOpen) {
return;
}
+ const pickerElement = menu.addItem({
+ iconHTML: "",
+ type: "empty",
+ label: `<div class="b3-menu__filter">${escapeHtml(window.siyuan.languages.loading)}</div>`,
+ });
+ const openMenu = () => {
+ const rect = target.getBoundingClientRect();
+ menu.open({x: rect.left, y: rect.bottom, h: rect.height, w: rect.width, target});
+ };
+ target.setAttribute("aria-expanded", "true");
+ openMenu();
const fonts = await loadFontFamilies(options.family);
if (closed) {
return;
@@ -323,25 +334,16 @@ export const openFontFamilyMenu = async (target: HTMLElement, options: IFontFami
if (target.tagName === "INPUT") {
(target as HTMLInputElement).value = getInlineFontFamilyLabel(options);
}
- menu.addItem({
- iconHTML: "",
- type: "empty",
- label: genFontPickerHTML(fonts, options, false),
- bind(element) {
- cleanup = bindFontPicker(element, {
- ...options,
- onClose: () => target.focus(),
- onSelect(family) {
- menu.close();
- options.onSelect(family);
- }
- });
+ pickerElement.innerHTML = genFontPickerHTML(fonts, options, false);
+ cleanup = bindFontPicker(pickerElement, {
+ ...options,
+ onClose: () => target.focus(),
+ onSelect(family) {
+ menu.close();
+ options.onSelect(family);
}
});
- const rect = target.getBoundingClientRect();
- target.setAttribute("aria-expanded", "true");
- menu.open({x: rect.left, y: rect.bottom, h: rect.height, w: rect.width, target});
- menu.element.querySelector(".b3-menu__items")?.setAttribute("style", "overflow: initial");
+ openMenu();
menu.element.querySelector<HTMLInputElement>('[data-type="font-family-search"]')?.focus();
};