From 82831e525d53a3766ddc9fa46ccecd261782a20a Mon Sep 17 00:00:00 2001 From: hairyf Date: Tue, 13 Oct 2026 22:26:34 +0800 Subject: [PATCH] fix: align native tab icons with official title geometry --- src/client/native/tab-adapter.tsx | 2 +- src/client/sidebar.module.css | 11 ++++++----- tests/e2e/mount.e2e.ts | 31 +++++++++++++++++++++++++++++++ tests/native-surface.spec.ts | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/client/native/tab-adapter.tsx b/src/client/native/tab-adapter.tsx index 979d74d9..f67d1abc 100644 --- a/src/client/native/tab-adapter.tsx +++ b/src/client/native/tab-adapter.tsx @@ -38,7 +38,7 @@ import type { SidebarStore, SidebarTab, TabType } from '../state.ts' import css from '../sidebar.module.css' /** The chip glyph's size: the tab strip's own icon scale. */ -const CHIP_ICON_SIZE = 14 +const CHIP_ICON_SIZE = 16 /** The editor kind: a chip for a file row shows the file's own glyph. */ const EDITOR_KIND = 'editor' diff --git a/src/client/sidebar.module.css b/src/client/sidebar.module.css index 96c30035..250a8f46 100644 --- a/src/client/sidebar.module.css +++ b/src/client/sidebar.module.css @@ -467,17 +467,18 @@ body[data-dsh-sidebar-dragging] .bottomPanel { overflow: hidden; } -/* The native tab chip's glyph (drawn by the plugin inside the host's - `sidebar.right.pane.tab.title` slot, which is the chip's content): sized to - the text, aligned on its baseline box, and separated from the title the way - the workbench strip separates its own glyph from its label. */ +/* The host title row owns centring and its 5px gap. Nested themed glyphs + must not add an inline SVG's baseline space to the icon's box. */ .chipIcon { display: inline-flex; align-items: center; - margin-right: 6px; flex: none; } +.chipIcon svg { + display: block; +} + /* "This page has something you have not looked at": a small solid dot on the tab, drawn on the native chip and on the bottom workbench strip alike. Static by design — a pulsing marker on every new subagent is noise, and the two diff --git a/tests/e2e/mount.e2e.ts b/tests/e2e/mount.e2e.ts index 3b04f49c..9def56d9 100644 --- a/tests/e2e/mount.e2e.ts +++ b/tests/e2e/mount.e2e.ts @@ -326,6 +326,30 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async 'the web profile must not offer a browser guide entry at DSH 0.1.7', ).toHaveCount(0) + // Compare real boxes with the official compass title: jsdom cannot catch + // a nested inline SVG's baseline offset or the host gap plus our margin. + const chipGeometry = (node: Element) => { + const svg = node.querySelector('svg')! + const icon = svg.getBoundingClientRect() + const row = node.getBoundingClientRect() + const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT) + let text: Node | null + while ((text = walker.nextNode()) !== null) { + if (text.textContent?.trim() && !svg.contains(text)) break + } + if (text === null) throw new Error('tab title text is missing') + const range = document.createRange() + range.selectNodeContents(text) + return { + width: icon.width, + height: icon.height, + gap: range.getBoundingClientRect().left - icon.right, + offset: icon.top + icon.height / 2 - (row.top + row.height / 2), + } + } + const activeChipTitle = pane.locator('[data-dockkit-tab][aria-selected="true"] [data-dockkit-tab-title]').first() + const officialGeometry = await activeChipTitle.evaluate(chipGeometry) + // Sweep every type through the guide. Each open mounts a real viewer (the // editor and mermaid chunks arrive lazily); a failure anywhere surfaces as a // pageerror or a crash strip, both of which the next assertion sees. A pane @@ -338,6 +362,13 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async await entry.click() await page.waitForTimeout(1_500) await assertNoCrash() + if (kind === 'files' || kind === 'git') { + const geometry = await activeChipTitle.evaluate(chipGeometry) + expect(geometry.width).toBe(officialGeometry.width) + expect(geometry.height).toBe(officialGeometry.height) + expect(Math.abs(geometry.gap - officialGeometry.gap), `${kind} icon/title spacing`).toBeLessThan(0.5) + expect(Math.abs(geometry.offset - officialGeometry.offset), `${kind} icon vertical centring`).toBeLessThan(0.5) + } } // The sweep opened the Side Chat type, whose view auto-creates a thread and diff --git a/tests/native-surface.spec.ts b/tests/native-surface.spec.ts index 9cb080d2..eb7cf6ce 100644 --- a/tests/native-surface.spec.ts +++ b/tests/native-surface.spec.ts @@ -984,7 +984,7 @@ describe('NativeTabTitle (the chip glyph)', () => { const { host, unmount } = renderTitle(records, service, nativeInfo('chip-1', 'stub-tab', 'Stub'), 'stub-tab') const chip = host.querySelector('[aria-hidden="true"]') expect(chip, 'the chip must carry a decorative glyph').not.toBeNull() - expect(chip!.querySelector('[data-stub-icon="14"]'), 'the descriptor icon renders at the chip scale').not.toBeNull() + expect(chip!.querySelector('[data-stub-icon="16"]'), 'the descriptor icon renders at the chip scale').not.toBeNull() expect(host.textContent, 'the title follows the glyph').toBe('Stub') expect(host.querySelector('[role="tab"]'), 'the chip itself is the host’s element, not the plugin’s').toBeNull() unmount()