Compare commits

...
Author SHA1 Message Date
l0ng-ai 30cf333331 fix(editor): keep same-name tabs distinguishable 2026-11-22 16:30:30 +08:00
3 changed files with 78 additions and 2 deletions

No files matched your search

+46
View File
@@ -69,3 +69,49 @@ test("the bottom single row keeps a long selected tab visible alongside the hidd
await pane.getByRole("tab", { name: shortFile, exact: true }).press("End");
await expectCloseToFit(tab);
});
test("same-name tabs keep the filename beside a shortened directory", async ({ workbench: page }) => {
const filename = "AllocationRule.ts";
const first = "qa";
const second = "backoffice-reconciliation";
await openSplit(page, [`${first}/${filename}`, `${second}/${filename}`], "top");
await page.setViewportSize({ width: 900, height: 760 });
const pane = page.locator("section[data-pane-id]").filter({
has: page.getByRole("tab").filter({ hasText: second }),
});
const selected = pane.getByRole("tab").filter({ hasText: second });
await expect(selected).toHaveText(`${second}/${filename}`);
await expectCloseToFit(selected);
const directory = selected.getByText(`${second}/`, { exact: true });
const name = selected.getByText(filename, { exact: true });
await expect.poll(() => directory.evaluate((el) => el.clientWidth > 0 && el.scrollWidth > el.clientWidth)).toBe(true);
await expect
.poll(() =>
name.evaluate((el) => {
const text = document.createRange();
text.selectNodeContents(el);
return el.getBoundingClientRect().width >= text.getBoundingClientRect().width;
}),
)
.toBe(true);
await pane.getByRole("button", { name: "Show Hidden Tabs" }).click();
const picker = page.getByRole("grid", { name: "Hidden Editor Tabs" });
await expect(picker.getByRole("gridcell").filter({ hasText: `${first}/${filename}` })).toBeVisible();
await page.keyboard.press("Enter");
const firstTab = pane.getByRole("tab").filter({ hasText: first });
await expectCloseToFit(firstTab);
await expect
.poll(() =>
firstTab.getByText(`${first}/`, { exact: true }).evaluate((el) => {
const text = document.createRange();
text.selectNodeContents(el);
return Math.abs(el.clientWidth - text.getBoundingClientRect().width);
}),
)
.toBeLessThanOrEqual(1);
await firstTab.locator("..").getByRole("button", { name: "Close Tab", exact: true }).click();
await expect(page.getByRole("tab", { name: filename, exact: true })).toHaveAttribute("aria-selected", "true");
});
@@ -150,6 +150,28 @@
.deprecated {
text-decoration-line: line-through;
}
.tabPath {
--tab-directory-min: min(5ch, 25%);
display: flex;
}
.tabDirectory > span,
.tabFilename {
overflow: hidden;
text-overflow: ellipsis;
}
.tabDirectory {
flex: 0 1000 max-content;
/* Leave space for a short prefix without stretching one that already fits. */
width: var(--tab-directory-min);
color: var(--fg-subtle);
}
.tabDirectory > span {
display: block;
}
.tabFilename {
flex: none;
max-width: calc(100% - var(--tab-directory-min));
}
.dupe {
color: var(--fg-faint);
margin-left: 4px;
+10 -2
View File
@@ -219,15 +219,23 @@ function PaneView({ paneId }: { paneId: string }) {
const pin = t.pinned ? <Icon name="pin" size={11} className={styles.pin} label="Pinned" /> : null;
const file = t.input.kind === "file" && t.input.path ? files.get(t.input.path) : undefined;
const title = markModified && dirty[i] ? `*${name}` : name;
const prefix = t.input.kind === "file" && dupe ? (dupe.endsWith("/") ? dupe : `${dupe}/`) : null;
return {
id: t.id,
label: (
label: prefix ? (
<span className={styles.tabPath}>
<span className={styles.tabDirectory}>
<span>{prefix}</span>
</span>
<span className={clsx(styles.tabFilename, file?.deprecated && styles.deprecated)}>{title}</span>
</span>
) : (
<>
{file?.deprecated ? <span className={styles.deprecated}>{title}</span> : title}
{dupe && <span className={styles.dupe}>{dupe}</span>}
</>
),
text: dupe ? `${name} — ${dupe}` : name,
text: prefix ? `${prefix}${name}` : dupe ? `${name} — ${dupe}` : name,
icon: showFileIcon
? t.input.kind === "file" && t.input.path
? (tabIcons[i] ?? file?.icon)