mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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.
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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<HTMLButtonElement>(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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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": "全部折叠",
|
||||
|
||||
Reference in New Issue
Block a user