Merge pull request #945 from hairyf/fix/native-tab-chip-alignment

fix: 对齐原生 Tab 与官方图标尺寸、间距和居中
This commit is contained in:
Hairy authored and GitHub committed 2026-11-21 12:54:45 +08:00
commit 1b36babe07
4 files changed
+39 -7

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ import css from '../sidebar.module.css'
import { createSidechatBindings, isSidechatOccurrence } from './sidechat-bindings.ts'
/** 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'
+6 -5
View File
@@ -497,17 +497,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
+31
View File
@@ -430,6 +430,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
@@ -454,6 +478,13 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async
}
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
+1 -1
View File
@@ -1080,7 +1080,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()