From 5d6c76cdda832af2e6bd8d6aa76178876b99cc1d Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 09:11:47 +0800 Subject: [PATCH] fix(keymap): make shortcut recording and conflicts easier to read (#5220) The shortcut recorder puts the action name and its category in the dialog body and uses a full-width first field. The optional second stroke stays beside its checkbox. Conflicting actions use two-line rows that keep the action name, category and binding readable in a narrow window. --- e2e/shortcutRecorderLayout.spec.ts | 44 ++++++++++ .../settings/keymap/Keymap.module.css | 80 ++++++++++++------ .../settings/keymap/RecordShortcutDialog.tsx | 81 +++++++++++-------- src/platform/locales/text/en.json | 2 + src/platform/locales/text/es.json | 3 +- src/platform/locales/text/fr.json | 3 +- src/platform/locales/text/ko.json | 3 +- src/platform/locales/text/pl.json | 3 +- src/platform/locales/text/pt.json | 3 +- src/platform/locales/text/tr.json | 3 +- src/platform/locales/text/zh-TW.json | 3 +- src/platform/locales/text/zh.json | 3 +- 12 files changed, 164 insertions(+), 67 deletions(-) create mode 100644 e2e/shortcutRecorderLayout.spec.ts diff --git a/e2e/shortcutRecorderLayout.spec.ts b/e2e/shortcutRecorderLayout.spec.ts new file mode 100644 index 000000000..aaaffafd8 --- /dev/null +++ b/e2e/shortcutRecorderLayout.spec.ts @@ -0,0 +1,44 @@ +import { expect, test } from "./fixtures"; + +test("shortcut assignment fits the first stroke and conflict names in a narrow window", async ({ workbench: page }) => { + await page.setViewportSize({ width: 336, height: 540 }); + await page.keyboard.press("Meta+,"); + const settings = page.getByRole("dialog", { name: "Settings", exact: true }); + await settings.getByRole("treeitem", { name: "Keymap", exact: true }).click(); + await settings.getByRole("textbox", { name: "Search actions" }).fill("Find Action"); + const action = settings.getByRole("treeitem", { name: /Find Action/ }); + await action.click(); + await settings.getByRole("button", { name: "Add Keyboard Shortcut", exact: true }).click(); + + const dialog = page.getByRole("dialog", { name: "Keyboard Shortcut: Find Action…", exact: true }); + const first = dialog.getByRole("textbox", { name: "First stroke" }); + const body = dialog.locator("[data-dialog-body]"); + const titleBar = dialog.locator("[data-dialog-titlebar]"); + await expect(first).toBeFocused(); + await expect(titleBar).toHaveText("Keyboard Shortcut"); + await expect(body.getByText("Find Action…", { exact: true })).toBeVisible(); + const firstBounds = (await first.boundingBox())!; + const bodyBounds = (await body.boundingBox())!; + expect(firstBounds.width).toBeGreaterThan(bodyBounds.width - 32); + const conflicts = dialog.getByRole("list", { name: "Conflicts:" }); + await expect(conflicts).toHaveCount(0); + + await first.press("Meta+Alt+L"); + await expect(conflicts).toBeVisible(); + await expect(conflicts.getByRole("listitem").filter({ hasText: "Reformat Code" }).first()).toBeVisible(); + expect(await conflicts.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + expect( + await conflicts + .getByRole("listitem") + .evaluateAll((rows) => rows.every((row) => row.scrollHeight <= row.clientHeight)), + ).toBe(true); + expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + + const ok = dialog.getByRole("button", { name: "OK", exact: true }); + await ok.click(); + const confirmation = page.getByRole("dialog", { name: "Warning", exact: true }); + await expect(confirmation.getByRole("list").getByText("Reformat Code", { exact: true })).toHaveCount(2); + await confirmation.getByRole("button", { name: "Leave", exact: true }).click(); + await expect(dialog).toBeHidden(); + await expect(action.locator("kbd").filter({ hasText: "⌥⌘L" })).toHaveCount(1); +}); diff --git a/src/features/settings/keymap/Keymap.module.css b/src/features/settings/keymap/Keymap.module.css index 35621de48..b6c53156d 100644 --- a/src/features/settings/keymap/Keymap.module.css +++ b/src/features/settings/keymap/Keymap.module.css @@ -30,9 +30,6 @@ .presetSelect { flex: 1; } -.spacer { - flex: 1; -} .modifiedNote { color: var(--fg-subtle); font-size: var(--fs-small); @@ -195,53 +192,88 @@ .recordLabel { color: var(--fg); } +.shortcutBody { + display: flex; + flex-direction: column; + gap: var(--space-2); + padding: var(--space-2) var(--space-3) 0; + font-size: var(--fs-ui); + overflow-wrap: anywhere; +} +.actionSummary { + display: grid; + gap: var(--space-0-5); +} +.actionName { + color: var(--fg-strong); + font-weight: 600; +} +.shortcutField { + flex: 0 0 auto; + background: var(--bg-field); +} +.shortcutField > span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.secondStroke { + display: flex; + align-items: center; + gap: var(--space-2); +} +.secondStroke > label { + max-width: 55%; +} +.secondStroke .shortcutField { + flex: 1; +} .recordHint { color: var(--fg-subtle); font-size: var(--fs-small); } -.conflicts { - min-height: 72px; - padding: 6px 8px; - border-radius: var(--radius-small); - box-shadow: inset 0 0 0 1px var(--border); -} -.noConflicts { - color: var(--fg-subtle); +.shortcutStatus { + display: grid; + gap: var(--space-1); } .conflictTitle { display: flex; align-items: center; gap: var(--space-1-5); color: var(--fg-emphasis); + font-weight: 600; } .conflictIcon { + flex: none; color: var(--warning); + --icon-color: currentColor; } .conflictList { list-style: none; - margin: 6px 0 0; - padding: 0 0 0 20px; - max-height: 120px; - overflow: auto; + margin: 0; + padding: 0; + max-height: 132px; + overflow-y: auto; } .conflictList li { - display: flex; - min-width: 0; - align-items: center; + display: grid; + grid-template-columns: minmax(0, 1fr) fit-content(42%); + align-items: start; gap: var(--space-2); - height: var(--h-row); + padding-block: var(--space-1); } .conflictAction { color: var(--fg); + overflow-wrap: anywhere; } -.conflictCategory { +.actionPath { color: var(--fg-subtle); font-size: var(--fs-small); } - -.conflictsLabel { - color: var(--fg); - padding-top: 4px; +.conflictBinding { + text-align: end; + white-space: normal; + overflow-wrap: anywhere; } .nameError { color: var(--danger); diff --git a/src/features/settings/keymap/RecordShortcutDialog.tsx b/src/features/settings/keymap/RecordShortcutDialog.tsx index c9a1b4dc8..7f715b5dd 100644 --- a/src/features/settings/keymap/RecordShortcutDialog.tsx +++ b/src/features/settings/keymap/RecordShortcutDialog.tsx @@ -20,7 +20,7 @@ import { findConflicts, resolveBindings, type Conflict, type KeymapDraft } from import { groupPath } from "./groups"; import { StrokeRecorder } from "./StrokeRecorder"; import styles from "./Keymap.module.css"; -import { tx } from "@/platform/i18n"; +import { useTx } from "@/platform/i18n"; import { usePlatform } from "@/platform/platformInfo"; export interface RecordShortcutDialogProps { @@ -39,6 +39,8 @@ export function RecordShortcutDialog({ action, actions, draft, onCancel, onSubmi const [second, setSecond] = useState(""); const [useSecond, setUseSecond] = useState(false); const os = usePlatform((s) => s.os); + const tx = useTx(); + const actionName = tx(action.title); const rectangularSelection = action.id === "editor.createRectangularSelectionOnMouseDrag"; const allowsSecond = !isPageSwipe(first) && !parseDoubleModifier(first); @@ -76,14 +78,23 @@ export function RecordShortcutDialog({ action, actions, draft, onCancel, onSubmi void ok() }, { label: "Cancel", role: "cancel" }, ]} > -
+
+
+
{actionName}
+
+ {groupPath(action) + .map((part) => tx(part)) + .join(" › ")} +
+
{mouse ? ( ) : ( @@ -102,31 +113,23 @@ export function RecordShortcutDialog({ action, actions, draft, onCancel, onSubmi On Linux, middle-button rectangular selection conflicts with primary selection paste.
)} -
- Conflicts: -
-
+
{already && ( - + The action already has this shortcut )} {!already && binding && conflicts.length === 0 && ( - + No conflicts )} - {!binding && ( - - Press a shortcut - - )} {conflicts.length > 0 && ( <>
- is already assigned to: + is already assigned to:
@@ -139,21 +142,26 @@ export function RecordShortcutDialog({ action, actions, draft, onCancel, onSubmi } function ConflictList({ conflicts }: { conflicts: readonly Conflict[] }) { + const tx = useTx(); return ( -
    +
      {conflicts.map((c) => (
    • - {c.title} - - ({groupPath({ id: c.actionId, category: c.category }).join(" | ")}) - - - {c.kind === "prefix" && ( - - chord prefix +
      +
      {tx(c.title)}
      + + {groupPath({ id: c.actionId, category: c.category }) + .map((part) => tx(part)) + .join(" › ")} + {c.kind === "prefix" && ( + <> + {" "} + · chord prefix + + )} - )} - +
      +
    • ))}
    @@ -171,23 +179,26 @@ interface KeyStrokesProps { } function KeyStrokes({ first, second, useSecond, allowsSecond, setFirst, setSecond, setUseSecond }: KeyStrokesProps) { + const tx = useTx(); return ( <> -
    - - First stroke: - - -
    -
    + +
    diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index f2e25dd94..ca44332ec 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2497,6 +2497,8 @@ "e.g. /api/": "e.g. /api/", "Part of a request URL": "Part of a request URL", "Mouse": "Mouse", + "Keyboard Shortcut": "Keyboard Shortcut", + "Mouse Shortcut": "Mouse Shortcut", "Keyboard": "Keyboard", "Form": "Form", "Page": "Page", diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index 5ba16adb8..20dfec059 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -890,7 +890,6 @@ "Find…": "Buscar…", "First letter only": "Solo la primera letra", "First stroke": "Primera combinación de teclas", - "First stroke:": "Primera combinación de teclas:", "Fix the highlighted fields": "Corrige los campos resaltados", "Flame Graph": "Gráfico de llamas", "Flame graph": "Gráfico de llamas", @@ -4088,6 +4087,7 @@ "based on {parent}": "basado en {parent}", "Delete keymap '{name}'?": "¿Eliminar el mapa de teclado '{name}'?", "Remove {shortcut}": "Quitar {shortcut}", + "Keyboard Shortcut": "Atajo de teclado", "Keyboard Shortcut: {action}": "Atajo de teclado: {action}", "Remove content root {path}": "Quitar raíz de contenido {path}", "Unmark {folder}": "Desmarcar {folder}", @@ -4827,6 +4827,7 @@ "Add Mouse Shortcut": "Agregar atajo de ratón", "Click here with Ctrl, Alt or Command held, or use a middle or side mouse button": "Haga clic aquí manteniendo presionado Ctrl, Alt o Command, o use el botón central o un botón lateral del ratón", "Mouse shortcut": "Atajo de ratón", + "Mouse Shortcut": "Atajo de ratón", "Mouse Shortcut: {action}": "Atajo de ratón: {action}", "Accept Left Side": "Aceptar lado izquierdo", "Accept Right Side": "Aceptar lado derecho", diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index 983a4baa0..3aef6b3eb 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -827,7 +827,6 @@ "Find…": "Rechercher…", "First letter only": "Première lettre uniquement", "First stroke": "Première touche", - "First stroke:": "Première touche :", "Fix the highlighted fields": "Corrigez les champs mis en évidence", "Flame Graph": "Flame graph", "Flame graph": "Flame graph", @@ -3952,6 +3951,7 @@ "based on {parent}": "basé sur {parent}", "Delete keymap '{name}'?": "Supprimer les raccourcis clavier '{name}' ?", "Remove {shortcut}": "Retirer {shortcut}", + "Keyboard Shortcut": "Raccourci clavier", "Keyboard Shortcut: {action}": "Raccourci clavier : {action}", "Remove content root {path}": "Retirer la racine de contenu {path}", "Unmark {folder}": "Démarquer {folder}", @@ -4682,6 +4682,7 @@ "Add Mouse Shortcut": "Ajouter un raccourci souris", "Click here with Ctrl, Alt or Command held, or use a middle or side mouse button": "Cliquez ici en maintenant Ctrl, Alt ou Commande, ou utilisez le bouton central ou un bouton latéral de la souris", "Mouse shortcut": "Raccourci souris", + "Mouse Shortcut": "Raccourci souris", "Mouse Shortcut: {action}": "Raccourci souris : {action}", "Accept Left Side": "Accepter le côté gauche", "Accept Right Side": "Accepter le côté droit", diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index 3a3b0757c..1be07f421 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -926,7 +926,6 @@ "Find…": "찾기…", "First letter only": "첫 글자만", "First stroke": "첫 번째 키 입력", - "First stroke:": "첫 번째 키 입력:", "Fix the highlighted fields": "강조 표시된 필드를 수정하세요", "Flame Graph": "플레임 그래프", "Flame graph": "플레임 그래프", @@ -4149,6 +4148,7 @@ "based on {parent}": "{parent} 기반", "Delete keymap '{name}'?": "키맵 '{name}'을(를) 삭제하시겠습니까?", "Remove {shortcut}": "{shortcut} 제거", + "Keyboard Shortcut": "키보드 단축키", "Keyboard Shortcut: {action}": "키보드 단축키: {action}", "Remove content root {path}": "콘텐츠 루트 {path} 제거", "Unmark {folder}": "{folder} 표시 해제", @@ -4899,6 +4899,7 @@ "Add Mouse Shortcut": "마우스 단축키 추가", "Click here with Ctrl, Alt or Command held, or use a middle or side mouse button": "Ctrl, Alt 또는 Command를 누른 채 여기를 클릭하거나 마우스 가운데 버튼 또는 측면 버튼을 사용하세요", "Mouse shortcut": "마우스 단축키", + "Mouse Shortcut": "마우스 단축키", "Mouse Shortcut: {action}": "마우스 단축키: {action}", "Accept Left Side": "왼쪽 수락", "Accept Right Side": "오른쪽 수락", diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index 941bd223e..2d2970712 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -882,7 +882,6 @@ "Find…": "Znajdź…", "First letter only": "Tylko pierwsza litera", "First stroke": "Naciśnięcie pierwsze", - "First stroke:": "Naciśnięcie pierwsze:", "Fix the highlighted fields": "Popraw podświetlone pola", "Flame Graph": "Wykres płomieniowy (Flame Graph)", "Flame graph": "Wykres płomieniowy", @@ -4044,6 +4043,7 @@ "based on {parent}": "na podstawie {parent}", "Delete keymap '{name}'?": "Usunąć mapę klawiszy '{name}'?", "Remove {shortcut}": "Usuń {shortcut}", + "Keyboard Shortcut": "Skrót klawiszowy", "Keyboard Shortcut: {action}": "Skrót klawiszowy: {action}", "Remove content root {path}": "Usuń katalog główny zawartości {path}", "Unmark {folder}": "Odznacz {folder}", @@ -4778,6 +4778,7 @@ "Add Mouse Shortcut": "Dodaj skrót myszy", "Click here with Ctrl, Alt or Command held, or use a middle or side mouse button": "Kliknij tutaj przytrzymując Ctrl, Alt lub Command albo użyj środkowego lub bocznego przycisku myszy", "Mouse shortcut": "Skrót myszy", + "Mouse Shortcut": "Skrót myszy", "Mouse Shortcut: {action}": "Skrót myszy: {action}", "Accept Left Side": "Zaakceptuj lewą stronę", "Accept Right Side": "Zaakceptuj prawą stronę", diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index 46ffc452a..0a2c73b76 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -882,7 +882,6 @@ "Find…": "Localizar…", "First letter only": "Apenas primeira letra", "First stroke": "Primeiro toque", - "First stroke:": "Primeiro toque:", "Fix the highlighted fields": "Corrija os campos destacados", "Flame Graph": "Flame Graph", "Flame graph": "Flame graph", @@ -4054,6 +4053,7 @@ "based on {parent}": "com base em {parent}", "Delete keymap '{name}'?": "Excluir o mapa de teclas '{name}'?", "Remove {shortcut}": "Remover {shortcut}", + "Keyboard Shortcut": "Atalho do teclado", "Keyboard Shortcut: {action}": "Atalho do teclado: {action}", "Remove content root {path}": "Remover raiz de conteúdo {path}", "Unmark {folder}": "Desmarcar {folder}", @@ -4793,6 +4793,7 @@ "Add Mouse Shortcut": "Adicionar atalho de mouse", "Click here with Ctrl, Alt or Command held, or use a middle or side mouse button": "Clique aqui mantendo Ctrl, Alt ou Command pressionado, ou use o botão do meio ou um botão lateral do mouse", "Mouse shortcut": "Atalho de mouse", + "Mouse Shortcut": "Atalho de mouse", "Mouse Shortcut: {action}": "Atalho de mouse: {action}", "Accept Left Side": "Aceitar lado esquerdo", "Accept Right Side": "Aceitar lado direito", diff --git a/src/platform/locales/text/tr.json b/src/platform/locales/text/tr.json index eb1a168d6..9d2bf18d7 100644 --- a/src/platform/locales/text/tr.json +++ b/src/platform/locales/text/tr.json @@ -3676,7 +3676,6 @@ "Find…": "Bul…", "First letter only": "Yalnızca ilk harf", "First stroke": "İlk tuş birleşimi", - "First stroke:": "İlk tuş birleşimi:", "Fix the highlighted fields": "Vurgulanan alanları düzeltin", "Flame Graph": "Alev Grafiği", "Flame graph": "Alev grafiği", @@ -6777,6 +6776,7 @@ "based on {parent}": "{parent} temel alınarak", "Delete keymap '{name}'?": "'{name}' tuş eşlemi silinsin mi?", "Remove {shortcut}": "{shortcut} kaldır", + "Keyboard Shortcut": "Klavye Kısayolu", "Keyboard Shortcut: {action}": "Klavye Kısayolu: {action}", "Remove content root {path}": "{path} içerik kökünü kaldır", "Unmark {folder}": "{folder} işaretini kaldır", @@ -7501,6 +7501,7 @@ "Sort by Modification Time": "Değiştirilme Zamanına Göre Sırala", "Add Mouse Shortcut": "Fare Kısayolu Ekle", "Mouse shortcut": "Fare kısayolu", + "Mouse Shortcut": "Fare Kısayolu", "Mouse Shortcut: {action}": "Fare Kısayolu: {action}", "Accept Left Side": "Sol Tarafı Kabul Et", "Accept Right Side": "Sağ Tarafı Kabul Et", diff --git a/src/platform/locales/text/zh-TW.json b/src/platform/locales/text/zh-TW.json index 9dbf13753..af0376ef5 100644 --- a/src/platform/locales/text/zh-TW.json +++ b/src/platform/locales/text/zh-TW.json @@ -1550,7 +1550,6 @@ "Find…": "查詢…", "First letter only": "僅首字母", "First stroke": "第一次擊鍵", - "First stroke:": "第一次擊鍵:", "Fix the highlighted fields": "請修復醒目提示的欄位", "Flame Graph": "火焰圖", "Flame graph": "火焰圖", @@ -5033,6 +5032,7 @@ "based on {parent}": "基於 {parent}", "Delete keymap '{name}'?": "是否刪除按鍵對映 '{name}'?", "Remove {shortcut}": "移除 {shortcut}", + "Keyboard Shortcut": "鍵盤快速鍵", "Keyboard Shortcut: {action}": "鍵盤快速鍵:{action}", "Remove content root {path}": "移除內容根 {path}", "Unmark {folder}": "取消標記 {folder}", @@ -5812,6 +5812,7 @@ "Click here with Ctrl, Alt or Command held, or use a middle or side mouse button": "按住 Ctrl、Alt 或 Command 在此點選,或使用滑鼠中鍵或側鍵", "Click here with Ctrl, Alt or Command held, or use the middle mouse button": "按住 Ctrl、Alt 或 Command 在此點選,或使用滑鼠中鍵", "Mouse shortcut": "滑鼠快速鍵", + "Mouse Shortcut": "滑鼠快速鍵", "Mouse Shortcut: {action}": "滑鼠快速鍵:{action}", "Accept Left Side": "接受左側", "Accept Right Side": "接受右側", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 0d2dbf6da..803d01ed9 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1917,7 +1917,6 @@ "Find…": "查找…", "First letter only": "仅首字母", "First stroke": "第一次击键", - "First stroke:": "第一次击键:", "Fix the highlighted fields": "请修复高亮显示的字段", "Flame Graph": "火焰图", "Flame graph": "火焰图", @@ -5483,6 +5482,8 @@ "based on {parent}": "基于 {parent}", "Delete keymap '{name}'?": "是否删除按键映射 '{name}'?", "Remove {shortcut}": "移除 {shortcut}", + "Keyboard Shortcut": "键盘快捷键", + "Mouse Shortcut": "鼠标快捷键", "Keyboard Shortcut: {action}": "键盘快捷键:{action}", "Remove content root {path}": "移除内容根 {path}", "Unmark {folder}": "取消标记 {folder}",