fix(mermaid): 放大视图工具栏让出窗口控件带(#805)
工具栏原本 top:16px、按钮 36px,在 42px 的原生窗口按钮带下只剩 10px 可点。 改为内联 top:16px+控件带高度,CSS 的 16px 保留为无 JS 时的降级;加 data-mermaid-toolbar 稳定选择器供 e2e 测量。 挂载 lane 注入可控的假 WCO(初始 0,不影响本 lane 其它断言),把带子调到 36px 后实测工具栏 top=52,调回 0 再实测回到 16。
This commit is contained in:
1 parent
a95c65c09c
commit
c3e9be88d8
3 files changed
+54
-1
No files matched your search
@@ -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<SVGSVGElement | null>(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(
|
||||
<div className={css.mermaidModal} data-mermaid-modal ref={overlayRef}>
|
||||
<div className={css.mermaidModalToolbar}>
|
||||
<div
|
||||
className={css.mermaidModalToolbar}
|
||||
data-mermaid-toolbar
|
||||
style={{ top: 16 + insetTop }}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className={css.mermaidModalButton}
|
||||
|
||||
@@ -2057,6 +2057,9 @@ body[data-dsh-sidebar-dragging] .bottomPanel {
|
||||
|
||||
.mermaidModalToolbar {
|
||||
position: absolute;
|
||||
/* Fallback only: mermaid.tsx sets an inline `top` that also clears the
|
||||
shell's native window-control band, which swallows pointer events (#805).
|
||||
Kept here so the toolbar still lands somewhere sane if that never runs. */
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
display: flex;
|
||||
|
||||
@@ -168,6 +168,30 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async
|
||||
if (message.type() === 'error') consoleErrors.push(message.text())
|
||||
})
|
||||
|
||||
// A fake Window Controls Overlay so the test can play the desktop shell's
|
||||
// native window-control band. It starts at 0 (plain-browser behaviour, so
|
||||
// every other assertion in this lane stays exactly as before); the mermaid
|
||||
// section below raises it and measures the REAL layout.
|
||||
await page.addInitScript(() => {
|
||||
const listeners = new Set<() => void>()
|
||||
const band = { height: 0, visible: true }
|
||||
Object.defineProperty(navigator, 'windowControlsOverlay', {
|
||||
configurable: true,
|
||||
value: {
|
||||
get visible() { return band.visible },
|
||||
getTitlebarAreaRect: () => ({ x: 0, y: 0, width: window.innerWidth, height: band.height }),
|
||||
addEventListener: (type: string, listener: () => void) => {
|
||||
if (type === 'geometrychange') listeners.add(listener)
|
||||
},
|
||||
removeEventListener: (_type: string, listener: () => void) => { listeners.delete(listener) },
|
||||
},
|
||||
})
|
||||
;(window as unknown as { __setTitlebarBand(height: number): void }).__setTitlebarBand = (height) => {
|
||||
band.height = height
|
||||
for (const listener of listeners) listener()
|
||||
}
|
||||
})
|
||||
|
||||
// Load the shell. The app renders into #root; the plugin appends its own
|
||||
// [data-dsh-better-sidebar] host once its client half activates.
|
||||
//
|
||||
@@ -577,6 +601,25 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async
|
||||
})
|
||||
expect(modalRegions.modal, 'the zoom modal must opt out of app-region computation').toBe('none')
|
||||
expect(modalRegions.button, 'its buttons must stay no-drag').toBe('no-drag')
|
||||
// Issue #805: the shell draws its native window controls OVER the page's
|
||||
// top-right and those pointer events never reach the document, so the
|
||||
// toolbar must sit below that band. At the reporter's 42px overlay a bare
|
||||
// 16px inset left only the bottom 10px of each 36px button clickable while
|
||||
// `elementFromPoint` still answered the button — the control read as dead.
|
||||
// Play the band and measure the real layout.
|
||||
const toolbar = page.locator('[data-mermaid-modal] [data-mermaid-toolbar]')
|
||||
const toolbarTop = async (): Promise<number> => await toolbar.evaluate(
|
||||
(element) => Math.round(element.getBoundingClientRect().top),
|
||||
)
|
||||
expect(await toolbarTop(), 'with no band the toolbar keeps its 16px inset').toBe(16)
|
||||
await page.evaluate(() => {
|
||||
;(window as unknown as { __setTitlebarBand(h: number): void }).__setTitlebarBand(36)
|
||||
})
|
||||
await expect.poll(toolbarTop, 'a 36px band must push the toolbar clear of it').toBe(52)
|
||||
await page.evaluate(() => {
|
||||
;(window as unknown as { __setTitlebarBand(h: number): void }).__setTitlebarBand(0)
|
||||
})
|
||||
await expect.poll(toolbarTop, 'shrinking the band must pull the toolbar back').toBe(16)
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(modal, 'Esc must close the zoom modal').toHaveCount(0, { timeout: 10_000 })
|
||||
await assertNoCrash()
|
||||
|
||||
Reference in new issue
Block a user