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 the tab drag spacer in sync with interface density
Jeffrey Chen704655672fd5
diff --git a/app/src/layout/tabUtil.test.ts b/app/src/layout/tabUtil.test.tsnew file mode 100644index 0000000000..941659e411--- /dev/null+++ b/app/src/layout/tabUtil.test.ts@@ -0,0 +1,94 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import {join} from "node:path";+import test from "node:test";+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";++const loadTabUtil = (headerTop: number) => {+ const source = readFileSync(join(__dirname, "tabUtil.ts"), "utf8");+ const code = transpileModule(source, {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},+ }).outputText;+ const created: string[] = [];+ const spacerStyle = {} as Record<string, string>;+ const spacer = {style: spacerStyle, parentElement: {parentElement: {style: {}}} as unknown as HTMLElement};+ (spacer as unknown as {parentElement: {clientHeight: number}}).parentElement.clientHeight = 29;+ const headerElement = {+ classList: {contains: (): boolean => false, remove: (): void => undefined},+ getBoundingClientRect: (): DOMRect => ({top: headerTop, left: 0, right: 900, width: 900}) as DOMRect,+ style: {paddingLeft: "", visibility: ""},+ lastElementChild: {style: {marginRight: ""}},+ querySelector: (selector: string): unknown => {+ created.push(selector);+ return spacer;+ },+ };+ const item = {+ headersElement: {parentElement: headerElement},+ element: {+ classList: {add: (): void => undefined, remove: (): void => undefined},+ querySelector: (): unknown => ({style: {backgroundColor: ""}}),+ },+ };+ const saved = new Map<string, PropertyDescriptor | undefined>();+ for (const key of ["window", "document", "getComputedStyle"]) {+ saved.set(key, Object.getOwnPropertyDescriptor(globalThis, key));+ }+ Object.assign(globalThis, {+ window: {siyuan: {layout: {layout: {element: {+ getBoundingClientRect: (): {left: number, right: number} => ({left: 0, right: 900}),+ }}}}},+ document: {getElementById: (): null => null, querySelector: (): {clientWidth: number} => ({clientWidth: 120}),+ body: {}},+ getComputedStyle: (): {getPropertyValue: () => string} => ({getPropertyValue: (): string => "8px"}),+ });+ const exports = {} as typeof import("./tabUtil");+ const modules: Record<string, unknown> = {+ "./getAll": {getAllWnds: (_layout: unknown, wnds: unknown[]) => wnds.push(item)},+ "../util/functions": {isWindow: () => true},+ };+ new Function("exports", "require", code)(exports, (name: string) => modules[name] || {});+ const restore = () => saved.forEach((descriptor, key) => descriptor ?+ Object.defineProperty(globalThis, key, descriptor) : Reflect.deleteProperty(globalThis, key));+ return {setTabPosition: exports.setTabPosition, spacerStyle, headerElement, spacer, created, restore};+};++test("tab drag spacer stretches with the row instead of pinning a pixel height", () => {+ const f = loadTabUtil(0);+ try {+ f.setTabPosition();+ assert.equal(f.spacerStyle.alignSelf, "stretch", "the spacer fills the row height through flex stretching");+ assert.equal(f.spacerStyle.height, "",+ "a pinned pixel height cannot shrink after the interface density changes");+ assert.equal(f.spacerStyle.WebkitAppRegion, "drag");+ // 再次执行(对应界面密度、覆盖层高度变化后的重算)仍然不写死高度。+ f.setTabPosition();+ assert.equal(f.spacerStyle.height, "");+ assert.equal(f.spacerStyle.alignSelf, "stretch");+ } finally {+ f.restore();+ }+});++test("tab drag spacer releases its stretching when the header leaves the top row", () => {+ const f = loadTabUtil(40);+ try {+ f.setTabPosition();+ assert.equal(f.spacerStyle.alignSelf, "");+ assert.equal(f.spacerStyle.height, "");+ assert.equal(f.spacerStyle.WebkitAppRegion, "");+ } finally {+ f.restore();+ }+});++test("padding-only updates leave the drag spacer untouched", () => {+ const f = loadTabUtil(0);+ try {+ f.setTabPosition(true);+ assert.equal(f.created.length, 0, "padding-only layout does not resize the drag spacer");+ assert.equal(f.spacerStyle.alignSelf, undefined);+ } finally {+ f.restore();+ }+});diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.tsindex f480e56904..c70e56ea30 100644--- a/app/src/layout/tabUtil.ts+++ b/app/src/layout/tabUtil.ts@@ -112,10 +112,13 @@ export const setTabPosition = (onlyPadding = false, onlyClear = false) => {}}dragElement.parentElement.parentElement.style.minWidth = "56px";- dragElement.style.height = dragElement.parentElement.clientHeight + "px";+ // 用 flex 拉伸撑满行高,跟随界面密度和覆盖层高度变化,避免写死像素后无法回缩。+ dragElement.style.alignSelf = "stretch";+ dragElement.style.height = "";(dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "drag";} else {dragElement.parentElement.parentElement.style.minWidth = "";+ dragElement.style.alignSelf = "";dragElement.style.height = "";(dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "";}