Compare commits

...
Author SHA1 Message Date
l0ng-ai cf14c68309 fix(settings): align the Editor Tabs form 2026-11-23 10:23:09 +08:00
3 changed files with 110 additions and 16 deletions

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
import type { Page } from "@playwright/test";
import { expect, test } from "./fixtures";
async function openEditorTabsSettings(page: Page) {
await page.evaluate(async () => {
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("file.settings", "editor.general.editorTabs");
});
const dialog = page.getByRole("dialog", { name: "Settings", exact: true });
await expect(dialog.getByRole("region", { name: "Closing Policy", exact: true })).toBeVisible();
return dialog;
}
test("Editor Tabs aligns appearance fields and stacks closing choices at both widths", async ({ workbench: page }) => {
const settings = await openEditorTabsSettings(page);
const appearance = settings.getByRole("region", { name: "Appearance", exact: true });
const placement = appearance.getByRole("button", { name: "Tab placement", exact: true });
const closePosition = appearance.getByRole("button", { name: "Close button position", exact: true });
const closing = settings.getByRole("region", { name: "Closing Policy", exact: true });
const limit = closing.getByRole("textbox", { name: "Tab limit", exact: true });
const footer = settings.getByRole("button", { name: "OK", exact: true });
for (const width of [1100, 580]) {
await page.setViewportSize({ width, height: 760 });
const placementBox = (await placement.boundingBox())!;
const closeBox = (await closePosition.boundingBox())!;
expect(Math.abs(placementBox.x - closeBox.x)).toBeLessThanOrEqual(1);
expect(Math.abs(placementBox.width - closeBox.width)).toBeLessThanOrEqual(1);
await expect(placement).toBeInViewport();
await expect(limit).toHaveValue("30");
for (const name of ["When the tab limit is reached", "When the current tab is closed, activate"]) {
const choices = closing.getByRole("radiogroup", { name, exact: true }).getByRole("radio");
const first = (await choices.first().boundingBox())!;
const last = (await choices.last().boundingBox())!;
expect(Math.abs(first.x - last.x)).toBeLessThanOrEqual(1);
expect(last.y).toBeGreaterThan(first.y + first.height);
expect(last.x + last.width).toBeLessThanOrEqual(width);
}
await expect(footer).toBeInViewport();
}
});
test("Editor Tabs keeps row and overflow choices independently selected and keyboard operable", async ({
workbench: page,
}) => {
const settings = await openEditorTabsSettings(page);
const group = settings.getByRole("radiogroup", { name: "Show tabs in", exact: true });
const one = group.getByRole("radio", { name: /^One row/ });
const multiple = group.getByRole("radio", { name: "Multiple rows", exact: true });
const scroll = group.getByRole("radio", { name: "Scroll the tabs panel", exact: true });
const squeeze = group.getByRole("radio", { name: "Squeeze tabs", exact: true });
await expect(one).toBeChecked();
await expect(scroll).toBeChecked();
const oneBox = (await one.boundingBox())!;
const scrollBox = (await scroll.boundingBox())!;
const multipleBox = (await multiple.boundingBox())!;
expect(scrollBox.x).toBeGreaterThan(oneBox.x + 8);
expect(scrollBox.y).toBeGreaterThan(oneBox.y);
expect(Math.abs(multipleBox.x - oneBox.x)).toBeLessThanOrEqual(1);
expect(multipleBox.y).toBeGreaterThan(scrollBox.y);
await scroll.press("ArrowDown");
await expect(squeeze).toBeFocused();
await expect(squeeze).toBeChecked();
await expect(one).toBeChecked();
await one.press("ArrowDown");
await expect(multiple).toBeFocused();
await expect(multiple).toBeChecked();
await expect(squeeze).toBeDisabled();
await expect(squeeze).toBeChecked();
await multiple.press("ArrowUp");
await expect(one).toBeChecked();
await expect(squeeze).toBeEnabled();
await settings.getByRole("button", { name: "OK", exact: true }).click();
const reopened = await openEditorTabsSettings(page);
await expect(reopened.getByRole("radio", { name: /^One row/ })).toBeChecked();
await expect(reopened.getByRole("radio", { name: "Squeeze tabs", exact: true })).toBeChecked();
});
@@ -126,6 +126,9 @@
.stackedRadioBlock {
margin-inline-end: 0;
}
.stackedRadioBlock > .radioLabel {
white-space: normal;
}
.stackedRadios {
max-width: 100%;
}
@@ -136,6 +139,11 @@
.stackedRadioBlock .radioLabel + .stackedRadios {
padding-inline-start: calc(var(--space-4) + var(--space-1));
}
.tabOverflowChoices {
align-items: flex-start;
gap: var(--space-1);
max-width: 100%;
}
.radio {
display: inline-flex;
align-items: center;
+21 -16
View File
@@ -9,7 +9,7 @@ import { useEffect, useId, useState } from "react";
import clsx from "clsx";
import { commands, isTauri } from "@/platform/ipc";
import { Checkbox, Icon, Radio, type IconName } from "@/ui";
import { SearchLabel, Select } from "../../components/Form";
import { Row, SearchLabel, Select } from "../../components/Form";
import { useLabelMatch, useSearchQuery, useSetting } from "../../components/context";
import { labelMatches } from "../../model/pages";
import { editorPage } from "./kit";
@@ -581,6 +581,7 @@ const TABS = editorPage({
t: "radio",
key: `${P}.tabs.closingPolicy`,
label: "When the tab limit is reached",
layout: "stacked",
options: [
{ value: "unchanged", label: "Close non-modified files first" },
{ value: "lru", label: "Close least recently used files" },
@@ -590,6 +591,7 @@ const TABS = editorPage({
t: "radio",
key: `${P}.tabs.activateOnClose`,
label: "When the current tab is closed, activate",
layout: "stacked",
options: [
{ value: "left", label: "The tab on the left" },
{ value: "right", label: "The tab on the right" },
@@ -607,10 +609,11 @@ function TabRows() {
const [overflow, setOverflow] = useSetting<string>(`${P}.tabs.oneRowOverflow`);
const [placement] = useSetting<string>(`${P}.tabs.placement`);
const matched = useLabelMatch("Show tabs in:");
const name = useId();
const rowsName = useId();
const overflowName = useId();
// Vertical (left / right) tabs always scroll in one column.
const disabled = placement === "none" || placement === "left" || placement === "right";
const radio = (label: string, checked: boolean, onChange: () => void, off = disabled) => (
const radio = (name: string, label: string, checked: boolean, onChange: () => void, off = disabled) => (
<label className={clsx(styles.radio, off && styles.dim)}>
<input type="radio" name={name} checked={checked} disabled={off} onChange={onChange} />
<SearchLabel text={label} />
@@ -618,30 +621,36 @@ function TabRows() {
);
return (
<div
className={clsx(styles.radioBlock, matched && styles.matched)}
className={clsx(styles.radioBlock, styles.stackedRadioBlock, matched && styles.matched)}
role="radiogroup"
aria-label={tx("Show tabs in")}
>
<div className={clsx(styles.radioLabel, disabled && styles.dim)}>
<SearchLabel text="Show tabs in" />:
</div>
<div className={styles.radios}>
{radio("One row, and if tabs don't fit:", !multiple, () => setMultiple(false))}
<div className={styles.children} role="radiogroup" aria-label={tx("If tabs don't fit")}>
<div className={clsx(styles.radios, styles.stackedRadios)}>
{radio(rowsName, "One row, and if tabs don't fit:", !multiple, () => setMultiple(false))}
<div
className={clsx(styles.children, styles.tabOverflowChoices)}
role="radiogroup"
aria-label={tx("If tabs don't fit")}
>
{radio(
overflowName,
"Scroll the tabs panel",
!multiple && overflow !== "squeeze",
overflow !== "squeeze",
() => setOverflow("scroll"),
disabled || multiple,
)}
{radio(
overflowName,
"Squeeze tabs",
!multiple && overflow === "squeeze",
overflow === "squeeze",
() => setOverflow("squeeze"),
disabled || multiple,
)}
</div>
{radio("Multiple rows", multiple, () => setMultiple(true))}
{radio(rowsName, "Multiple rows", multiple, () => setMultiple(true))}
</div>
</div>
);
@@ -657,12 +666,8 @@ const CLOSE_POSITIONS = [
function CloseButtonPosition() {
const [show, setShow] = useSetting<boolean>(`${P}.tabs.showCloseButton`);
const [position, setPosition] = useSetting<string>(`${P}.tabs.closeButtonPosition`);
const matched = useLabelMatch("Close button position:");
return (
<div className={clsx(styles.check, matched && styles.matched)}>
<span>
<SearchLabel text="Close button position:" />
</span>
<Row label="Close button position">
<Select
value={show ? (position === "left" ? "left" : "right") : "none"}
options={CLOSE_POSITIONS}
@@ -672,7 +677,7 @@ function CloseButtonPosition() {
if (v !== "none") setPosition(v);
}}
/>
</div>
</Row>
);
}