From b9d2934b1b70dafa202afd705a6364d8dd8b33ef Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sun, 8 Nov 2026 15:50:47 +0800 Subject: [PATCH] fix(sidebar): treat a zero-sized dock anchor as absent (#1157) --- CHANGELOG.md | 2 ++ CHANGELOG_EN.md | 2 ++ src/client/sidebar/dock-fallback.tsx | 9 +++++++-- tests/dock-fallback.spec.tsx | 28 ++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e71c694b..131ff213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ - ⌨️ **终端支持 Ctrl/Cmd+C 与 Ctrl/Cmd+V 复制粘贴**([#1103](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1103)):有选区时 Ctrl+C 复制并清空选区,没有选区时仍把 Ctrl+C 交给 shell(SIGINT);Ctrl+V 粘贴,Ctrl+Shift+C/V 同样可用。macOS 的 Cmd+C/V 走同一条路径。 +- 🧭 **空白会话 + 右栏收起时,备用「展开底部面板」不再压住主题左上角按钮**([#1157](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1157)):主题把锚点隐藏后仍留在 DOM 里、rect 全为 0,旧逻辑把它当成真实位置并撞上 macOS 红绿灯下限;现在零尺寸锚点按不存在处理,退回右上角兜底。 + ### v0.30.1 - 🎯 **设置页「侧边卡片」的导航图标不再叠成两个**:插件此前按"宿主设置导航还没有图标通道"的老假设,用 CSS 把兜底齿轮藏起来、再画自己的图标;宿主早已提供按 section id 寻址的 `settings.section.icon` 插槽,而且图标的 DOM 外面多了一层 span,老选择器失效后兜底 SVG 露了出来,与插件图标并排显示。现在改为**走宿主插槽**提供图标,删掉标记 + CSS 遮罩那一套(顺带去掉了一个监听整个 document 的 MutationObserver)。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index 9384073e..7d3db13e 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -46,6 +46,8 @@ - ⌨️ **The terminal now supports Ctrl/Cmd+C and Ctrl/Cmd+V copy/paste** ([#1103](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1103)): Ctrl+C copies the selection (and clears it); with no selection it still reaches the shell as SIGINT. Ctrl+V pastes, Ctrl+Shift+C/V works too, and macOS Cmd+C/V follows the same path. +- 🧭 **A blank session with the right column collapsed no longer puts the fallback bottom-panel toggle on top of the theme's top-left button** ([#1157](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1157)): a theme can leave the anchor in the DOM with an all-zero rect, and the old code treated that as a real position and hit the macOS traffic-light floor; a zero-sized anchor is now treated as absent and uses the top-right fallback. + ### v0.30.1 - 🎯 **The "Side card" settings row no longer shows two icons**: the plugin still assumed the settings navigation had no icon channel, so it hid the fallback gear with CSS and painted its own glyph. The shell has long since exposed a `settings.section.icon` slot addressed by section id, and it now wraps the nav icon in a span — the stale `> svg:first-child` rule stopped hiding the fallback, so both glyphs rendered side by side. The row now contributes its icon **through the slot**, and the marker + CSS-mask apparatus is gone (along with a document-wide MutationObserver). diff --git a/src/client/sidebar/dock-fallback.tsx b/src/client/sidebar/dock-fallback.tsx index 6975ec3d..af26df76 100644 --- a/src/client/sidebar/dock-fallback.tsx +++ b/src/client/sidebar/dock-fallback.tsx @@ -143,8 +143,13 @@ function slotOccupiedByRect(cx: number, cy: number): boolean { function measure(): { top: number; left: number } { const anchor = document.querySelector('[data-sidebar-right-expand], [data-sidebar-right-toggle]') 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 + // A collapsed right column can leave the toggle in the DOM with an all-zero + // rect (the theme hides the panel with display:none). Treat that exactly like + // a missing anchor: the zero rect would otherwise pin the entry to the + // top-left 88px macOS traffic-light inset and cover the theme's own button. + const visible = rect !== undefined && rect.width > 0 && rect.height > 0 + const top = visible ? Math.max(4, rect.top + (rect.height - BUTTON_SIZE) / 2) : 8 + let left = visible ? rect.left - GAP - BUTTON_SIZE : window.innerWidth - BUTTON_SIZE - GAP - 8 // 复用宿主 preload 的平台属性;原生红绿灯不会出现在 elementsFromPoint 中。 // 48px 高度 / 88px 左侧留白与宿主 AppFrame / fullscreen dock strip 的几何一致。 const root = document.documentElement diff --git a/tests/dock-fallback.spec.tsx b/tests/dock-fallback.spec.tsx index 727484f6..77d09297 100644 --- a/tests/dock-fallback.spec.tsx +++ b/tests/dock-fallback.spec.tsx @@ -442,6 +442,34 @@ describe('dock fallback(空白会话入口)', () => { } }) + it('treats an all-zero anchor rect as absent instead of the top-left fallback', async () => { + phaseIs(true) + // A collapsed right column can leave the toggle in the DOM but display:none, + // which makes every rect field 0. The old code used that zero rect as a real + // anchor: left became -36, the macOS traffic-light floor clamped it to 88, + // and the entry landed exactly on the theme's top-left button. + const anchor = document.createElement('button') + anchor.setAttribute('data-sidebar-right-expand', 'true') + anchor.getBoundingClientRect = () => ({ + x: 0, y: 0, left: 0, top: 0, width: 0, height: 0, right: 0, bottom: 0, + toJSON: () => ({}), + }) as DOMRect + document.body.append(anchor) + const hit = stubHitTest(() => []) + const { unmount } = renderDockFallback() + try { + await settle() + const shell = document.querySelector('[data-dsh-dock-fallback]') + expect(shell, '空白会话里备用入口应当在').not.toBeNull() + expect(shell!.style.top, '零尺寸锚点走右上角兜底').toBe('8px') + expect(shell!.style.left, '零尺寸锚点走右上角兜底').toBe(`${window.innerWidth - 44}px`) + } finally { + unmount() + hit.restore() + anchor.remove() + } + }) + it('bounds the retreat walk at 100 steps (400px)', async () => { phaseIs(true) const anchor = appendAnchor(500)