From cf14c683092026a7fe2f9e5e7b09b77784f552be Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:23:09 +0800 Subject: [PATCH] fix(settings): align the Editor Tabs form --- e2e/editorTabsSettingsLayout.spec.ts | 81 +++++++++++++++++++ .../settings/pages/editor/Editor.module.css | 8 ++ .../settings/pages/editor/general.tsx | 37 +++++---- 3 files changed, 110 insertions(+), 16 deletions(-) create mode 100644 e2e/editorTabsSettingsLayout.spec.ts diff --git a/e2e/editorTabsSettingsLayout.spec.ts b/e2e/editorTabsSettingsLayout.spec.ts new file mode 100644 index 0000000000..1414a3e845 --- /dev/null +++ b/e2e/editorTabsSettingsLayout.spec.ts @@ -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(); +}); diff --git a/src/features/settings/pages/editor/Editor.module.css b/src/features/settings/pages/editor/Editor.module.css index 5d92fdbb0a..f119ce682b 100644 --- a/src/features/settings/pages/editor/Editor.module.css +++ b/src/features/settings/pages/editor/Editor.module.css @@ -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; diff --git a/src/features/settings/pages/editor/general.tsx b/src/features/settings/pages/editor/general.tsx index 5f123f324b..37efbc284b 100644 --- a/src/features/settings/pages/editor/general.tsx +++ b/src/features/settings/pages/editor/general.tsx @@ -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(`${P}.tabs.oneRowOverflow`); const [placement] = useSetting(`${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) => (