An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Keep mobile reference targets below top bars https://github.com/siyuan-note/siyuan/issues/19036
Daniela308a17039d9
diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.tsindex b58c4a1d3f..f52646bb9d 100644--- a/app/src/util/highlightById.ts+++ b/app/src/util/highlightById.ts@@ -1,5 +1,6 @@import {hasClosestBlock, isInEmbedBlock} from "../protyle/util/hasClosest";import {focusByRange, getEditorRange} from "../protyle/util/selection";+import {getStartScrollTop} from "./highlightPosition";export const bgFade = (element: Element) => {element.classList.add("protyle-wysiwyg--hl");@@ -106,8 +107,22 @@ export const scrollCenter = (const elementRect = nodeElement.getBoundingClientRect();const contentRect = protyle.contentElement.getBoundingClientRect();if (position === "start") {+ const breadcrumbElement = protyle.breadcrumb?.element.parentElement;+ // 使用未应用滚动平移的面包屑边界,确保顶部栏重新显示后目标块仍在可视区域内。+ const offsetParentTop = breadcrumbElement?.offsetParent?.getBoundingClientRect().top ?? contentRect.top;protyle.contentElement.scroll({- top: protyle.contentElement.scrollTop + elementRect.top - contentRect.top - (window.siyuan.config.editor.fontSize * 1.625 * 2 + 24),+ top: getStartScrollTop({+ scrollTop: protyle.contentElement.scrollTop,+ elementTop: elementRect.top,+ contentTop: contentRect.top,+ contextHeight: window.siyuan.config.editor.fontSize * 1.625 * 2 + 24,+ overlay: breadcrumbElement ? {+ absolute: getComputedStyle(breadcrumbElement).position === "absolute",+ offsetParentTop,+ offsetTop: breadcrumbElement.offsetTop,+ height: breadcrumbElement.offsetHeight,+ } : undefined,+ }),behavior});return;diff --git a/app/src/util/highlightPosition.test.ts b/app/src/util/highlightPosition.test.tsnew file mode 100644index 0000000000..1d75c89c4b--- /dev/null+++ b/app/src/util/highlightPosition.test.ts@@ -0,0 +1,60 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {getStartScrollTop} from "./highlightPosition";++const baseOptions = {+ scrollTop: 300,+ elementTop: 700,+ contentTop: 100,+ contextHeight: 76,+};++describe("highlight start position", () => {+ it("keeps the existing position for a breadcrumb in normal flow", () => {+ assert.equal(getStartScrollTop({+ ...baseOptions,+ overlay: {+ absolute: false,+ offsetParentTop: 52,+ offsetTop: 0,+ height: 48,+ },+ }), 824);+ });++ it("places the target below the untransformed portrait mobile bars", () => {+ assert.equal(getStartScrollTop({+ ...baseOptions,+ overlay: {+ absolute: true,+ offsetParentTop: 100,+ offsetTop: 48,+ height: 42,+ },+ }), 734);+ });++ it("uses only the breadcrumb height for the merged landscape top bar", () => {+ assert.equal(getStartScrollTop({+ ...baseOptions,+ overlay: {+ absolute: true,+ offsetParentTop: 100,+ offsetTop: 0,+ height: 42,+ },+ }), 782);+ });++ it("does not move the visible top above the content viewport", () => {+ assert.equal(getStartScrollTop({+ ...baseOptions,+ overlay: {+ absolute: true,+ offsetParentTop: 0,+ offsetTop: 0,+ height: 42,+ },+ }), 824);+ });+});diff --git a/app/src/util/highlightPosition.ts b/app/src/util/highlightPosition.tsnew file mode 100644index 0000000000..30c64ea31a--- /dev/null+++ b/app/src/util/highlightPosition.ts@@ -0,0 +1,21 @@+interface IStartScrollOverlay {+ absolute: boolean;+ offsetParentTop: number;+ offsetTop: number;+ height: number;+}++export const getStartScrollTop = (options: {+ scrollTop: number;+ elementTop: number;+ contentTop: number;+ contextHeight: number;+ overlay?: IStartScrollOverlay;+}) => {+ let visibleTop = options.contentTop;+ if (options.overlay?.absolute) {+ visibleTop = Math.max(visibleTop,+ options.overlay.offsetParentTop + options.overlay.offsetTop + options.overlay.height);+ }+ return options.scrollTop + options.elementTop - visibleTop - options.contextHeight;+};