Skip to content

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

:art: Improve database text cell editor positioning https://github.com/siyuan-note/siyuan/issues/19685

Daniel61757e3c21d7
diff --git a/app/src/protyle/render/av/richTextEditorPosition.test.ts b/app/src/protyle/render/av/richTextEditorPosition.test.ts
index d1f8f56161..1ebfd62d2f 100644
--- a/app/src/protyle/render/av/richTextEditorPosition.test.ts
+++ b/app/src/protyle/render/av/richTextEditorPosition.test.ts
@@ -71,28 +71,30 @@ describe("attribute view rich-text editor positioning", () => {
}
});
- it("places the measured panel directly above a low cell", () => {
+ it("overlays a low cell while keeping the measured panel inside the window", () => {
const panel = createPanel(240);
const anchor = createAnchor({left: 551, top: 412, width: 199, height: 32});
positionAVRichTextEditor(panel as unknown as HTMLElement, anchor);
assert.equal(panel.style.left, "551px");
- assert.equal(panel.style.top, "172px");
+ assert.equal(panel.style.top, "300px");
assert.equal(panel.style.width, "420px");
assert.equal(panel.style.maxHeight, "480px");
- assert.equal(panel.getBoundingClientRect().bottom, anchor.getBoundingClientRect().top);
+ assert.equal(panel.getBoundingClientRect().bottom, window.innerHeight);
+ assert.ok(panel.getBoundingClientRect().top <= anchor.getBoundingClientRect().top);
+ assert.ok(panel.getBoundingClientRect().bottom >= anchor.getBoundingClientRect().bottom);
});
- it("places the panel directly below a cell when it fits", () => {
+ it("aligns the panel with the top of a cell when it fits", () => {
Object.assign(window, {innerWidth: 1000, innerHeight: 800});
const panel = createPanel(240);
const anchor = createAnchor({left: 100, top: 100, width: 150, height: 32});
positionAVRichTextEditor(panel as unknown as HTMLElement, anchor);
- assert.equal(panel.style.top, "132px");
- assert.equal(panel.getBoundingClientRect().top, anchor.getBoundingClientRect().bottom);
+ assert.equal(panel.style.top, "100px");
+ assert.equal(panel.getBoundingClientRect().top, anchor.getBoundingClientRect().top);
});
it("keeps horizontal margins and follows changes to the measured panel height", () => {
@@ -102,11 +104,13 @@ describe("attribute view rich-text editor positioning", () => {
positionAVRichTextEditor(panel as unknown as HTMLElement, anchor);
assert.equal(panel.style.left, "172px");
- assert.equal(panel.style.top, "172px");
+ assert.equal(panel.style.top, "300px");
panel.height = 300;
positionAVRichTextEditor(panel as unknown as HTMLElement, anchor);
- assert.equal(panel.style.top, "112px");
- assert.equal(panel.getBoundingClientRect().bottom, anchor.getBoundingClientRect().top);
+ assert.equal(panel.style.top, "240px");
+ assert.equal(panel.getBoundingClientRect().bottom, window.innerHeight);
+ assert.ok(panel.getBoundingClientRect().top <= anchor.getBoundingClientRect().top);
+ assert.ok(panel.getBoundingClientRect().bottom >= anchor.getBoundingClientRect().bottom);
});
});
diff --git a/app/src/protyle/render/av/richTextEditorPosition.ts b/app/src/protyle/render/av/richTextEditorPosition.ts
index bfd36556ac..4c68cc808b 100644
--- a/app/src/protyle/render/av/richTextEditorPosition.ts
+++ b/app/src/protyle/render/av/richTextEditorPosition.ts
@@ -10,5 +10,7 @@ export const positionAVRichTextEditor = (panelElement: HTMLElement, anchorElemen
window.innerWidth - width - AV_RICH_TEXT_EDITOR_MARGIN);
panelElement.style.width = `${width}px`;
panelElement.style.maxHeight = `${maxHeight}px`;
- setPosition(panelElement, left, anchorRect.bottom, anchorRect.height, AV_RICH_TEXT_EDITOR_MARGIN);
+ // 浮层覆盖单元格,底部空间不足时仅上移到窗口内。
+ const top = Math.min(anchorRect.top, window.innerHeight - panelElement.getBoundingClientRect().height);
+ setPosition(panelElement, left, top, 0, AV_RICH_TEXT_EDITOR_MARGIN);
};