Skip to content

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

:bug: Prevent database headers and block gutters from overlapping split panes https://github.com/siyuan-note/siyuan/issues/19588

Danield59032e98a71
diff --git a/app/src/layout/resizePane.test.ts b/app/src/layout/resizePane.test.ts
index 147d3c5d70..7216b835a6 100644
--- a/app/src/layout/resizePane.test.ts
+++ b/app/src/layout/resizePane.test.ts
@@ -1,6 +1,6 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {resizePanePercentages, splitPanePercentages} from "./resizePane";
+import {MIN_VERTICAL_PANE_SIZE, resizePanePercentages, splitPanePercentages} from "./resizePane";
describe("layout pane resizing", () => {
it("keeps two panes proportional after resizing", () => {
@@ -15,10 +15,20 @@ describe("layout pane resizing", () => {
assert.deepEqual(percentages, [40, 20, 40]);
});
- it("rejects sizes below the minimum", () => {
+ it("clamps sizes at the minimum", () => {
const percentages = resizePanePercentages([100, 100], 0, 1, 95);
- assert.equal(percentages, undefined);
+ assert.deepEqual(percentages, [96, 4]);
+ });
+
+ it("keeps vertical panes usable when dragged past either edge", () => {
+ assert.deepEqual(resizePanePercentages([400, 400], 0, 1, -1000, MIN_VERTICAL_PANE_SIZE), [25, 75]);
+ assert.deepEqual(resizePanePercentages([400, 400], 0, 1, 1000, MIN_VERTICAL_PANE_SIZE), [75, 25]);
+ });
+
+ it("allows an undersized pane to recover without shrinking it further", () => {
+ assert.deepEqual(resizePanePercentages([100, 400], 0, 1, -50, MIN_VERTICAL_PANE_SIZE), [20, 80]);
+ assert.deepEqual(resizePanePercentages([100, 400], 0, 1, 100, MIN_VERTICAL_PANE_SIZE), [40, 60]);
});
it("normalizes pane sizes before splitting an existing pane", () => {
diff --git a/app/src/layout/resizePane.ts b/app/src/layout/resizePane.ts
index cf76a5a4f5..6de310dc3c 100644
--- a/app/src/layout/resizePane.ts
+++ b/app/src/layout/resizePane.ts
@@ -1,3 +1,5 @@
+export const MIN_VERTICAL_PANE_SIZE = 200;
+
export const resizePanePercentages = (
sizes: number[],
previousIndex: number,
@@ -9,11 +11,13 @@ export const resizePanePercentages = (
return;
}
const resizedSizes = sizes.slice();
- resizedSizes[previousIndex] += delta;
- resizedSizes[nextIndex] -= delta;
- if (resizedSizes[previousIndex] < minSize || resizedSizes[nextIndex] < minSize) {
- return;
- }
+ // 已小于最小尺寸的分屏允许恢复,但不能继续缩小;越界拖动停在边界。
+ const previousMinimum = Math.min(minSize, sizes[previousIndex]);
+ const nextMinimum = Math.min(minSize, sizes[nextIndex]);
+ const boundedDelta = Math.max(previousMinimum - sizes[previousIndex],
+ Math.min(delta, sizes[nextIndex] - nextMinimum));
+ resizedSizes[previousIndex] += boundedDelta;
+ resizedSizes[nextIndex] -= boundedDelta;
return panePercentages(resizedSizes);
};
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index c460576b33..1fee48ac8d 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -42,8 +42,9 @@ import {adjustDockPadding} from "./dock/util";
import {setTitle} from "../util/processTitle";
import {activateQueuedAVLocate, queueAVLocateRequest} from "../protyle/render/av/locate";
import {applyDockEntryVisibility} from "../config/entryVisibility/runtime";
-import {panePercentages, resizePanePercentages} from "./resizePane";
+import {MIN_VERTICAL_PANE_SIZE, panePercentages, resizePanePercentages} from "./resizePane";
import {requestResponsiveDockLayout} from "./dock/responsive";
+import {stickyRow} from "../protyle/render/av/row";
const isBuiltInCustomModel = (type: string) => {
return type === "siyuan-card" || type === "siyuan-database-row";
@@ -1044,6 +1045,8 @@ export const addResize = (obj: Layout | Wnd, after = true) => {
documentSelf.body.classList.add("fn__pointer-none");
const nextElement = resizeElement.nextElementSibling as HTMLElement;
const previousElement = resizeElement.previousElementSibling as HTMLElement;
+ const resizingProtyles = getAllEditor().map(editor => editor?.protyle).filter(protyle =>
+ protyle && (previousElement.contains(protyle.element) || nextElement.contains(protyle.element)));
const isCenterResize = !!resizeElement.parentElement.closest(".layout__center");
const responsiveDock = !isCenterResize && direction === "lr" ?
[window.siyuan.layout?.leftDock, window.siyuan.layout?.rightDock].find((dock) =>
@@ -1085,7 +1088,7 @@ export const addResize = (obj: Layout | Wnd, after = true) => {
const delta = currentCoordinate - x;
const previousNowSize = previousSize + delta;
const nextNowSize = nextSize - delta;
- if (previousNowSize < 8 || nextNowSize < 8) {
+ if (!isCenterResize && (previousNowSize < 8 || nextNowSize < 8)) {
return;
}
if (window.siyuan.layout.leftDock && window.siyuan.layout.leftDock.layout.element === previousElement &&
@@ -1116,6 +1119,7 @@ export const addResize = (obj: Layout | Wnd, after = true) => {
previousIndex,
nextIndex,
delta,
+ direction === "tb" ? MIN_VERTICAL_PANE_SIZE : 8,
);
if (percentages) {
setPanePercentages(paneElements, percentages);
@@ -1130,6 +1134,16 @@ export const addResize = (obj: Layout | Wnd, after = true) => {
}
};
+ const updateFixedRows = () => {
+ // 分屏拖动不一定改变文档内容尺寸,需在绘制前同步数据库固定栏的坐标和裁剪。
+ resizingProtyles.forEach(protyle => {
+ hideElements(["gutterOnly"], protyle);
+ protyle.wysiwyg.element.querySelectorAll<HTMLElement>(".av").forEach(item => {
+ stickyRow(item, protyle.contentElement, "all");
+ });
+ });
+ };
+
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
moveEvent.preventDefault();
moveEvent.stopPropagation();
@@ -1139,6 +1153,7 @@ export const addResize = (obj: Layout | Wnd, after = true) => {
resizeFrame = 0;
if (pendingCoordinate !== undefined) {
applyResize(pendingCoordinate);
+ updateFixedRows();
}
pendingCoordinate = undefined;
});
@@ -1152,6 +1167,7 @@ export const addResize = (obj: Layout | Wnd, after = true) => {
}
if (pendingCoordinate !== undefined) {
applyResize(pendingCoordinate);
+ updateFixedRows();
}
documentSelf.body.classList.remove("fn__pointer-none");
documentSelf.onmousemove = null;
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 1a715ccd95..1fb4a7c4f7 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -4070,6 +4070,14 @@ data-type="fold"${viewOccurrenceID ? ` data-view-occurrence-id="${encodeURICompo
const left = compressed ? horizontalAnchorLeft - this.element.clientWidth - space / 2 + 3 - gutterGap :
getNaturalLeft(this.element.clientWidth);
this.element.style.left = `${getFixedGutterPosition(left, fixedContainerRect?.left)}px`;
+ // 块标及其插入按钮按滚动视口和分屏边界裁剪,保留视口内的外伸控件。
+ const viewportRect = protyle.contentElement.getBoundingClientRect();
+ const paneRect = protyle.element.closest(".layout-tab-container")?.getBoundingClientRect() || viewportRect;
+ const gutterRect = this.element.getBoundingClientRect();
+ this.element.style.clipPath = `inset(${Math.max(contentTop, paneRect.top) - gutterRect.top}px ${
+ gutterRect.right - Math.min(viewportRect.right, paneRect.right)}px ${
+ gutterRect.bottom - Math.min(viewportRect.bottom, paneRect.bottom)}px ${
+ Math.max(viewportRect.left, paneRect.left) - gutterRect.left}px)`;
}
}
diff --git a/app/src/protyle/render/av/backlinkSticky.test.ts b/app/src/protyle/render/av/backlinkSticky.test.ts
index a3920122ab..46deaefcfd 100644
--- a/app/src/protyle/render/av/backlinkSticky.test.ts
+++ b/app/src/protyle/render/av/backlinkSticky.test.ts
@@ -15,10 +15,17 @@ test("sticky views follow visible breadcrumbs and return to the viewport top whe
require: () => ({hasTopClosestByAttribute: () => false}),
window: {innerHeight: 800},
});
+ let paneBottom = 800;
const views = {
classList: {contains: (name: string) => name === "av__views--fixed"},
offsetHeight: 40,
- style: {top: "", left: "", width: ""},
+ style: {top: "", left: "", width: "", clipPath: ""},
+ closest: (selector: string) => ({
+ getBoundingClientRect: () => ({
+ top: 24, bottom: selector === ".layout-tab-container" ? paneBottom : 800, left: 0, right: 500,
+ }),
+ }),
+ getBoundingClientRect: () => ({top: parseFloat(views.style.top), bottom: parseFloat(views.style.top) + 40, left: 20, right: 420}),
nextElementSibling: {
classList: {contains: (name: string) => name === "av__views-placeholder"},
getBoundingClientRect: () => ({top: -100, left: 20, width: 400}),
@@ -42,6 +49,16 @@ test("sticky views follow visible breadcrumbs and return to the viewport top whe
};
exports.stickyRow(block, scroll, "top");
assert.equal(views.style.top, "72px");
+ assert.equal(views.style.clipPath, "inset(0px 0px 0px 0px)");
+ paneBottom = 90;
+ exports.stickyRow(block, scroll, "top");
+ assert.equal(views.style.clipPath, "inset(0px 0px 22px 0px)");
+ paneBottom = 60;
+ exports.stickyRow(block, scroll, "top");
+ assert.equal(views.style.clipPath, "inset(0px 0px 52px 0px)");
+ paneBottom = 800;
+ exports.stickyRow(block, scroll, "top");
+ assert.equal(views.style.clipPath, "inset(0px 0px 0px 0px)");
hidden = true;
exports.stickyRow(block, scroll, "top");
assert.equal(views.style.top, "24px");
diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts
index b465eec3d2..189dff9bd3 100644
--- a/app/src/protyle/render/av/row.ts
+++ b/app/src/protyle/render/av/row.ts
@@ -497,14 +497,28 @@ const applyFixedClip = (el: HTMLElement, scrollEl: HTMLElement) => {
const scrollLeft = scrollEl.scrollLeft;
const clientWidth = scrollEl.clientWidth;
const scrollWidth = scrollEl.scrollWidth;
- if (scrollWidth <= clientWidth) {
- if (el.style.clipPath) {
- el.style.clipPath = "";
- }
- return;
- }
const right = Math.max(0, scrollWidth - scrollLeft - clientWidth);
- el.style.clipPath = `inset(0 ${right}px 0 ${scrollLeft}px)`;
+ applyFixedViewportClip(el, scrollWidth > clientWidth ? scrollLeft : 0, right);
+};
+
+const applyFixedViewportClip = (el: HTMLElement, left = 0, right = 0) => {
+ // 固定栏按编辑器与分屏的交集裁剪,避免分屏缩小时覆盖相邻文档。
+ const viewport = el.closest(".protyle-content");
+ const pane = el.closest(".layout-tab-container");
+ const rect = el.getBoundingClientRect();
+ let top = 0;
+ let bottom = 0;
+ [viewport, pane].forEach(element => {
+ if (!element) {
+ return;
+ }
+ const bounds = element.getBoundingClientRect();
+ top = Math.max(top, bounds.top - rect.top);
+ bottom = Math.max(bottom, rect.bottom - bounds.bottom);
+ left = Math.max(left, bounds.left - rect.left);
+ right = Math.max(right, rect.right - bounds.right);
+ });
+ el.style.clipPath = `inset(${top}px ${right}px ${bottom}px ${left}px)`;
};
const stickyScrollElMap = new WeakMap<HTMLElement, HTMLElement>();
@@ -592,7 +606,7 @@ export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement,
bindHeaderScrollSync(blockElement, scrollEl);
}
- // 先批量读取所有几何信息,再统一写入 style,避免读-写交错触发强制重排
+ // 先批量读取吸顶判定所需的几何信息,再更新固定栏位置及裁剪范围。
const elementRect = scrollElement.getBoundingClientRect();
const breadcrumbElement = scrollElement.previousElementSibling as HTMLElement;
// 移动端面包屑隐藏后仍保留布局尺寸,吸顶位置需回到滚动视口顶部。
@@ -692,7 +706,7 @@ export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement,
});
}
- // 第二遍:纯写入,此时不再读取布局,仅触发一次重排
+ // 第二遍:应用固定栏位置,并按定位后的实际边界裁剪。
const stickyBottom = Math.round(window.innerHeight - elementRect.bottom);
if (viewsTask) {
if (viewsTask.shouldFix) {
@@ -702,6 +716,7 @@ export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement,
viewsTask.element.style.left = viewsTask.left + "px";
viewsTask.element.style.top = viewsTask.top + "px";
viewsTask.element.style.width = viewsTask.width + "px";
+ applyFixedViewportClip(viewsTask.element);
} else {
removeFixedRow(viewsTask.element, "av__views--fixed", "av__views-placeholder");
}
@@ -712,10 +727,10 @@ export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement,
if (!item.classList.contains("av__row--header--fixed")) {
addFixedRow(item, "av__row--header--fixed", "av__row--header-placeholder", headerH, Math.round(bodyRect.width));
}
- syncFixedRowPos(item, bodyRect, task.scrollLeft, task.scrollEl);
item.style.top = bodyRect.bottom < headerStickyTop + headerH
? Math.round(bodyRect.bottom - headerH) + "px"
: headerStickyTop + "px";
+ syncFixedRowPos(item, bodyRect, task.scrollLeft, task.scrollEl);
} else {
removeFixedRow(item, "av__row--header--fixed", "av__row--header-placeholder");
}
@@ -726,8 +741,8 @@ export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement,
if (!item.classList.contains("av__row--footer--fixed")) {
addFixedRow(item, "av__row--footer--fixed", "av__row--footer--placeholder", footerH, Math.round(bodyRect.width));
}
- syncFixedRowPos(item, bodyRect, task.scrollLeft, task.scrollEl);
item.style.bottom = stickyBottom + "px";
+ syncFixedRowPos(item, bodyRect, task.scrollLeft, task.scrollEl);
} else {
removeFixedRow(item, "av__row--footer--fixed", "av__row--footer--placeholder");
}