Skip to content

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

:bug: Keep backlink block gutters below sticky titles https://github.com/siyuan-note/siyuan/issues/13679

Daniel27ef23bfbcf4
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index ac83ae257a..e9050d2cc4 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -101,7 +101,7 @@ import {
setOrderedListStart
} from "../wysiwyg/list";
import {applyHeadingLevelUpdates, getHeadingLevelUpdateOperations} from "../util/headingTransform";
-import {getGutterMarginHeight} from "./layout";
+import {getBacklinkGutterContentTop, getGutterMarginHeight} from "./layout";
// 块类型 data-type 到本地化名称键的映射,用于块标提示中的 ${x}
const BLOCK_TYPE_LANG_KEYS: { [key: string]: string } = {
@@ -3598,9 +3598,13 @@ data-type="fold" style="cursor:inherit;"><svg style="width: 10px;${fold && fold
let contentTop = protyle.contentElement.getBoundingClientRect().top;
if (protyle.options.backlinkData) {
const backlinkElement = protyle.element.closest(".backlinkList, .backlinkMList");
- if (backlinkElement) {
- contentTop = Math.max(contentTop, backlinkElement.getBoundingClientRect().top);
- }
+ const backlinkItemElement = protyle.element.closest(".backlinkList__item");
+ const titleElement = backlinkItemElement?.querySelector(":scope > .b3-list-item");
+ contentTop = getBacklinkGutterContentTop(
+ contentTop,
+ backlinkElement?.getBoundingClientRect().top,
+ titleElement?.getBoundingClientRect().bottom,
+ );
}
let rect = element.getBoundingClientRect();
let marginHeight = 0;
diff --git a/app/src/protyle/gutter/layout.test.ts b/app/src/protyle/gutter/layout.test.ts
index 46c98bd8c7..f3a62faa6a 100644
--- a/app/src/protyle/gutter/layout.test.ts
+++ b/app/src/protyle/gutter/layout.test.ts
@@ -1,6 +1,6 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {getGutterMarginHeight} from "./layout";
+import {getBacklinkGutterContentTop, getGutterMarginHeight} from "./layout";
describe("getGutterMarginHeight", () => {
it("uses the natural height after heading gutter buttons wrap", () => {
@@ -22,3 +22,13 @@ describe("getGutterMarginHeight", () => {
assert.equal(getGutterMarginHeight(44, 34, 0, 16), 5);
});
});
+
+describe("getBacklinkGutterContentTop", () => {
+ it("keeps the gutter below the sticky document title", () => {
+ assert.equal(getBacklinkGutterContentTop(20, 30, 62), 62);
+ });
+
+ it("keeps the existing content boundary when it is lower", () => {
+ assert.equal(getBacklinkGutterContentTop(80, 30, 62), 80);
+ });
+});
diff --git a/app/src/protyle/gutter/layout.ts b/app/src/protyle/gutter/layout.ts
index e11f12bdbd..f22a4f0ce5 100644
--- a/app/src/protyle/gutter/layout.ts
+++ b/app/src/protyle/gutter/layout.ts
@@ -6,3 +6,7 @@ export const getGutterMarginHeight = (blockHeight: number, gutterHeight: number,
return (blockHeight - (naturalGutterHeight || gutterHeight)) / 2;
}
};
+
+export const getBacklinkGutterContentTop = (contentTop: number, panelTop?: number, titleBottom?: number) => {
+ return Math.max(contentTop, panelTop ?? contentTop, titleBottom ?? contentTop);
+};