From 31c169c889ec8b392afa4e30246c43e1a476980e Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 20:05:32 +0800 Subject: [PATCH] fix(editor): give the indentation chooser a code style heading (#5008) The indentation popup uses a Code Style heading for the active file's language. The current indentation stays checked even when the file uses a custom number of spaces. The heading and choices use the standard menu text size. --- e2e/editor.spec.ts | 34 ++++++++++++++++++++++++++++ src/editor/core/view/StatusItems.tsx | 17 +++++++++----- src/platform/locales/text/en.json | 5 ++++ src/platform/locales/text/zh.json | 4 ++++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/e2e/editor.spec.ts b/e2e/editor.spec.ts index 864dc0c3b..b3aed8d14 100644 --- a/e2e/editor.spec.ts +++ b/e2e/editor.spec.ts @@ -13,6 +13,40 @@ test("opens a file from the project tree and types into it", async ({ workbench: await expect(editor.locator(".cm-content")).not.toContainText("// typed by e2e"); }); +test("indentation shows the language and current width with room for the keyboard choices", async ({ + workbench: page, +}) => { + await openFromTree(page, "build.gradle.kts"); + await page.evaluate(async () => { + const path = "/src/editor/core/controller.ts"; + const { editorController, useEditorStatus } = await import(/* @vite-ignore */ path); + const active = useEditorStatus.getState().status!.path; + editorController().manager.get(active)!.setIndent({ tabSize: 3, insertSpaces: true }); + }); + + const status = page.getByRole("button", { name: "3 spaces", exact: true }); + await status.click(); + const menu = page.getByRole("menu", { name: "Indentation", exact: true }); + const title = page.getByText("Kotlin Code Style", { exact: true }); + await expect(title).toBeVisible(); + await page.setViewportSize({ width: 500, height: 520 }); + await expect(title).toBeInViewport({ ratio: 1 }); + await expect(title).toHaveCSS("font-size", "13px"); + await expect(title).toHaveCSS("font-weight", "600"); + await expect(menu.getByRole("menuitemcheckbox", { name: "3 spaces", checked: true })).toBeInViewport({ ratio: 1 }); + await expect(menu.getByRole("menuitem", { name: "Configure Indents…" })).toBeInViewport({ ratio: 1 }); + + await expect(menu.getByRole("menuitemcheckbox", { name: "2 spaces", checked: false })).toBeFocused(); + await page.keyboard.press("ArrowDown"); + await page.keyboard.press("ArrowDown"); + await page.keyboard.press("Enter"); + await expect(menu).toBeHidden(); + const four = page.getByRole("button", { name: "4 spaces", exact: true }); + await expect(four).toBeVisible(); + await four.click(); + await expect(menu.getByRole("menuitemcheckbox", { name: "4 spaces", checked: true })).toBeVisible(); +}); + test("Delete edits text after the focused Project tree is remounted", async ({ workbench: page }) => { const editor = await openFromTree(page, "README.md"); const content = editor.locator(".cm-content"); diff --git a/src/editor/core/view/StatusItems.tsx b/src/editor/core/view/StatusItems.tsx index ffcef4136..b47f88cfe 100644 --- a/src/editor/core/view/StatusItems.tsx +++ b/src/editor/core/view/StatusItems.tsx @@ -30,6 +30,7 @@ import { untitledTitle, } from "@/platform/virtualDocs"; import { editorController, isTextInput, useEditorStatus, useGotoLine, useTabs } from "../controller"; +import { languageInfo } from "../cm/languages"; import { useDocMeta, useOutline, type DocMeta } from "../model/document"; import { symbolChain } from "./outline"; import { NavChildrenPopup } from "./NavBarPopup"; @@ -625,13 +626,18 @@ export function IndentStatus() { const ref = useRef(null); if (!meta) return null; const { tabSize, insertSpaces } = meta.indent; - const label = insertSpaces ? `${tabSize} spaces` : `Tab (${tabSize})`; + const language = languageInfo(meta.language)?.name; + const title = language ? tx`${language} Code Style` : tx("Code Style"); + const spaces = (width: number) => (width === 1 ? tx`${width} space` : tx`${width} spaces`); + const tabs = tx`Tab (${tabSize})`; + const widths = [...new Set(insertSpaces ? [2, 4, 8, tabSize] : [2, 4, 8])].sort((a, b) => a - b); + const label = insertSpaces ? spaces(tabSize) : tabs; const set = (indent: { tabSize: number; insertSpaces: boolean }) => editorController().manager.get(meta.path)?.setIndent(indent); const choice = (id: string, text: string, indent: { tabSize: number; insertSpaces: boolean }) => ({ id, label: text, - checked: indent.tabSize === tabSize && indent.insertSpaces === insertSpaces ? true : undefined, + checked: indent.tabSize === tabSize && indent.insertSpaces === insertSpaces, run: () => set(indent), }); return ( @@ -650,12 +656,11 @@ export function IndentStatus() { onClose={() => setOpen(false)} anchor={ref} placement="top-end" + title={title} aria-label="Indentation" items={[ - choice("s2", "2 spaces", { tabSize: 2, insertSpaces: true }), - choice("s4", "4 spaces", { tabSize: 4, insertSpaces: true }), - choice("s8", "8 spaces", { tabSize: 8, insertSpaces: true }), - choice("tab", `Tab (${tabSize})`, { tabSize, insertSpaces: false }), + ...widths.map((width) => choice(`s${width}`, spaces(width), { tabSize: width, insertSpaces: true })), + choice("tab", tabs, { tabSize, insertSpaces: false }), { kind: "separator" }, { id: "configure", diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 88d5e69d3..3fe5450cc 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,9 @@ { + "Code Style": "Code Style", + "{language} Code Style": "{language} Code Style", + "{width} space": "{width} space", + "{width} spaces": "{width} spaces", + "Tab ({tabSize})": "Tab ({tabSize})", "Timeline": "Timeline", "At breakpoint": "At breakpoint", "Replacement preview": "Replacement preview", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 7622be635..f5825b916 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1080,6 +1080,10 @@ "Code Structure": "代码结构", "Code Folding": "代码折叠", "Code Style": "代码样式", + "{language} Code Style": "{language} 代码样式", + "{width} space": "{width} 个空格", + "{width} spaces": "{width} 个空格", + "Tab ({tabSize})": "制表符({tabSize})", "Code breadcrumbs": "代码痕迹导航", "Collapse": "折叠", "Collapse All": "全部折叠",