Skip to content

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

:bug: fix https://github.com/siyuan-note/siyuan/issues/5956

Vanessad521ebde4fb0
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index 218895e35a..852911fd21 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -3,6 +3,7 @@ import {ToolbarItem} from "./ToolbarItem";
import {setPosition} from "../../util/setPosition";
import {getSelectionPosition} from "../util/selection";
import {Constants} from "../../constants";
+import {hasClosestByAttribute} from "../util/hasClosest";
export class Font extends ToolbarItem {
public element: HTMLElement;
@@ -70,8 +71,11 @@ export const fontMenu = (protyle: IProtyle) => {
});
lastColorHTML += "</div>";
}
- const textElement = protyle.toolbar.range.cloneContents().querySelector('[data-type~="text"]') as HTMLElement;
+ let textElement = protyle.toolbar.range.cloneContents().querySelector('[data-type~="text"]') as HTMLElement;
let fontSize = "16px";
+ if (!textElement) {
+ textElement = hasClosestByAttribute(protyle.toolbar.range.startContainer, "data-type", "text") as HTMLElement;
+ }
if (textElement) {
fontSize = textElement.style.fontSize;
}