From f2c0fcdc96cfe47a24ffda23a7e5bf7b0eafef7e Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 23:54:10 +0800 Subject: [PATCH] fix(settings): align Smart Keys backspace and paste controls (#4823) Settings > Editor > General > Smart Keys places the Backspace and paste formatting controls directly below the Enter options; the two controls share a label column and the paste escaping option sits below the formatting control. --- e2e/smartKeysLayout.spec.ts | 67 +++++++++++++++++++ .../settings/pages/editor/general.tsx | 55 ++++++++------- src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + 4 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 e2e/smartKeysLayout.spec.ts diff --git a/e2e/smartKeysLayout.spec.ts b/e2e/smartKeysLayout.spec.ts new file mode 100644 index 000000000..d0179eefb --- /dev/null +++ b/e2e/smartKeysLayout.spec.ts @@ -0,0 +1,67 @@ +import type { Page } from "@playwright/test"; +import { expect, test } from "./fixtures"; + +async function openSmartKeys(page: Page) { + await page.keyboard.press("Meta+,"); + const dialog = page.getByRole("dialog", { name: "Settings", exact: true }); + await dialog.getByRole("textbox", { name: "Search settings" }).fill("Smart Keys"); + await dialog.getByRole("treeitem", { name: "Smart Keys", exact: true }).click(); + return dialog; +} + +test("backspace and paste controls align below Enter options in Smart Keys", async ({ workbench: page }) => { + const dialog = await openSmartKeys(page); + const enter = dialog.getByRole("region", { name: "Enter", exact: true }); + const unindent = dialog.getByRole("button", { name: /^Unindent(?: on Backspace)?$/ }); + const paste = dialog.getByRole("button", { name: "Reformat on paste", exact: true }); + const escape = dialog.getByRole("checkbox", { name: "Escape text on paste in string literals", exact: true }); + + for (const width of [1120, 520]) { + await page.setViewportSize({ width, height: 760 }); + await expect(unindent).toBeInViewport({ ratio: 0.98 }); + await expect(paste).toBeInViewport({ ratio: 0.98 }); + const enterBox = (await enter.boundingBox())!; + const unindentBox = (await unindent.boundingBox())!; + const pasteBox = (await paste.boundingBox())!; + expect(unindentBox.y).toBeGreaterThan(enterBox.y + enterBox.height); + expect(pasteBox.y).toBeGreaterThanOrEqual(unindentBox.y + unindentBox.height); + expect(Math.abs(pasteBox.x - unindentBox.x)).toBeLessThan(1); + expect((await escape.boundingBox())!.y).toBeGreaterThanOrEqual(pasteBox.y + pasteBox.height); + } + + await paste.click(); + await expect(page.getByRole("option", { name: "Indent Each Line", exact: true })).toBeInViewport(); +}); + +test("Smart Keys keeps backspace and paste preferences independent across Apply and Cancel", async ({ + workbench: page, +}) => { + const setOption = async (label: string, option: string) => { + await page + .getByRole("dialog", { name: "Settings", exact: true }) + .getByRole("button", { name: label, exact: true }) + .click(); + await page.getByRole("option", { name: option, exact: true }).click(); + }; + + const dialog = await openSmartKeys(page); + await setOption("Unindent on Backspace", "To nearest indent position"); + await setOption("Reformat on paste", "Indent Block"); + await dialog.getByRole("button", { name: "Apply", exact: true }).click(); + await expect(dialog.getByRole("button", { name: "Apply", exact: true })).toBeDisabled(); + await dialog.getByRole("button", { name: "Cancel", exact: true }).click(); + + const reopened = await openSmartKeys(page); + await expect(reopened.getByRole("button", { name: "Unindent on Backspace", exact: true })).toHaveText( + "To nearest indent position", + ); + await expect(reopened.getByRole("button", { name: "Reformat on paste", exact: true })).toHaveText("Indent Block"); + await setOption("Reformat on paste", "None"); + await reopened.getByRole("button", { name: "Cancel", exact: true }).click(); + + const final = await openSmartKeys(page); + await expect(final.getByRole("button", { name: "Unindent on Backspace", exact: true })).toHaveText( + "To nearest indent position", + ); + await expect(final.getByRole("button", { name: "Reformat on paste", exact: true })).toHaveText("Indent Block"); +}); diff --git a/src/features/settings/pages/editor/general.tsx b/src/features/settings/pages/editor/general.tsx index 1e3c492f5..b89ec3b88 100644 --- a/src/features/settings/pages/editor/general.tsx +++ b/src/features/settings/pages/editor/general.tsx @@ -736,12 +736,6 @@ const SMART_KEYS = editorPage({ { items: [ { t: "check", key: `${P}.smartKeys.smartHome`, label: "Home moves caret to first non-whitespace character" }, - { - t: "check", - key: `${P}.smartKeys.camelHumps`, - label: 'Use "CamelHumps" words', - hint: "⌥← / ⌥→ and ⌥⌫ stop at humps of camelCase names.", - }, { t: "check", key: `${P}.smartKeys.pairBrackets`, @@ -749,9 +743,36 @@ const SMART_KEYS = editorPage({ hint: "Also pairs <> for generics where the syntax says a type starts.", }, { t: "check", key: `${P}.smartKeys.pairQuotes`, label: "Insert pair quote" }, + { + t: "check", + key: `${P}.smartKeys.camelHumps`, + label: 'Use "CamelHumps" words', + hint: "⌥← / ⌥→ and ⌥⌫ stop at humps of camelCase names.", + }, { t: "check", key: `${P}.smartKeys.surroundSelection`, label: "Surround selection on typing quote or brace" }, { t: "check", key: `${P}.smartKeys.tabOutOfPair`, label: "Jump outside closing bracket/quote with Tab" }, { t: "check", key: `${P}.smartKeys.simultaneousTagEditing`, label: "Simultaneous editing" }, + ], + }, + { + title: "Enter", + items: [ + { t: "check", key: `${P}.smartKeys.smartIndent`, label: "Smart indent" }, + { t: "check", key: `${P}.smartKeys.insertDocStub`, label: "Insert documentation comment stub" }, + ], + }, + { + items: [ + { + t: "select", + key: `${P}.smartKeys.backspaceUnindent`, + label: "Unindent on Backspace", + options: [ + { value: "autoindent", label: "To proper indent position" }, + { value: "nearest", label: "To nearest indent position" }, + { value: "none", label: "Disabled" }, + ], + }, { t: "select", key: `${P}.smartKeys.reformatOnPaste`, @@ -769,28 +790,6 @@ const SMART_KEYS = editorPage({ }, ], }, - { - title: "Enter", - items: [ - { t: "check", key: `${P}.smartKeys.smartIndent`, label: "Smart indent" }, - { t: "check", key: `${P}.smartKeys.insertDocStub`, label: "Insert documentation comment stub" }, - ], - }, - { - title: "Backspace", - items: [ - { - t: "select", - key: `${P}.smartKeys.backspaceUnindent`, - label: "Unindent", - options: [ - { value: "autoindent", label: "To proper indent position" }, - { value: "nearest", label: "To nearest indent position" }, - { value: "none", label: "Disabled" }, - ], - }, - ], - }, ], }); diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index ac02c12f5..aa9f33dd4 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -514,6 +514,7 @@ "Inlay hint preview": "Inlay hint preview", "Inlay hint categories": "Inlay hint categories", "Parameter": "Parameter", + "Unindent on Backspace": "Unindent on Backspace", "Global variable": "Global variable", "Package reference": "Package reference", "Constant": "Constant", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 13c7af12d..92f239cfe 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -457,6 +457,7 @@ "Inlay hint preview": "嵌入提示预览", "Inlay hint categories": "嵌入提示类别", "Parameter": "参数", + "Unindent on Backspace": "按退格键取消缩进", "Package reference": "包引用", "Instance field": "实例字段", "Static symbol": "静态符号",