Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/16115

Vanessa063a877d9258
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index b4f7238294..91b516208c 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -12,6 +12,7 @@ export class Font extends ToolbarItem {
constructor(protyle: IProtyle, menuItem: IMenuItem) {
super(protyle, menuItem);
this.element.addEventListener("click", () => {
+ const triggerRect = this.element.getBoundingClientRect();
protyle.toolbar.element.classList.add("fn__none");
protyle.toolbar.subElement.innerHTML = "";
protyle.toolbar.subElement.style.width = "";
@@ -22,7 +23,7 @@ export class Font extends ToolbarItem {
protyle.toolbar.subElementCloseCB = undefined;
focusByRange(protyle.toolbar.range);
/// #if !MOBILE
- protyle.toolbar.setSelectionElementPosition(protyle, protyle.toolbar.subElement);
+ protyle.toolbar.setSelectionElementPosition(protyle, protyle.toolbar.subElement, triggerRect);
/// #endif
});
}
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 8c08a8c7c7..88470f2edb 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -192,7 +192,7 @@ export class Toolbar {
});
}
- public setSelectionElementPosition(protyle: IProtyle, element: HTMLElement) {
+ public setSelectionElementPosition(protyle: IProtyle, element: HTMLElement, triggerRect?: DOMRect) {
if (!this.rangePosition || !this.range) {
return;
}
@@ -211,7 +211,11 @@ export class Toolbar {
(above >= protyleRect.top + 30 ?
above : Math.min(below, protyleRect.bottom - element.clientHeight));
const horizontalDivisor = this.isMultipleClick ? 3 : 4;
- setPosition(element, this.rangePosition.left - element.clientWidth / horizontalDivisor, y);
+ // 子面板与触发按钮水平居中,垂直方向继续避让选区
+ const left = triggerRect ?
+ triggerRect.left + (triggerRect.width - element.clientWidth) / 2 :
+ this.rangePosition.left - element.clientWidth / horizontalDivisor;
+ setPosition(element, left, y);
return y;
}