Skip to content

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

:bug: Fix mobile database sticky header position https://github.com/siyuan-note/siyuan/issues/19425

Daniel2f3c8f2a55c8
diff --git a/app/src/protyle/render/av/backlinkSticky.test.ts b/app/src/protyle/render/av/backlinkSticky.test.ts
index 79c70f08b8..a3920122ab 100644
--- a/app/src/protyle/render/av/backlinkSticky.test.ts
+++ b/app/src/protyle/render/av/backlinkSticky.test.ts
@@ -8,6 +8,48 @@ const compiled = transpileModule(readFileSync("src/protyle/render/av/row.ts", "u
compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
}).outputText;
+test("sticky views follow visible breadcrumbs and return to the viewport top when hidden", () => {
+ const exports: {stickyRow?: (block: unknown, scroll: unknown, status: string) => void} = {};
+ runInNewContext(compiled, {
+ exports,
+ require: () => ({hasTopClosestByAttribute: () => false}),
+ window: {innerHeight: 800},
+ });
+ const views = {
+ classList: {contains: (name: string) => name === "av__views--fixed"},
+ offsetHeight: 40,
+ style: {top: "", left: "", width: ""},
+ nextElementSibling: {
+ classList: {contains: (name: string) => name === "av__views-placeholder"},
+ getBoundingClientRect: () => ({top: -100, left: 20, width: 400}),
+ },
+ };
+ const block = {
+ classList: {contains: () => false},
+ dataset: {avType: "gallery"},
+ querySelector: (selector: string) => selector === ".av__views" ? views : null,
+ getBoundingClientRect: () => ({bottom: 600}),
+ };
+ let hidden = false;
+ const scroll = {
+ scrollTop: 200,
+ getBoundingClientRect: () => ({top: 24, bottom: 800}),
+ previousElementSibling: {
+ classList: {contains: (name: string) => name === "protyle-breadcrumb"},
+ getAttribute: () => hidden ? "true" : null,
+ getBoundingClientRect: () => ({bottom: 72}),
+ },
+ };
+ exports.stickyRow(block, scroll, "top");
+ assert.equal(views.style.top, "72px");
+ hidden = true;
+ exports.stickyRow(block, scroll, "top");
+ assert.equal(views.style.top, "24px");
+ hidden = false;
+ exports.stickyRow(block, scroll, "top");
+ assert.equal(views.style.top, "72px");
+});
+
test("backlink scrolling clears fixed rows and their spacers without calculating window positions", () => {
const exports: {stickyRow?: (block: unknown, scroll: unknown, status: string) => void} = {};
runInNewContext(compiled, {exports, require: () => ({})});
diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts
index 0d36d58f47..c5164eb00a 100644
--- a/app/src/protyle/render/av/row.ts
+++ b/app/src/protyle/render/av/row.ts
@@ -595,7 +595,9 @@ export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement,
// 先批量读取所有几何信息,再统一写入 style,避免读-写交错触发强制重排
const elementRect = scrollElement.getBoundingClientRect();
const breadcrumbElement = scrollElement.previousElementSibling as HTMLElement;
- const breadcrumbBottom = breadcrumbElement?.classList.contains("protyle-breadcrumb") ?
+ // 移动端面包屑隐藏后仍保留布局尺寸,吸顶位置需回到滚动视口顶部。
+ const breadcrumbBottom = breadcrumbElement?.classList.contains("protyle-breadcrumb") &&
+ breadcrumbElement.getAttribute("aria-hidden") !== "true" ?
breadcrumbElement.getBoundingClientRect().bottom : elementRect.top;
const scrollTop = scrollElement.scrollTop;
const scrollLeft = scrollEl ? scrollEl.scrollLeft : 0;