From 4108e1544c38e085be8d8358f8ac2139f4def957 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 4 Nov 2026 22:09:38 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat(floating):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=A3=B3=E7=9A=84=E5=8E=9F=E7=94=9F=E7=AA=97=E5=8F=A3=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=B8=A6=E5=87=A0=E4=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 桌面壳用 Electron titleBarOverlay 在页面顶部画最小化/最大化/关闭,那条带子 的鼠标事件到不了网页(#805 已实测)。这里只读标准 WCO 几何作为唯一来源: 无 API、visible=false(幽灵接口)、0 高(全屏)、读取抛错一律退化为 0, 普通浏览器与网页版行为不变。 不写偏好、不加设置项、不发布 CSS 变量、不复活 #430 删掉的 --dsh-title-bar-strip / body[data-dsh-title-bar-compat]。 --- src/client/viewport-inset.ts | 138 +++++++++++++++++++++++++++++++++++ tests/viewport-inset.spec.ts | 134 ++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+) create mode 100644 src/client/viewport-inset.ts create mode 100644 tests/viewport-inset.spec.ts diff --git a/src/client/viewport-inset.ts b/src/client/viewport-inset.ts new file mode 100644 index 00000000..5e685977 --- /dev/null +++ b/src/client/viewport-inset.ts @@ -0,0 +1,138 @@ +/** + * How many CSS pixels at the top of the viewport the DESKTOP SHELL paints its + * native window controls over (minimize / maximize / close). + * + * Why this exists: on Windows the shell enables Electron's `titleBarOverlay`, + * which draws those buttons OVER the page and takes every pointer event in + * that band before it can reach the DOM. A floating surface pinned to the + * viewport top therefore loses its whole title bar: the close button looks + * dead while `document.elementFromPoint` still answers it (the two-point + * bisection in issue #805 measured the same mechanism for the mermaid zoom + * toolbar; the Tasks detail window is the same bug one component over). + * + * The ONE source is the standard Window Controls Overlay geometry. No + * preference, no settings row, no URL stamp, no shell-supplied service, and + * nothing is published to the DOM — the previous configurable "title-bar + * strip" was removed in #430 because it had grown five sources and zero + * consumers; this has one source and three real consumers. + */ +import { useSyncExternalStore } from 'react' + +/** The slice of `navigator.windowControlsOverlay` this module needs. */ +export interface WindowControlsOverlayLike { + readonly visible: boolean + getTitlebarAreaRect(): { + readonly x: number + readonly y: number + readonly width: number + readonly height: number + } + addEventListener(type: 'geometrychange', listener: () => void): void + removeEventListener(type: 'geometrychange', listener: () => void): void +} + +/** The part of the viewport a floating surface must not cover. */ +export interface ViewportInset { + readonly top: number +} + +export const NO_VIEWPORT_INSET: ViewportInset = Object.freeze({ top: 0 }) + +function overlayOf(navigatorLike: Navigator | undefined): WindowControlsOverlayLike | undefined { + const candidate = (navigatorLike as + | (Navigator & { windowControlsOverlay?: WindowControlsOverlayLike }) + | undefined)?.windowControlsOverlay + return candidate ?? undefined +} + +/** + * The safe gap below the native control band. + * + * `y + height` rather than `height` alone: the rect names the title-bar AREA, + * so its bottom edge is the first pixel the page can own (the two coincide on + * Windows, where `y` is 0, but a shell may inset the band). + * + * Everything unusable collapses to 0 — no API, `visible: false` (headless + * Chromium and some macOS builds expose the interface with no overlay), a + * zero-height band (full screen), or a throwing call. 0 keeps plain browsers + * and web profiles exactly as they were. + */ +function computeInset(candidate: WindowControlsOverlayLike | undefined): ViewportInset { + if (candidate === undefined) return NO_VIEWPORT_INSET + try { + if (candidate.visible !== true) return NO_VIEWPORT_INSET + const rect = candidate.getTitlebarAreaRect() + const top = Math.round(rect.y + rect.height) + return Number.isFinite(top) && top > 0 ? { top } : NO_VIEWPORT_INSET + } catch { + return NO_VIEWPORT_INSET + } +} + +let source: WindowControlsOverlayLike | undefined +let snapshot: ViewportInset = NO_VIEWPORT_INSET +const listeners = new Set<() => void>() + +function emit(): void { + for (const listener of listeners) listener() +} + +function reread(): void { + const next = computeInset(source) + if (next === snapshot) return + snapshot = next + emit() +} + +// Probe at module evaluation, not on the first subscriber: `useSyncExternalStore` +// reads the snapshot before it subscribes, so a lazy mount would paint the +// first frame at the unsafe position and then jump the window down. +if (typeof navigator !== 'undefined') { + source = overlayOf(navigator) + if (source !== undefined) { + snapshot = computeInset(source) + source.addEventListener('geometrychange', reread) + } +} + +// Some Electron builds expose the overlay without firing `geometrychange` on +// maximize / restore; a resize is the same event in practice. Event-driven, so +// it costs nothing while idle (unlike the polling the steady-state rules guard). +if (typeof window !== 'undefined') { + window.addEventListener('resize', reread) +} + +/** The current inset. Stable reference until the geometry actually changes. */ +export function getViewportInset(): ViewportInset { + return snapshot +} + +/** Subscribe to geometry changes; returns the disposer. */ +export function subscribeViewportInset(listener: () => void): () => void { + listeners.add(listener) + return () => { listeners.delete(listener) } +} + +/** Swap the overlay source (tests). `undefined` = no overlay API. */ +export function setViewportInsetSourceForTests( + next: WindowControlsOverlayLike | undefined, +): void { + source?.removeEventListener('geometrychange', reread) + source = next + const computed = computeInset(next) + if (computed !== snapshot) { + snapshot = computed + emit() + } + next?.addEventListener('geometrychange', reread) +} + +/** React consumer: the inset, re-rendering when the shell band changes. */ +export function useViewportInset(): ViewportInset { + return useSyncExternalStore(subscribeViewportInset, getViewportInset, getViewportInset) +} + +/** Convenience for callers that only need the number. */ +export function useViewportInsetTop(): number { + return useViewportInset().top +} diff --git a/tests/viewport-inset.spec.ts b/tests/viewport-inset.spec.ts new file mode 100644 index 00000000..3e3b2a37 --- /dev/null +++ b/tests/viewport-inset.spec.ts @@ -0,0 +1,134 @@ +/** + * The viewport's top inset (viewport-inset.ts): the band the desktop shell + * paints its native window controls over, which floating surfaces must stay + * out of (issue #805; the Tasks detail window's close button is the same bug). + * + * Every unusable shape collapses to 0 so plain browsers keep their exact + * behaviour: no API, a `visible: false` ghost interface (headless Chromium, + * some macOS builds), a zero-height band (full screen), and a throwing read. + */ +// @vitest-environment jsdom +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { + getViewportInset, + setViewportInsetSourceForTests, + subscribeViewportInset, + type WindowControlsOverlayLike, +} from '../src/client/viewport-inset.ts' + +interface Rect { x: number; y: number; width: number; height: number } + +/** A controllable WCO source: `emit()` plays the browser's geometrychange. */ +function overlay(initial: Rect, visible = true): { + source: WindowControlsOverlayLike + set(next: Partial): void + setVisible(next: boolean): void + emit(): void + listenerCount(): number + boom(): void +} { + let rect = { ...initial } + let isVisible = visible + let throws = false + const listeners = new Set<() => void>() + return { + source: { + get visible() { return isVisible }, + getTitlebarAreaRect() { + if (throws) throw new Error('geometry raced the layout') + return { ...rect } + }, + addEventListener(_type, listener) { listeners.add(listener) }, + removeEventListener(_type, listener) { listeners.delete(listener) }, + }, + set(next) { rect = { ...rect, ...next } }, + setVisible(next) { isVisible = next }, + emit() { for (const listener of listeners) listener() }, + listenerCount: () => listeners.size, + boom() { throws = true }, + } +} + +beforeEach(() => { + setViewportInsetSourceForTests(undefined) +}) + +afterEach(() => { + setViewportInsetSourceForTests(undefined) +}) + +describe('viewport inset: the shape of the native control band', () => { + it('is zero without the Window Controls Overlay API', () => { + expect(getViewportInset().top).toBe(0) + }) + + it('reads the band height', () => { + setViewportInsetSourceForTests(overlay({ x: 0, y: 0, width: 1_000, height: 36 }).source) + expect(getViewportInset().top).toBe(36) + }) + + it('rounds a fractional height', () => { + setViewportInsetSourceForTests(overlay({ x: 0, y: 0, width: 1_000, height: 35.6 }).source) + expect(getViewportInset().top).toBe(36) + }) + + it('uses the rect bottom edge, not the raw height', () => { + // A shell that insets the band: the page may start at y + height. + setViewportInsetSourceForTests(overlay({ x: 0, y: 4, width: 1_000, height: 32 }).source) + expect(getViewportInset().top).toBe(36) + }) + + it('treats a non-visible overlay as absent (ghost interface)', () => { + setViewportInsetSourceForTests(overlay({ x: 0, y: 0, width: 1_000, height: 44 }, false).source) + expect(getViewportInset().top).toBe(0) + }) + + it('treats a zero-height band as no band (full screen)', () => { + setViewportInsetSourceForTests(overlay({ x: 0, y: 0, width: 1_000, height: 0 }).source) + expect(getViewportInset().top).toBe(0) + }) + + it('does not throw when the geometry read races the layout', () => { + const fake = overlay({ x: 0, y: 0, width: 1_000, height: 44 }) + setViewportInsetSourceForTests(fake.source) + expect(getViewportInset().top).toBe(44) + fake.boom() + expect(() => { fake.emit() }).not.toThrow() + expect(getViewportInset().top).toBe(0) + }) +}) + +describe('viewport inset: live geometry', () => { + it('notifies subscribers when the band changes', () => { + const fake = overlay({ x: 0, y: 0, width: 1_000, height: 0 }) + setViewportInsetSourceForTests(fake.source) + let calls = 0 + const dispose = subscribeViewportInset(() => { calls += 1 }) + expect(getViewportInset().top).toBe(0) + + fake.set({ height: 36 }) + fake.emit() + expect(getViewportInset().top).toBe(36) + + // A later event with the same geometry must not wake React again. + fake.set({ height: 0 }) + fake.emit() + expect(getViewportInset().top).toBe(0) + expect(calls).toBe(2) + + dispose() + fake.set({ height: 36 }) + fake.emit() + expect(calls).toBe(2) + }) + + it('detaches the previous source when tests swap it', () => { + const first = overlay({ x: 0, y: 0, width: 1_000, height: 36 }) + setViewportInsetSourceForTests(first.source) + expect(first.listenerCount()).toBe(1) + const second = overlay({ x: 0, y: 0, width: 1_000, height: 44 }) + setViewportInsetSourceForTests(second.source) + expect(first.listenerCount()).toBe(0) + expect(getViewportInset().top).toBe(44) + }) +}) From 3939fe5b6ebc09a0ab9aca425d124c2844e50e95 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 4 Nov 2026 22:09:44 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix(floating):=20=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=B5=AE=E7=AA=97=E7=9A=84=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E6=A0=8F=E4=B8=8D=E5=86=8D=E8=90=BD=E8=BF=9B=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 浮窗顶部下限原本写死 8px,而自身标题栏高 34px,关闭键正好落在 Windows 原生 窗口按钮那条带子里,点击被原生层吃掉(elementFromPoint 仍返回按钮本身,所以 页面侧看起来正常)。改为 8px + 控件带高度,覆盖锚点定位、拖拽、resize 三条 路径;带子变大时把已摆好的窗抬出去,变小时不主动下拉(不移动用户摆好的窗)。 普通浏览器无 WCO 时 inset=0,与改动前逐字等价。 --- src/client/FloatingWindow.tsx | 57 ++++++++++++++------ tests/floating-window.spec.tsx | 99 ++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 16 deletions(-) diff --git a/src/client/FloatingWindow.tsx b/src/client/FloatingWindow.tsx index 93085dda..a22ee976 100644 --- a/src/client/FloatingWindow.tsx +++ b/src/client/FloatingWindow.tsx @@ -37,6 +37,7 @@ import { createPortal } from 'react-dom' import { Button, IconCloseFillRegular } from '@deepseek-ai/dsh-client-ui-primitives' import { createFrameBatcher } from './frame-batcher.ts' import { t } from './locales.ts' +import { useViewportInsetTop } from './viewport-inset.ts' import css from './FloatingWindow.module.css' /** Default share of the viewport a fresh window takes. */ @@ -105,11 +106,22 @@ function clamp(value: number, min: number, max: number): number { * title bar / its right edge) reachable": a window that hangs off the bottom * edge hides its own resize corner, which is exactly how the first real-host * check lost it. + * + * `minStart` is the lowest the origin may go; callers pass the top edge raised + * past the shell's native window-control band, which takes pointer events + * before the page sees them (./viewport-inset.ts). The overflow branch keeps + * its old shape: there the title bar is already off-screen, so raising the + * floor would only push the window's bottom further out. */ -function clampOrigin(start: number, size: number, viewport: number): number { +function clampOrigin( + start: number, + size: number, + viewport: number, + minStart = VIEWPORT_MARGIN, +): number { const fullyInside = viewport - size - VIEWPORT_MARGIN - return fullyInside >= VIEWPORT_MARGIN - ? clamp(start, VIEWPORT_MARGIN, fullyInside) + return fullyInside >= minStart + ? clamp(start, minStart, fullyInside) : clamp(start, KEEP_ON_SCREEN - size, viewport - KEEP_ON_SCREEN) } @@ -119,7 +131,9 @@ function initialBox( size: { width: number; height: number } | undefined, min: { width: number; height: number }, viewport: { width: number; height: number }, + insetTop: number, ): WindowBox { + const topFloor = VIEWPORT_MARGIN + insetTop const width = clamp( size?.width ?? viewport.width * DEFAULT_WIDTH_RATIO, min.width, @@ -128,15 +142,15 @@ function initialBox( const height = clamp( size?.height ?? viewport.height * DEFAULT_HEIGHT_RATIO, min.height, - Math.max(min.height, viewport.height - VIEWPORT_MARGIN * 2), + Math.max(min.height, viewport.height - topFloor - VIEWPORT_MARGIN), ) const rect = anchor?.getBoundingClientRect() const left = rect === undefined ? (viewport.width - width) / 2 : clamp(rect.left, VIEWPORT_MARGIN, viewport.width - width - VIEWPORT_MARGIN) const top = rect === undefined - ? Math.max(VIEWPORT_MARGIN, (viewport.height - height) / 2) - : clamp(rect.bottom + 6, VIEWPORT_MARGIN, viewport.height - height - VIEWPORT_MARGIN) + ? Math.max(topFloor, (viewport.height - height) / 2) + : clamp(rect.bottom + 6, topFloor, viewport.height - height - VIEWPORT_MARGIN) return { left: Math.round(left), top: Math.round(top), @@ -158,6 +172,9 @@ export function FloatingWindow(props: FloatingWindowProps): ReactNode { width: minSize?.width ?? DEFAULT_MIN_WIDTH, height: minSize?.height ?? DEFAULT_MIN_HEIGHT, }), [minSize?.width, minSize?.height]) + /** The shell's native window-control band: pointer events die in it. */ + const insetTop = useViewportInsetTop() + const topFloor = VIEWPORT_MARGIN + insetTop const frameRef = useRef(null) const onCloseRef = useRef(onClose) onCloseRef.current = onClose @@ -174,8 +191,10 @@ export function FloatingWindow(props: FloatingWindowProps): ReactNode { setBox(initialBox(anchor, initialSize, min, { width: window.innerWidth, height: window.innerHeight, - })) - // Mount-only on purpose: see the comment above. + }, insetTop)) + // Mount-only on purpose: see the comment above. The inset is read + // synchronously at module evaluation, so this first box already clears the + // shell band; a later change is handled by the re-clamp effect below. // eslint-disable-next-line react-hooks/exhaustive-deps }, []) @@ -185,21 +204,27 @@ export function FloatingWindow(props: FloatingWindowProps): ReactNode { const current = boxRef.current if (current === null) return const width = clamp(current.width, min.width, Math.max(min.width, window.innerWidth - VIEWPORT_MARGIN * 2)) - const height = clamp( - current.height, - min.height, - Math.max(min.height, window.innerHeight - MIN_VIEWPORT_HEIGHT), + // Old cap ("leave room for the title bar below") AND the new top floor: + // a band that grew while the window sat near the top would otherwise + // leave its title bar under the native controls. + const heightCap = Math.min( + window.innerHeight - MIN_VIEWPORT_HEIGHT, + window.innerHeight - topFloor - VIEWPORT_MARGIN, ) + const height = clamp(current.height, min.height, Math.max(min.height, heightCap)) setBox({ width, height, left: clampOrigin(current.left, width, window.innerWidth), - top: clampOrigin(current.top, height, window.innerHeight), + top: clampOrigin(current.top, height, window.innerHeight, topFloor), }) } window.addEventListener('resize', onResize) + // The band changed under an already-placed window: lift it out, never + // push it back down (that would move a window the reader placed). + onResize() return () => { window.removeEventListener('resize', onResize) } - }, [min.width, min.height]) + }, [min.width, min.height, topFloor]) // Escape only: no outside-click, no blur, no anchor observer (see the header). useEffect(() => { @@ -230,7 +255,7 @@ export function FloatingWindow(props: FloatingWindowProps): ReactNode { pendingDragRef.current = { ...start, left: clampOrigin(start.left + (move.clientX - startX), start.width, window.innerWidth), - top: clampOrigin(start.top + (move.clientY - startY), start.height, window.innerHeight), + top: clampOrigin(start.top + (move.clientY - startY), start.height, window.innerHeight, topFloor), } dragBatcher.schedule(() => { const pending = pendingDragRef.current @@ -248,7 +273,7 @@ export function FloatingWindow(props: FloatingWindowProps): ReactNode { window.addEventListener('pointermove', onMove) window.addEventListener('pointerup', onUp) window.addEventListener('pointercancel', onUp) - }, [dragBatcher]) + }, [dragBatcher, topFloor]) /** Resize from one edge handle: `axis` picks which dimension the handle owns. */ const resizeBatcher = useRef(createFrameBatcher()).current diff --git a/tests/floating-window.spec.tsx b/tests/floating-window.spec.tsx index d91fdd44..2b292acf 100644 --- a/tests/floating-window.spec.tsx +++ b/tests/floating-window.spec.tsx @@ -15,6 +15,10 @@ import { createElement, createRef, type RefObject } from 'react' import { act } from 'react-dom/test-utils' import { renderRoot, setupReactAct } from './test-utils.ts' import { FloatingWindow } from '../src/client/FloatingWindow.tsx' +import { + setViewportInsetSourceForTests, + type WindowControlsOverlayLike, +} from '../src/client/viewport-inset.ts' setupReactAct() @@ -57,6 +61,7 @@ beforeEach(() => { }) afterEach(() => { + setViewportInsetSourceForTests(undefined) vi.unstubAllGlobals() for (const el of document.querySelectorAll('body > div')) el.remove() }) @@ -242,3 +247,97 @@ describe('FloatingWindow gestures', () => { unmount() }) }) + +/** A controllable Window Controls Overlay: the shell's native control band. */ +function overlayBand(height: number, visible = true): { + source: WindowControlsOverlayLike + set(next: number): void + emit(): void +} { + let band = height + const listeners = new Set<() => void>() + return { + source: { + get visible() { return visible }, + getTitlebarAreaRect: () => ({ x: 0, y: 0, width: 1_000, height: band }), + addEventListener: (_type, listener) => { listeners.add(listener) }, + removeEventListener: (_type, listener) => { listeners.delete(listener) }, + }, + set(next) { band = next }, + emit() { for (const listener of listeners) listener() }, + } +} + +/** Drag the title bar into the top-left corner (the clamp's tightest case). */ +function dragToTopLeft(): void { + const handle = frame().querySelector('[data-window-handle]') as HTMLElement + act(() => { + pointer(handle, 'pointerdown', 500, 100) + pointer(window, 'pointermove', -5_000, -5_000) + pointer(window, 'pointerup', -5_000, -5_000) + }) +} + +/** + * The desktop shell paints its native window controls OVER the viewport's top + * band and the page never sees those pointer events (issue #805 measured it). + * A floating window whose title bar lands there reads as unclosable: the Tasks + * detail window's × was the report that started this. + */ +describe('FloatingWindow keeps its title bar out of the native control band', () => { + it('lifts an anchored window below the band', () => { + setViewportInsetSourceForTests(overlayBand(44).source) + const anchor = document.createElement('button') + document.body.append(anchor) + anchor.getBoundingClientRect = () => ({ + left: 100, top: 0, right: 200, bottom: 20, width: 100, height: 20, + x: 100, y: 0, toJSON: () => ({}), + }) as DOMRect + const { unmount } = renderWindow({ anchor }) + // Without the band the anchor would place it at 26; the floor is 8 + 44. + expect(box().top).toBe(52) + unmount() + }) + + it('never drags the window into the band', () => { + setViewportInsetSourceForTests(overlayBand(44).source) + const { unmount } = renderWindow() + dragToTopLeft() + expect(box().top).toBe(52) + unmount() + }) + + it('lifts an already-placed window when the band appears', () => { + const band = overlayBand(0) + setViewportInsetSourceForTests(band.source) + const { unmount } = renderWindow() + dragToTopLeft() + expect(box().top).toBe(8) + act(() => { band.set(44); band.emit() }) + expect(box().top).toBe(52) + unmount() + }) + + it('does not pull the window back up when the band disappears', () => { + // Deliberate: a window the reader placed must not jump on maximize/restore; + // the floor only ever guarantees "not inside the band". + const band = overlayBand(44) + setViewportInsetSourceForTests(band.source) + const { unmount } = renderWindow() + dragToTopLeft() + expect(box().top).toBe(52) + act(() => { band.set(0); band.emit() }) + expect(box().top).toBe(52) + unmount() + }) + + it('leaves plain browsers untouched when the overlay is a ghost', () => { + // Headless Chromium and some macOS builds expose the interface with + // `visible: false`: no band, so the old 8px floor must stay exact. + setViewportInsetSourceForTests(overlayBand(44, false).source) + const { unmount } = renderWindow() + dragToTopLeft() + expect(box().top).toBe(8) + unmount() + }) +}) From a95c65c09c54f1edc5909ca878faecd4106b4892 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 4 Nov 2026 22:09:50 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix(tasks):=20=E8=8A=82=E7=82=B9=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=BC=B9=E5=B1=82=E5=90=8C=E6=A0=B7=E9=81=BF=E5=BC=80?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=8E=A7=E4=BB=B6=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 锚定弹层顶部下限也是 8px,锚点靠近窗口顶部时整张卡片的头部会落进原生窗口 按钮带。改用同一份控件带几何:锚点自身在带内时也向下退让,拖拽纵向下限同步。 --- src/client/AnchoredPopover.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/client/AnchoredPopover.tsx b/src/client/AnchoredPopover.tsx index f45ec389..914d1d60 100644 --- a/src/client/AnchoredPopover.tsx +++ b/src/client/AnchoredPopover.tsx @@ -21,6 +21,7 @@ import { } from 'react' import { createPortal } from 'react-dom' import { createFrameBatcher } from './frame-batcher.ts' +import { useViewportInsetTop } from './viewport-inset.ts' /** The popover's default visual width (viewport-clamped). */ const POP_WIDTH = 264 @@ -62,6 +63,8 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { const baseRef = useRef({ left: 0, top: 0 }) const cardWidth = Math.min(width, window.innerWidth - VIEWPORT_MARGIN * 2) + /** The shell's native window-control band: pointer events die in it. */ + const topFloor = VIEWPORT_MARGIN + useViewportInsetTop() // Measure + position once the card is in the DOM (and whenever the anchor // or content changes size). layout effect: no visible jump. @@ -73,15 +76,18 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { const height = card.offsetHeight let top = rect.bottom + 6 if (top + height > window.innerHeight - VIEWPORT_MARGIN) { - top = Math.max(VIEWPORT_MARGIN, rect.top - height - 6) + top = Math.max(topFloor, rect.top - height - 6) } + // The anchor itself may sit in the band (a row near the top edge): opening + // just below it still leaves our own header under the native controls. + top = Math.max(topFloor, top) const left = Math.min( Math.max(VIEWPORT_MARGIN, rect.left), Math.max(VIEWPORT_MARGIN, window.innerWidth - cardWidth - VIEWPORT_MARGIN), ) baseRef.current = { left, top } setPos({ left: left + offsetRef.current.x, top: top + offsetRef.current.y }) - }, [anchor, children, cardWidth]) + }, [anchor, children, cardWidth, topFloor]) // A new anchor starts a fresh placement (never inherit another node's drag). useEffect(() => { setOffset({ x: 0, y: 0 }) }, [anchor]) @@ -103,8 +109,8 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { Math.max(VIEWPORT_MARGIN - base.left, window.innerWidth - cardWidth - VIEWPORT_MARGIN - base.left), ) const nextY = Math.min( - Math.max(start.y + (move.clientY - startY), VIEWPORT_MARGIN - base.top), - Math.max(VIEWPORT_MARGIN - base.top, window.innerHeight - 48 - base.top), + Math.max(start.y + (move.clientY - startY), topFloor - base.top), + Math.max(topFloor - base.top, window.innerHeight - 48 - base.top), ) pendingDragRef.current = { offset: { x: nextX, y: nextY }, @@ -127,7 +133,7 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { window.addEventListener('pointermove', onMove) window.addEventListener('pointerup', onUp) window.addEventListener('pointercancel', onUp) - }, [cardWidth, dragBatcher, draggable]) + }, [cardWidth, dragBatcher, draggable, topFloor]) // Global dismissal (see the file header for the contract). useEffect(() => { From c3e9be88d822b0c79974ccb247e6a7ac661f6b8a Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 4 Nov 2026 22:09:55 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix(mermaid):=20=E6=94=BE=E5=A4=A7=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E5=B7=A5=E5=85=B7=E6=A0=8F=E8=AE=A9=E5=87=BA=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E6=8E=A7=E4=BB=B6=E5=B8=A6=EF=BC=88#805=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 工具栏原本 top:16px、按钮 36px,在 42px 的原生窗口按钮带下只剩 10px 可点。 改为内联 top:16px+控件带高度,CSS 的 16px 保留为无 JS 时的降级;加 data-mermaid-toolbar 稳定选择器供 e2e 测量。 挂载 lane 注入可控的假 WCO(初始 0,不影响本 lane 其它断言),把带子调到 36px 后实测工具栏 top=52,调回 0 再实测回到 16。 --- src/client/mermaid.tsx | 9 +++++++- src/client/sidebar.module.css | 3 +++ tests/e2e/mount.e2e.ts | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/client/mermaid.tsx b/src/client/mermaid.tsx index 16658246..76d646bd 100644 --- a/src/client/mermaid.tsx +++ b/src/client/mermaid.tsx @@ -32,6 +32,7 @@ import { isDarkScheme, subscribeColorScheme } from './theme.ts' import { markdownTextProps } from './markdown-labels.tsx' import { t } from './locales.ts' import { sanitizeSvg } from './mermaid-sanitize.ts' +import { useViewportInsetTop } from './viewport-inset.ts' import type { MermaidMarkdownProps } from './mermaid-blocks.ts' import { splitMermaidBlocks } from './mermaid-blocks.ts' import { renderMermaidDiagram, type MermaidTheme } from './mermaid-frame.ts' @@ -192,6 +193,8 @@ function MermaidZoomModal({ svg, onClose }: { svg: SVGSVGElement; onClose: () => const svgRef = useRef(null) const dragRef = useRef({ active: false, startX: 0, startY: 0 }) const zoomRef = useRef({ scale: 1, tx: 0, ty: 0 }) + /** The shell's native window-control band: it eats pointer events (#805). */ + const insetTop = useViewportInsetTop() const applyTransform = (): void => { const node = svgRef.current @@ -298,7 +301,11 @@ function MermaidZoomModal({ svg, onClose }: { svg: SVGSVGElement; onClose: () => return createPortal(
-
+