From c908959f3dfc3ac24c3909dcd6b127c2269627a6 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Mon, 26 Oct 2026 15:26:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(sidebar):=20=E6=A1=8C=E9=9D=A2=E5=A3=B3?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E5=85=A5=E5=8F=A3=E9=81=BF=E5=BC=80=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E6=A0=8F=E5=B7=A6=E4=BE=A7=E7=B3=BB=E7=BB=9F=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=88#992=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS 桌面壳的原生红绿灯不在 elementsFromPoint 命中栈里,旧走查退到 视口左缘 left=4 时会把它压住。现在 darwin(非全屏、标题栏行)把左移 下限抬到宿主标题栏保留区 88px;下限之上仍无空位时接受与宿主内容重叠, 不隐藏空白会话唯一的底部工作台入口。web 行为仍是原来的 100 步有界走查。 tests/dock-fallback.spec.tsx 补 3 例:桌面占满时 left >= 88 且入口可点、 原生控件不在命中栈时同样避开保留区、web 占满时仍停在原位置。 --- src/client/sidebar/dock-fallback.tsx | 24 ++++++----- tests/dock-fallback.spec.tsx | 62 +++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/client/sidebar/dock-fallback.tsx b/src/client/sidebar/dock-fallback.tsx index 1363f003..6975ec3d 100644 --- a/src/client/sidebar/dock-fallback.tsx +++ b/src/client/sidebar/dock-fallback.tsx @@ -134,22 +134,26 @@ function slotOccupiedByRect(cx: number, cy: number): boolean { * 因此这里从锚点左侧起逐像素左移,取**最近的一个真的空着**的槽位。走查是**有界**的: * 最多 {@link MAX_RETREAT_STEPS} 步(400px)——真实的宿主编簇只有几个 28px 按钮,退过 * 400px 说明整排都被占着,而每一步都要采样 5 个点做命中测试,不封顶的走查(旧值 400 步) - * 会把一次 tick 变成上千次命中测试。到达上限仍未找到空位就接受当前槽位;一直退到 - * 视口左缘(`left <= 4`)仍被占时停在最左(宁可贴边,也不叠在宿主控件上)。 + * 会把一次 tick 变成上千次命中测试。走查有两条下限:macOS 桌面壳的标题栏左侧是系统窗口 + * 按钮(红绿灯,约 88px),原生控件不会出现在命中测试栈里,所以那条下限必须显式保留; + * 若下限之上仍无空位,接受与宿主内容重叠——空白会话没有别的底部工作台 opener,宁可叠 + * 内容也不叠系统控件、更不能把唯一入口藏掉。 * @returns 视口坐标下的 top/left。 */ function measure(): { top: number; left: number } { const anchor = document.querySelector('[data-sidebar-right-expand], [data-sidebar-right-toggle]') - if (anchor === null) return { top: 8, left: window.innerWidth - BUTTON_SIZE - GAP - 8 } - const rect = anchor.getBoundingClientRect() - const top = Math.max(4, rect.top + (rect.height - BUTTON_SIZE) / 2) - let left = Math.max(4, rect.left - GAP - BUTTON_SIZE) - for (let step = 0; step < MAX_RETREAT_STEPS; step++) { - if (slotFree(left, top)) break + const rect = anchor?.getBoundingClientRect() + const top = rect === undefined ? 8 : Math.max(4, rect.top + (rect.height - BUTTON_SIZE) / 2) + let left = rect === undefined ? window.innerWidth - BUTTON_SIZE - GAP - 8 : rect.left - GAP - BUTTON_SIZE + // 复用宿主 preload 的平台属性;原生红绿灯不会出现在 elementsFromPoint 中。 + // 48px 高度 / 88px 左侧留白与宿主 AppFrame / fullscreen dock strip 的几何一致。 + const root = document.documentElement + const minLeft = root.dataset.platform === 'darwin' && !root.hasAttribute('data-fullscreen') && top < 48 ? 88 : 4 + for (let step = 0; step < MAX_RETREAT_STEPS && left >= minLeft; step++) { + if (slotFree(left, top)) return { top, left } left -= STEP_PX - if (left <= 4) { left = 4; break } } - return { top, left } + return { top, left: Math.max(left, minLeft) } } export function DockFallback({ store }: { store: SidebarStore }): ReactNode { diff --git a/tests/dock-fallback.spec.tsx b/tests/dock-fallback.spec.tsx index 33cf0467..fe1bc5ca 100644 --- a/tests/dock-fallback.spec.tsx +++ b/tests/dock-fallback.spec.tsx @@ -222,6 +222,66 @@ describe('dock fallback(空白会话入口)', () => { } }) + it('keeps an occupied desktop row outside the traffic-light reserve without losing the only entry', async () => { + phaseIs(true) + document.documentElement.dataset.platform = 'darwin' + const anchor = appendAnchor(100) + const hit = stubHitTest(() => [anchor]) + const { unmount, store } = renderDockFallback() + try { + await settle() + const shell = document.querySelector('[data-dsh-dock-fallback]') + expect(shell, '空白会话没有其他 opener,不能隐藏唯一入口').not.toBeNull() + expect(Number.parseFloat(shell!.style.left), '无空位也不能落到 left<=4 或红绿灯区域').toBeGreaterThanOrEqual(88) + clickFallbackToggle() + expect(store.getSnapshot().state?.bottomOpen).toBe(true) + } finally { + unmount() + hit.restore() + anchor.remove() + delete document.documentElement.dataset.platform + } + }) + + it('avoids the desktop reserve even when native window controls are absent from the hit-test stack', async () => { + phaseIs(true) + document.documentElement.dataset.platform = 'darwin' + const anchor = appendAnchor(100) + const hit = stubHitTest(() => []) + const { unmount } = renderDockFallback() + try { + await settle() + const shell = document.querySelector('[data-dsh-dock-fallback]') + expect(shell).not.toBeNull() + expect(Number.parseFloat(shell!.style.left)).toBeGreaterThanOrEqual(88) + } finally { + unmount() + hit.restore() + anchor.remove() + delete document.documentElement.dataset.platform + } + }) + + it('keeps the bounded web walk (reaches the left edge, never hides)', async () => { + phaseIs(true) + const anchor = appendAnchor(100) + const hit = stubHitTest(() => [anchor]) + const { unmount } = renderDockFallback() + try { + await settle() + const shell = document.querySelector('[data-dsh-dock-fallback]') + // Web keeps the original bounded walk: every sampled slot is occupied, + // so the entry stops at the viewport's left edge (4px). Hiding the only + // blank-session entry would be worse than a leftover overlap. + expect(shell).not.toBeNull() + expect(shell!.style.left).toBe('4px') + } finally { + unmount() + hit.restore() + anchor.remove() + } + }) + // 占位判定走命中测试而不是角色筛选:该点下面整摞元素只要有不透明的小控件就算占着。 // 这里把命中测试桩成「前两个槽位被盖住」,断言入口继续左移。 it('steps past tab chips that are not buttons (hit-test occupancy)', async () => { @@ -394,7 +454,7 @@ describe('dock fallback(空白会话入口)', () => { expect(hit.hits(), '让位走查必须封顶在 100 步(400px)').toBe(100) const shell = document.querySelector('[data-dsh-dock-fallback]') // 锚点在 500、按钮 28px、间距 8px → 起点 464;100 步 × 4px = 400px → 64。 - // 旧上限(400 步)会一路退到视口左缘并停成 4px。 + // 耗尽上限后停在 464 - 400,而不是视口左缘;隐藏唯一入口不是可接受的兜底。 expect(shell!.style.left, '耗尽上限后停在 464 - 400,而不是视口左缘').toBe('64px') } finally { unmount()