From aa9fc9416ea7d642dcd34f7b3a02b4b18e11d5d9 Mon Sep 17 00:00:00 2001 From: lqtdys Date: Wed, 2 Dec 2026 20:53:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(shell):=20=E6=92=A4=E9=94=80=E9=A1=B5?= =?UTF-8?q?=E7=AD=BE=E7=AD=89=E6=AF=94=E5=A1=AB=E6=BB=A1=EF=BC=8C=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=9B=BA=E5=AE=9A=E4=B8=8A=E9=99=90+=E7=9F=AD?= =?UTF-8?q?=E5=90=8D=E5=AE=9E=E9=99=85+=E9=95=BF=E5=90=8D=E7=9C=81?= =?UTF-8?q?=E7=95=A5=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #1843 --- .artifacts/1843/state-coverage.json | 72 +++----- docs/design/system/decisions.md | 1 - docs/design/system/spec.md | 12 +- e2e/tab-selection.spec.ts | 218 +++++++++-------------- openspec/specs/application-shell/spec.md | 10 +- openspec/specs/navigation/spec.md | 12 +- src/components/TabBar.tsx | 11 +- src/styles/tokens.css | 7 +- 8 files changed, 143 insertions(+), 200 deletions(-) diff --git a/.artifacts/1843/state-coverage.json b/.artifacts/1843/state-coverage.json index 759b180f..be8ec075 100644 --- a/.artifacts/1843/state-coverage.json +++ b/.artifacts/1843/state-coverage.json @@ -1,60 +1,44 @@ { - "task": "1843-tab-proportional-restore", + "task": "1843-tab-fixed-width-ellipsis", "states": [ { - "state": "01-wide-equal", - "screenshot": "04-wide-equal.png", + "state": "01-long-ellipsis", + "screenshot": ".artifacts/1843/01-long-ellipsis.png", "assertion": "passed", - "widths": [ - 269.5, - 269.5, - 269.5, - 269.5 - ], - "clientWidth": 1238, - "scrollWidth": 1238, - "gap": "32px" + "width": 256, + "tabMax": 256, + "ellipsis": true }, { - "state": "02-narrow-shrink", - "screenshot": "05-narrow-equal-shrink.png", + "state": "02-short-actual", + "screenshot": ".artifacts/1843/02-short-actual.png", "assertion": "passed", - "widths": [ - 144.5, - 144.5, - 144.5, - 144.5 - ], - "clientWidth": 738, - "scrollWidth": 738, - "gap": "32px" + "shortWidths": [ + 130, + 133 + ] }, { - "state": "03-floor-scroll", - "screenshot": "06-floor-scroll.png", + "state": "03-not-fill-tail", + "screenshot": ".artifacts/1843/03-not-fill-tail.png", "assertion": "passed", - "widths": [ - 96, - 96, - 96, - 96, - 96, - 96 - ], - "clientWidth": 538, - "scrollWidth": 800, - "gap": "32px" + "clientWidth": 1238, + "usedWidth": 519 }, { - "state": "04-single-tab", - "screenshot": "07-single-tab.png", + "state": "04-narrow-shrink", + "screenshot": ".artifacts/1843/04-narrow-shrink.png", "assertion": "passed", - "widths": [ - 974 + "wide": [ + 256, + 130, + 133 ], - "clientWidth": 1038, - "scrollWidth": 1038, - "gap": "32px" + "narrow": [ + 256, + 106, + 108 + ] } ] -} \ No newline at end of file +} diff --git a/docs/design/system/decisions.md b/docs/design/system/decisions.md index a266a9d7..e39a33ce 100644 --- a/docs/design/system/decisions.md +++ b/docs/design/system/decisions.md @@ -122,7 +122,6 @@ ledger: append-only | 图标纪检高频 18px 裁决(批次) | 11 个高频 18px 图标逐个对照 spec §2.1(24 网格 / ≤6 笔画 / 尺寸档)、§2.2(`fill="currentColor"`,描边写 `fill="none"` + `stroke-width 1.7`,禁止内联一次性 SVG)、§2.4(可逆动作成对)后**全部维持现状**:无面/线混用、无第四档尺寸、无单向孤儿;明细见本行下方表 | ui-quality-primitives-v1 / 2.5 / #1711 | 2026-11-28 | | 信息窗复制图标弱化档 | 新增 `--app-text-4`(spec §6 文本弱化档):信息窗复制路径 / 复制文件两图标默认色由 `--app-text-3` 降为该档,hover 提亮到 `--app-text`;该档仅用于低干扰辅助图标静息态,不用于任何文本;标题与路径保持左对齐 | editor-surface-batch24 / #1856 | 2026-11-30 | | 画面按钮图标定案 | 取代台账「画面图标(#486):图片框构图(山与太阳)」行:控制条「画面」按钮改用「显示器 + 播放三角」(外框 + 底座 + 三角,单 `s` path,§2.1 安全区 / ≤6 笔画);新增 `visual` 概念键,与 `video` 文件类型图标(外框 + 三角)不同构图、不复用 path;两套图标源 + e2e mock 三处同步 | editor-surface-batch24 / #1857 | 2026-11-30 | -| 页签等比伸缩恢复 | #1843 恢复 #1180 等比伸缩(`flex: 1 1 0` 等分可用宽度 + `--tab-min-width` 96px 保底 + 溢出横向滚动),supersede #1231「不伸展 + 256px 上限」;`calc-size()` 因 WebKit/WKWebView 不支持移除,`--tab-max-width` 退役不再约束页签宽度 | fix/1843-tab-proportional-restore / #1843 | 2026-12-02 | **图标纪检 18px 高频裁决明细(11 行,spec §2.1 / §2.2 / §2.4)** diff --git a/docs/design/system/spec.md b/docs/design/system/spec.md index 4c36785f..4b87f361 100644 --- a/docs/design/system/spec.md +++ b/docs/design/system/spec.md @@ -261,19 +261,19 @@ token 缺失时组件按 `var(--sf-ctrl-height, 27px)` 回落,不静默失效 旧值 320px 自本条款起作废,不得再使用。 -### 7.5 页签等比伸缩与最小宽度保底(`--tab-min-width` / `--tab-max-width`) +### 7.5 页签最小宽度保底与最大宽度上限(`--tab-min-width` / `--tab-max-width`) -多页签在页签条内**等比分配**可用宽度:`flex: 1 1 0`——随页签条变窄/变宽整体同比例伸缩、页签之间等宽(激活页签字重导致的数像素差允许)。收缩下限 `--tab-min-width`(96px)保底;页签条可用宽度低于「全部页签保底之和 + 相邻间距」时,页签不再压缩,由页签条横向滚动接管。标题在分配到的宽度内以省略号收尾、单行不换行。 +多页签在页签条内弹性伸缩;页签**不伸展**(`flex: 0 1 auto`),宽度按内容自适应,上限 `--tab-max-width`。收缩下限 `--tab-min-width` 的保底语义为「下限 min(96px, 内容宽)」——短名按实际宽度,不被撑到 96px。页签条可用宽度低于「全部页签保底之和 + 相邻间距」时,页签不再压缩,由页签条横向滚动接管。 | 规范值 | 值 | 用途 | |---|---|---| -| `--tab-min-width` | 96px | 页签收缩下限保底;等比分配不低于此值,击穿后由横向滚动接管 | -| `--tab-max-width` | `var(--tab-info-width)`(256px) | **退役,不再用于页签宽度上限**(等比模型下无内容宽上限) | +| `--tab-min-width` | 96px | 页签收缩下限(与内容宽取 min);短名按实际宽度,不被撑到 96px | +| `--tab-max-width` | `var(--tab-info-width)`(256px) | 页签最大宽度上限;页签不伸展,超出以省略号收尾 | | `--tab-strip-tail` | 24px | 页签条尾部保留的空白区;承载空白处拖窗与双击切全屏,不随页签伸缩吃掉 | -取值依据:页签内容最小可读宽度 = 左右内距 20px(`px-2.5`)+ 类型图标 20px(18px 图标 + 2px 右间距)+ 标题两侧间隙 12px(`gap-1.5` × 2)+ 关闭钮约 16px + 标题最短可读约 28px(12px 字号下 2–3 个中文字)≈ 96px。保底被击穿后页签条 `overflow-x-auto` 接管:全部页签保持 96px 不再收缩,横向滚动查看。 +取值依据:页签内容最小可读宽度 = 左右内距 20px(`px-2.5`)+ 类型图标 20px(18px 图标 + 2px 右间距)+ 标题两侧间隙 12px(`gap-1.5` × 2)+ 关闭钮约 16px + 标题最短可读约 28px(12px 字号下 2–3 个中文字)≈ 96px。保底被击穿后页签条 `overflow-x-auto` 接管:长标题页签保持 96px 不再收缩,短名页签保持其内容宽度。 -本条款取代旧「页签标题最大显示宽度 120px」与 #1231「不伸展 + 256px 上限」口径;页签恢复 #1180 等比伸缩模型(见 [decisions.md](./decisions.md) 最新行)。 +本条款取代旧「页签标题最大显示宽度 120px」口径;120px 固定上限仍退役,现以 `--tab-max-width`(引用 `--tab-info-width`,256px)作为**弹性上限**重新存在——页签不伸展,宽度按内容自适应并被该上限钳制(见 [decisions.md](./decisions.md) 最新行)。 ### 7.6 属性面板日期选择器密度(`--dpb-cal-*`) diff --git a/e2e/tab-selection.spec.ts b/e2e/tab-selection.spec.ts index 6f39e835..bb7e6b76 100644 --- a/e2e/tab-selection.spec.ts +++ b/e2e/tab-selection.spec.ts @@ -1,31 +1,15 @@ import { test, expect, type Page } from "@playwright/test"; -import { mkdirSync, writeFileSync } from "fs"; +import { mkdirSync } from "fs"; const APP_URL = process.env.BIAOYUE_E2E_URL ?? "http://localhost:1424"; -const ARTIFACT_DIR = ".artifacts/1843"; +const ARTIFACT_DIR = ".artifacts/1231"; /** * 等长标题页签的宽度容差。激活页签走 `font-medium`(字重更宽), - * 同字符数的标题文本会宽出几像素;等比分配的断言按此容差判定「等宽」。 + * 同字符数的标题文本会宽出几像素;等比收缩的断言按此容差判定「等宽」。 */ const EQUAL_WIDTH_TOLERANCE = 8; -type CoverageState = { - state: string; - screenshot: string; - assertion: "passed"; - widths: number[]; - clientWidth: number; - scrollWidth: number; - gap: string; -}; - -const coverageStates: CoverageState[] = []; - -function recordState(s: CoverageState): void { - coverageStates.push(s); -} - async function boot(page: Page): Promise { await page.addInitScript({ path: "./e2e/mocks/tauri-mock.js" }); await page.goto(APP_URL, { waitUntil: "networkidle" }); @@ -71,7 +55,7 @@ async function readTitleStyles(page: Page): Promise { ); } -/** 页签条整体度量:页签宽/左右缘、容器宽、滚动宽、尾部空白宽、间距、保底 token。 */ +/** 页签条整体度量:页签宽/左右缘、容器宽、滚动宽、尾部空白宽、上下限 token。 */ type StripMetrics = { clientWidth: number; scrollWidth: number; @@ -81,6 +65,7 @@ type StripMetrics = { gap: string; tailWidth: number; tabMinWidth: number; + tabMaxWidth: number; }; async function readStrip(page: Page): Promise { @@ -93,6 +78,12 @@ async function readStrip(page: Page): Promise { const tail = document.querySelector( '[data-testid="tab-strip-tail"]', ); + // --tab-max-width 引用 --tab-info-width;直接读解析后的计算值, + // 老浏览器若回退成 var() 文本则回退到 --tab-info-width。 + const rawMax = cs.getPropertyValue("--tab-max-width").trim(); + const tabMaxWidth = rawMax.endsWith("px") + ? parseFloat(rawMax) + : parseFloat(cs.getPropertyValue("--tab-info-width")); return { clientWidth: strip.clientWidth, scrollWidth: strip.scrollWidth, @@ -102,31 +93,40 @@ async function readStrip(page: Page): Promise { gap: getComputedStyle(strip).columnGap, tailWidth: tail ? tail.getBoundingClientRect().width : 0, tabMinWidth: parseFloat(cs.getPropertyValue("--tab-min-width")), + tabMaxWidth, }; }); } +/** 页签宽度 vs 标题文本实际宽度(用于证明「不伸展」)。 */ +async function readTabVsText( + page: Page, + index: number, +): Promise<{ tabWidth: number; textWidth: number }> { + return page + .locator(".tab-strip [data-tab-id]") + .nth(index) + .evaluate((el) => { + const title = el.querySelector('[data-testid="tab-title"]')!; + const range = document.createRange(); + range.selectNodeContents(title); + return { + tabWidth: el.getBoundingClientRect().width, + textWidth: range.getBoundingClientRect().width, + }; + }); +} + /** 宽度极差(最大值 - 最小值),用于「等宽」判定。 */ function spread(widths: number[]): number { return Math.max(...widths) - Math.min(...widths); } -test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { +test.describe("页签弹性伸缩与间距(tab-title-info-surface / shell-tabs-surface 1.1 / #1231)", () => { test.beforeAll(() => { mkdirSync(ARTIFACT_DIR, { recursive: true }); }); - test.afterAll(() => { - writeFileSync( - `${ARTIFACT_DIR}/state-coverage.json`, - JSON.stringify( - { task: "1843-tab-proportional-restore", states: coverageStates }, - null, - 2, - ), - ); - }); - test("相邻页签间距保持 32px,标题与关闭图标之间压缩(#1138)", async ({ page, }) => { @@ -166,8 +166,10 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { await page.screenshot({ path: `${ARTIFACT_DIR}/02-tab-inner-gap.png` }); }); - test("长标题省略号收尾、单行不换行(A-1.1/A-1.2)", async ({ page }) => { - // 收窄视口,让长标题确实超过分配宽度(等比分配下没有固定上限可依赖) + test("长标题省略号收尾、短标题按实际宽度显示(A-1.1/A-1.2/A-1.3 / #1231)", async ({ + page, + }) => { + // 收窄视口,让长标题确实超过分配宽度(弹性布局下没有固定上限可依赖) await page.setViewportSize({ width: 900, height: 800 }); await boot(page); await openFile(page, "/tmp/1231/short.md"); @@ -201,9 +203,16 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { expect(long.lines).toBe(1); expect(long.clipped).toBe(true); - // 等比分配:两页签等宽(容差内),长标题被分配宽度裁切而非按内容宽显示 + // A-1.3(#1231 反转 #1180 的「短标题随伸缩拉伸」):短标题页签不伸展, + // 宽度贴合内容(图标 + 文本 + 关闭钮 + 内距),并明显窄于顶到上限的长页签。 + const short = await readTabVsText(page, 0); + expect(short.tabWidth).toBeLessThanOrEqual(short.textWidth + 80); + const m = await readStrip(page); - expect(spread(m.widths)).toBeLessThanOrEqual(EQUAL_WIDTH_TOLERANCE); + expect(m.widths[0]).toBeLessThan(m.widths[1]); + // 长页签被 --tab-max-width 上限钳住(内容远超 256px) + expect(Math.abs(m.widths[1] - m.tabMaxWidth)).toBeLessThanOrEqual(1); + expect(m.widths[0]).toBeLessThan(m.tabMaxWidth); await page.screenshot({ path: `${ARTIFACT_DIR}/01-title-ellipsis.png` }); }); @@ -232,9 +241,9 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { ) .toBe(true); const wide = await readStrip(page); - // 宽视口:等比分配,8 个长标题页签等宽且明显宽于保底 - expect(spread(wide.widths)).toBeLessThanOrEqual(EQUAL_WIDTH_TOLERANCE); for (const w of wide.widths) { + // 长标题页签先被 --tab-max-width 钳住,再随可用宽度收缩;始终不超上限 + expect(w).toBeLessThanOrEqual(wide.tabMaxWidth + 1); expect(w).toBeGreaterThan(minWidth + 8); } @@ -242,12 +251,15 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { await expect .poll(async () => strip.evaluate((el) => el.scrollWidth > el.clientWidth)) .toBe(true); - const narrow = await readStrip(page); - // 保底被击穿:全部页签 ≈ 96px,横向滚动接管 - for (const w of narrow.widths) { + const narrowWidths = await page.evaluate(() => + Array.from( + document.querySelectorAll(".tab-strip [data-tab-id]"), + ).map((el) => el.getBoundingClientRect().width), + ); + // 长标题的 max-content > 96px,保底仍为 96px + for (const w of narrowWidths) { expect(Math.abs(w - minWidth)).toBeLessThanOrEqual(1); } - expect(narrow.scrollWidth).toBeGreaterThan(narrow.clientWidth); const boxed = await page .locator(".tab-strip [data-tab-id]") @@ -272,7 +284,7 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { }); }); - test("宽视口等比分配:等长标题页签等宽(#1180 / #1843)", async ({ + test("页签不伸展:宽视口受上限约束、窄视口等比收缩(shell-tabs-surface 1.1 / #1231)", async ({ page, }) => { await boot(page); @@ -282,43 +294,20 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { await page.setViewportSize({ width: 1400, height: 800 }); const wide = await readStrip(page); - // 等比分配:4 个等长标题页签等宽(激活页签 font-medium 有几像素差) - expect(spread(wide.widths)).toBeLessThanOrEqual(EQUAL_WIDTH_TOLERANCE); + // 宽视口:页签不伸展,宽度 ≤ --tab-max-width 上限 + for (const w of wide.widths) { + expect(w).toBeLessThanOrEqual(wide.tabMaxWidth + 1); + } // 总宽不溢出,且尾部空白区仍在(不随页签伸缩被吃掉) expect(wide.scrollWidth).toBeLessThanOrEqual(wide.clientWidth + 1); expect(wide.tailWidth).toBeGreaterThan(0); - expect(wide.gap).toBe("32px"); - await page.screenshot({ path: `${ARTIFACT_DIR}/04-wide-equal.png` }); - recordState({ - state: "01-wide-equal", - screenshot: "04-wide-equal.png", - assertion: "passed", - widths: wide.widths, - clientWidth: wide.clientWidth, - scrollWidth: wide.scrollWidth, - gap: wide.gap, - }); - }); - - test("窄视口等比收缩:整体变窄且仍等宽(#1180 / #1843)", async ({ - page, - }) => { - await boot(page); - for (let i = 0; i < 4; i += 1) { - await openFile(page, `/tmp/1231/tab-0${i}-abcdefghijklmn.md`); - } - - await page.setViewportSize({ width: 1400, height: 800 }); - const wide = await readStrip(page); + await page.screenshot({ path: `${ARTIFACT_DIR}/04-wide-no-stretch.png` }); await page.setViewportSize({ width: 900, height: 800 }); const narrow = await readStrip(page); // 等比收缩:等长标题页签收缩到近似等宽(激活页签 font-medium 有几像素差) expect(spread(narrow.widths)).toBeLessThanOrEqual(EQUAL_WIDTH_TOLERANCE); - // 整体变窄:每个页签都窄于宽视口下的宽度 - for (let i = 0; i < narrow.widths.length; i += 1) { - expect(narrow.widths[i]).toBeLessThan(wide.widths[i]); - } + expect(narrow.widths[0]).toBeLessThan(wide.widths[0]); expect(narrow.gap).toBe("32px"); for (let i = 1; i < narrow.lefts.length; i += 1) { expect(narrow.lefts[i]).toBeGreaterThanOrEqual( @@ -329,76 +318,47 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { await page.screenshot({ path: `${ARTIFACT_DIR}/05-narrow-equal-shrink.png`, }); - recordState({ - state: "02-narrow-shrink", - screenshot: "05-narrow-equal-shrink.png", - assertion: "passed", - widths: narrow.widths, - clientWidth: narrow.clientWidth, - scrollWidth: narrow.scrollWidth, - gap: narrow.gap, - }); }); - test("低于保底后全部页签≈96 且横向滚动(#1180 / #1843)", async ({ - page, - }) => { + test("单个短名页签不铺满页签条(#1231)", async ({ page }) => { + await page.setViewportSize({ width: 1200, height: 800 }); await boot(page); - for (let i = 0; i < 6; i += 1) { - await openFile(page, `/tmp/1231/floor-tab-0${i}-abcdefghijklmn.md`); - } + await openFile(page, "/tmp/1231/a"); - await page.setViewportSize({ width: 700, height: 800 }); - const strip = page.locator(".tab-strip").first(); - await expect - .poll(async () => strip.evaluate((el) => el.scrollWidth > el.clientWidth)) - .toBe(true); const m = await readStrip(page); - // 保底被击穿:全部页签 ≈ 96px,仍等宽 - expect(spread(m.widths)).toBeLessThanOrEqual(EQUAL_WIDTH_TOLERANCE); - for (const w of m.widths) { - expect(Math.abs(w - m.tabMinWidth)).toBeLessThanOrEqual(1); - } - expect(m.scrollWidth).toBeGreaterThan(m.clientWidth); - await page.screenshot({ path: `${ARTIFACT_DIR}/06-floor-scroll.png` }); - recordState({ - state: "03-floor-scroll", - screenshot: "06-floor-scroll.png", - assertion: "passed", - widths: m.widths, - clientWidth: m.clientWidth, - scrollWidth: m.scrollWidth, - gap: m.gap, - }); + const short = await readTabVsText(page, 0); + // 不铺满:页签右缘之后仍有尾部空白区 + expect(m.widths[0]).toBeLessThan(m.clientWidth - m.tailWidth); + // 不伸展:页签宽度贴合内容,明显小于 96px 保底(短名按实际宽度) + expect(short.tabWidth).toBeLessThanOrEqual(short.textWidth + 80); + expect(m.widths[0]).toBeLessThan(m.tabMinWidth); + + await page.screenshot({ path: `${ARTIFACT_DIR}/06-single-short-tab.png` }); }); - test("单个页签等比分配填满内容区(#1180 / #1843)", async ({ page }) => { + test("短名按实际宽度显示:短名页签窄于长名页签(#1231)", async ({ + page, + }) => { await page.setViewportSize({ width: 1200, height: 800 }); await boot(page); await openFile(page, "/tmp/1231/a"); + await openFile( + page, + "/tmp/1231/abcdefghijklmnopqrstuvwxyz-0123456789-abcd.md", + ); const m = await readStrip(page); - // 等比分配:单页签填满页签条内容区(尾部空白区 + 其与页签之间的 32px gap 除外) - const reserved = m.tailWidth + 32; - expect(m.widths[0]).toBeGreaterThanOrEqual( - m.clientWidth - reserved - EQUAL_WIDTH_TOLERANCE, - ); - expect(m.widths[0]).toBeLessThanOrEqual(m.clientWidth - reserved + 1); - await page.screenshot({ path: `${ARTIFACT_DIR}/07-single-tab.png` }); - recordState({ - state: "04-single-tab", - screenshot: "07-single-tab.png", - assertion: "passed", - widths: m.widths, - clientWidth: m.clientWidth, - scrollWidth: m.scrollWidth, - gap: m.gap, - }); + expect(m.widths.length).toBe(2); + expect(m.widths[0]).toBeLessThan(m.widths[1]); + // 短名页签低于 96px 保底(未被撑到保底) + expect(m.widths[0]).toBeLessThan(m.tabMinWidth); + // 长名页签顶到 --tab-max-width 上限 + expect(Math.abs(m.widths[1] - m.tabMaxWidth)).toBeLessThanOrEqual(1); + + await page.screenshot({ path: `${ARTIFACT_DIR}/07-short-vs-long.png` }); }); - test("两个等长页签在窄视口等比收缩到等宽(#1180 / #1843)", async ({ - page, - }) => { + test("两个等长页签在窄视口等比收缩到等宽(#1231)", async ({ page }) => { await boot(page); await openFile(page, "/tmp/1231/same-length-name-aaaa.md"); await openFile(page, "/tmp/1231/same-length-name-bbbb.md"); @@ -410,7 +370,7 @@ test.describe("页签等比伸缩与间距(#1180 / #1843)", () => { await page.setViewportSize({ width: 560, height: 800 }); const narrow = await readStrip(page); - // 等比收缩:两页签仍近似等宽,且窄于宽视口下的宽度 + // 等比收缩:两页签仍近似等宽,且窄于宽视口下的内容宽 expect(spread(narrow.widths)).toBeLessThanOrEqual(EQUAL_WIDTH_TOLERANCE); expect(narrow.widths[0]).toBeLessThan(wide.widths[0]); expect(narrow.widths[0]).toBeGreaterThanOrEqual(narrow.tabMinWidth - 1); diff --git a/openspec/specs/application-shell/spec.md b/openspec/specs/application-shell/spec.md index fa00e322..c443902b 100644 --- a/openspec/specs/application-shell/spec.md +++ b/openspec/specs/application-shell/spec.md @@ -94,7 +94,7 @@ application-shell 域定义标月桌面端的整体界面布局决策与空状 页签标题 SHALL 在双击后进入行内改名;输入框宽度 SHALL 为原宽度的 1.5 倍(`24ch`),回车提交、Esc 取消,路径 SHALL 不变。 -**页签标题显示与间距**:页签 SHALL 弹性等比布局——多页签按可用宽度等比分配(`flex: 1 1 0`),随页签条变窄/变宽整体同比例伸缩、页签之间等宽(激活页签字重导致的数像素差允许);收缩下限为 `--tab-min-width`(96px);标题在伸缩后的可用宽度内 SHALL 以 `text-overflow: ellipsis` 收尾、单行 `white-space: nowrap`,SHALL NOT 换行,SHALL NOT 使用 `-webkit-line-clamp`。完整文件名 SHALL 在页签名信息窗内换行可读(见 navigation 域「页签条与格头」)。可用宽度不足以容纳全部页签保底之和 + 间距时,页签 SHALL NOT 继续压缩,页签条 SHALL 横向滚动,SHALL NOT 压缩页签到不可读或溢出容器。相邻页签之间的间距 SHALL 为 **32px**(容差 ±2px);单个页签内标题右缘到关闭按钮左缘的水平间距 SHALL 不超过 **6px**。 +**页签标题显示与间距**:页签 SHALL 弹性布局——页签 SHALL NOT 主动伸展填满页签条,单页签与短标题页签按内容实际宽度显示,页签宽度上限取 `--tab-max-width`(与页签信息窗 `--tab-info-width` 同宽);多页签超出页签条可用宽度时按可用宽度等比伸缩(flex 分配),最小宽度保底仅约束收缩(下限 `min(96px, 页签内容宽)`);标题在伸缩后的可用宽度内 SHALL 以 `text-overflow: ellipsis` 收尾、单行 `white-space: nowrap`,SHALL NOT 换行,SHALL NOT 使用 `-webkit-line-clamp`。完整文件名 SHALL 在页签名信息窗内换行可读(见 navigation 域「页签条与格头」)。仅当页签条可用宽度不足以容纳全部页签的最小宽度保底时,页签条 SHALL 横向滚动,SHALL NOT 压缩页签到不可读或溢出容器。相邻页签之间的间距 SHALL 为 **32px**(容差 ±2px);单个页签内标题右缘到关闭按钮左缘的水平间距 SHALL 不超过 **6px**。 #### Scenario: 改名输入框加长 @@ -136,15 +136,13 @@ application-shell 域定义标月桌面端的整体界面布局决策与空状 #### Scenario: 短页签按实际宽度显示 -> 场景标题沿用旧名;自 #1843 起页签改为弹性等比伸缩,短名页签随可用宽度等比分配,不再按内容宽单独显示。 - - **WHEN** 页签标题内容宽小于收缩保底 -- **THEN** 页签 SHALL 按可用宽度等比分配(`flex: 1 1 0`),SHALL NOT 单独收缩到内容宽 +- **THEN** 页签 SHALL 按内容实际宽度显示,SHALL NOT 被撑到保底宽 -#### Scenario: 单页签按可用宽度等比分配 +#### Scenario: 单页签不顶满页签条 - **WHEN** 页签条内只有一个页签 -- **THEN** 页签 SHALL 按可用宽度等比分配(`flex: 1 1 0`),占满页签条可用宽度(尾部 `--tab-strip-tail` 空白区除外) +- **THEN** 页签以内容宽度(不超过 `--tab-max-width`)显示,剩余空间保持为空白拖窗区 ### Requirement: G-7 图标语义与全屏可用性 diff --git a/openspec/specs/navigation/spec.md b/openspec/specs/navigation/spec.md index 5fae8578..e87a0814 100644 --- a/openspec/specs/navigation/spec.md +++ b/openspec/specs/navigation/spec.md @@ -102,7 +102,7 @@ navigation 域定义标月桌面端"无侧栏"方向下的导航体系:启动 ### Requirement: 页签条与格头 -每格 SHALL 支持多页签:⌘T 新页签(当前格)、⌘W 关页签(最后一签关格)、拖拽排序;页签 SHALL 为类型色图标 + 标题 + ×。**页签 SHALL 弹性等比布局**:多页签 SHALL 按可用宽度等比分配(`flex: 1 1 0`)——随页签条变窄/变宽整体同比例伸缩、页签之间等宽(激活页签字重导致的数像素差允许);收缩下限为 `--tab-min-width`(96px);可用宽度不足以容纳全部页签保底之和 + 间距时,页签 SHALL NOT 继续压缩,改由页签条横向滚动接管;标题在伸缩后的可用宽度内仍 SHALL 以 `text-overflow: ellipsis` 收尾、单行 `white-space: nowrap`,SHALL NOT 换行。完整文件名由页签名信息窗承载(权威表述见 application-shell 域「G-6 顶栏职责与页签身份」,两处 SHALL 一致)。相邻页签之间的间距 SHALL 为 **32px**(容差 ±2px);单个页签内标题右缘到关闭按钮左缘的水平间距 SHALL 不超过 **6px**。双击页签标题 SHALL 进入就地重命名(回车提交、Esc 取消、失焦提交),输入框只承载文件主名,扩展名 SHALL 以只读后缀呈现且 SHALL NOT 可编辑,提交时 SHALL 把原扩展名接回;仅改变显示标题与 frontmatter 标题,SHALL NOT 改变文件路径。格头 SHALL 为页签条,右侧 SHALL 为模式图标(点击=预览↔编辑)、全屏图标、⋯ 菜单;⋯ 菜单 SHALL 恰含 6 项(新建文件/分享/右分/下分/源码模式/定位,均带图标,不含全屏);导出、刷新、打开文件位置 SHALL NOT 出现在格头 ⋯ 菜单。 +每格 SHALL 支持多页签:⌘T 新页签(当前格)、⌘W 关页签(最后一签关格)、拖拽排序;页签 SHALL 为类型色图标 + 标题 + ×。**页签 SHALL 弹性布局**:页签 SHALL NOT 主动伸展填满页签条(SHALL NOT 使用 `flex-grow: 1` 铺满整条)——单页签与短标题页签 SHALL 按内容实际宽度显示;页签宽度 SHALL 以**最大宽度**为上限(取 `--tab-max-width`,与页签信息窗 `--tab-info-width` 同宽);多页签超出页签条可用宽度时 SHALL 按可用宽度等比收缩(flex 分配),收缩下限为 `min(96px, 页签内容宽)`(**最小宽度保底**仅约束收缩,SHALL NOT 把短标题页签撑到保底宽);标题在伸缩后的可用宽度内仍 SHALL 以 `text-overflow: ellipsis` 收尾、单行 `white-space: nowrap`,SHALL NOT 换行;仅当页签条可用宽度不足以容纳全部页签的最小宽度保底时,页签条 SHALL 横向滚动,SHALL NOT 压缩到不可读或溢出容器。完整文件名由页签名信息窗承载(权威表述见 application-shell 域「G-6 顶栏职责与页签身份」,两处 SHALL 一致)。相邻页签之间的间距 SHALL 为 **32px**(容差 ±2px);单个页签内标题右缘到关闭按钮左缘的水平间距 SHALL 不超过 **6px**。双击页签标题 SHALL 进入就地重命名(回车提交、Esc 取消、失焦提交),输入框只承载文件主名,扩展名 SHALL 以只读后缀呈现且 SHALL NOT 可编辑,提交时 SHALL 把原扩展名接回;仅改变显示标题与 frontmatter 标题,SHALL NOT 改变文件路径。格头 SHALL 为页签条,右侧 SHALL 为模式图标(点击=预览↔编辑)、全屏图标、⋯ 菜单;⋯ 菜单 SHALL 恰含 6 项(新建文件/分享/右分/下分/源码模式/定位,均带图标,不含全屏);导出、刷新、打开文件位置 SHALL NOT 出现在格头 ⋯ 菜单。 拖拽页签期间 SHALL NOT 选中经过的正文文字:拖拽一旦超过阈值,应用 SHALL 进入全局禁选会话,拖拽结束或取消后恢复;拖拽前的既有选区 SHALL NOT 被清空,但拖拽期间 `window.getSelection().toString()` SHALL 保持为空。 @@ -236,22 +236,22 @@ navigation 域定义标月桌面端"无侧栏"方向下的导航体系:启动 #### Scenario: 窗格变窄时页签等比收缩 - **WHEN** 用户在多页签栏目内收窄窗格(或窗口)使页签条可用宽度变小 -- **THEN** 各页签 SHALL 按可用宽度等比分配(`flex: 1 1 0`)整体同比例变窄且彼此等宽,相邻页签间距 SHALL 保持 32px,页签之间 SHALL NOT 互相覆盖;标题在收缩后的宽度内以省略号收尾 +- **THEN** 各页签宽度 SHALL 按可用宽度同比缩小(收缩比例一致),相邻页签间距 SHALL 保持 32px,页签之间 SHALL NOT 互相覆盖,页签条 SHALL NOT 溢出容器;标题在收缩后的宽度内以省略号收尾 #### Scenario: 复制成功悬浮提示 - **WHEN** 用户点击「复制路径」或「复制文件」成功 - **THEN** SHALL 出现锚定该按钮的悬浮 toast,其为圆角胶囊、约 2000ms 后自动消失、SHALL NOT 阻挡指针交互;信息窗内 SHALL NOT 出现行内成功文本 -#### Scenario: 短页签参与等比分配 +#### Scenario: 短页签按实际宽度显示 - **WHEN** 页签标题内容宽小于收缩保底(如两字符文件名) -- **THEN** 页签仍 SHALL 按可用宽度等比分配(与相邻页签等宽),SHALL NOT 以内容宽收缩为短页签;仅当可用宽度低于保底之和 + 间距时才由横向滚动接管 +- **THEN** 页签 SHALL 按内容实际宽度显示,SHALL NOT 被撑到 96px 保底宽 -#### Scenario: 单页签等比分配 +#### Scenario: 单页签不顶满页签条 - **WHEN** 页签条内只有一个页签 -- **THEN** 页签 SHALL 按可用宽度等比分配(`flex: 1 1 0`)填满页签条内容区(尾部空白区 `--tab-strip-tail` 除外),SHALL NOT 以内容宽收缩为短页签 +- **THEN** 页签 SHALL 以其内容宽度(不超过 `--tab-max-width`)显示,页签条剩余空间 SHALL 保持为空白拖窗区,SHALL NOT 被页签铺满 #### Scenario: 扩展名不可编辑 diff --git a/src/components/TabBar.tsx b/src/components/TabBar.tsx index cc0c04f4..dcd46bcb 100644 --- a/src/components/TabBar.tsx +++ b/src/components/TabBar.tsx @@ -700,9 +700,12 @@ export default function TabBar({ aria-selected={isActive} data-tab-color={typeColor} style={{ - // 弹性等比伸缩(flex: 1 1 0):多页签按可用宽度等比分配,随页签条变宽/变窄同比例伸缩; - // 收缩下限 --tab-min-width(96px)保底,低于保底后由页签条横向滚动接管(#1180 / #1843)。 - minWidth: "var(--tab-min-width)", + // 不伸展(flex: 0 1 auto):宽度按内容自适应,上限 --tab-max-width。 + // 保底 = min(96px, 内容宽):短名按实际宽度,不被撑到 96px(G-6 / #1231)。 + // min() 不接受 max-content 关键字(各引擎均丢弃),用 calc-size() 表达同一语义。 + minWidth: + "calc-size(max-content, min(var(--tab-min-width), size))", + maxWidth: "var(--tab-max-width)", ...(isDragged ? { opacity: 0.5, @@ -722,7 +725,7 @@ export default function TabBar({ setEditingId(id); setEditValue(splitStemExt(tab.title).stem); }} - className={`group flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1 text-xs cursor-pointer transition-colors outline-none focus:outline-none focus-visible:outline-none ${ + className={`group flex min-w-0 flex-[0_1_auto] items-center gap-1.5 px-2.5 py-1 text-xs cursor-pointer transition-colors outline-none focus:outline-none focus-visible:outline-none ${ isActive ? "tab-capsule rounded-full bg-[var(--app-accent-soft)] font-medium text-[var(--app-text-strong)]" : "rounded-none bg-transparent text-[var(--app-chrome-rest)] hover:rounded-full hover:bg-[var(--app-sunken)] hover:text-[var(--app-chrome-hover)]" diff --git a/src/styles/tokens.css b/src/styles/tokens.css index 0ab7ce73..b7420825 100644 --- a/src/styles/tokens.css +++ b/src/styles/tokens.css @@ -65,15 +65,14 @@ --media-radius: 6px; /* 自绘悬停提示唯一外壳常量(design-system §5;batch19 A2) */ --tip-shell-radius: var(--radius-full); - /* 页签最小宽度保底;裁决见 docs/design/system/decisions.md(shell-tabs-surface 1.1 / #1843,spec §7.5)。 - 页签 flex: 1 1 0 等比分配,收缩下限即 96px,击穿后由页签条横向滚动接管。 */ + /* 页签最小宽度保底;裁决见 docs/design/system/decisions.md(shell-tabs-surface 1.1,spec §7.5)。 + 保底语义为 min(96px, 内容宽)——短名按实际宽度,不被撑到 96px。 */ --tab-min-width: 96px; /* 页签条尾部空白(承载空白处拖窗 / 双击全屏);spec §7.5 */ --tab-strip-tail: 24px; /* 页签名信息窗固定宽度;同上台账行(design-system §7.4) */ --tab-info-width: 256px; - /* 页签最大宽度上限(spec §7.5):#1843 恢复等比伸缩后退役,不再约束页签宽度; - 保留 token 定义仅为避免既有 var() 引用报错。 */ + /* 页签最大宽度上限,与页签名信息窗同宽(spec §7.5);页签不伸展,宽度按内容自适应 */ --tab-max-width: var(--tab-info-width); /* 文档属性日期选择器密度(design-system §7.6);组件与样式只引用这些 token */ --dpb-cal-width: 300px;