Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-9250 fix(shortcuts): free unclaimed modifier variants and record macOS Option chords (#10590)
Jiayuan Zhang0da7ec40d115
diff --git a/packages/core/shortcuts/definitions.test.ts b/packages/core/shortcuts/definitions.test.tsindex 85e095ae6d..ecb9a2f0fd 100644--- a/packages/core/shortcuts/definitions.test.ts+++ b/packages/core/shortcuts/definitions.test.ts@@ -304,6 +304,127 @@ describe("keyboard shortcut definitions", () => {).toBe(true);});+ it("frees modifier variants of reserved keys that nothing else assigns", () => {+ const free = [+ createShortcutChord("X", { primary: true, shift: true }),+ createShortcutChord("Y", { primary: true, shift: true }),+ createShortcutChord("A", { primary: true, alt: true }),+ createShortcutChord("Z", { primary: true, alt: true }),+ createShortcutChord("H", { primary: true, shift: true }),+ createShortcutChord("M", { primary: true, shift: true }),+ ];+ for (const chord of free) {+ for (const runtime of ["web", "desktop"] as const) {+ expect(+ isShortcutAllowedForAction("goInbox", chord, "macos", runtime),+ `${formatShortcut(chord, "macos")} on macos/${runtime}`,+ ).toBe(true);+ }+ }+ expect(+ isShortcutAllowedForAction(+ "openSearch",+ createShortcutChord("X", { primary: true, shift: true }),+ "windows",+ "web",+ ),+ ).toBe(true);+ });++ it("keeps the variants the OS, desktop menu or browser assign", () => {+ const everywhere = [+ createShortcutChord("Z", { primary: true, shift: true }),+ createShortcutChord("V", { primary: true, shift: true }),+ createShortcutChord("V", { primary: true, alt: true, shift: true }),+ createShortcutChord("H", { primary: true, alt: true }),+ createShortcutChord("M", { primary: true, alt: true }),+ createShortcutChord("F", { primary: true, control: true }),+ createShortcutChord("W", { primary: true, alt: true }),+ createShortcutChord("3", { primary: true, shift: true }),+ ];+ for (const chord of everywhere) {+ for (const runtime of ["web", "desktop"] as const) {+ expect(+ isReservedShortcut(chord, "macos", runtime),+ `${formatShortcut(chord, "macos")} on macos/${runtime}`,+ ).toBe(true);+ }+ }+ });++ it("reserves Electron's DevTools accelerator on desktop only", () => {+ const macDevTools = createShortcutChord("I", { primary: true, alt: true });+ expect(isReservedShortcut(macDevTools, "macos", "desktop")).toBe(true);+ expect(isShortcutAllowedForAction("openSearch", macDevTools, "macos", "web")).toBe(true);+ const devTools = createShortcutChord("I", { primary: true, shift: true });+ for (const platform of ["windows", "linux"] as const) {+ expect(isReservedShortcut(devTools, platform, "desktop")).toBe(true);+ expect(isShortcutAllowedForAction("openSearch", devTools, platform, "web")).toBe(true);+ }+ // Browser DevTools chords a page can claim stay recordable.+ expect(+ isReservedShortcut(createShortcutChord("C", { primary: true, shift: true }), "macos", "web"),+ ).toBe(false);+ expect(+ isReservedShortcut(createShortcutChord("J", { primary: true, alt: true }), "macos", "web"),+ ).toBe(false);+ });++ it("names macOS Option chords by physical key instead of the composed glyph", () => {+ expect(+ shortcutFromEvent(+ keyEvent("©", { code: "KeyG", metaKey: true, altKey: true }),+ "macos",+ ),+ ).toEqual(createShortcutChord("G", { primary: true, alt: true }));+ // Option+E/I/N/U/` are dead keys on the US layout, with or without Command.+ expect(+ shortcutFromEvent(keyEvent("Dead", { code: "KeyE", altKey: true }), "macos"),+ ).toEqual(createShortcutChord("E", { alt: true }));+ expect(+ shortcutFromEvent(keyEvent("¡", { code: "Digit1", metaKey: true, altKey: true }), "macos"),+ ).toEqual(createShortcutChord("1", { primary: true, alt: true }));+ expect(+ shortcutFromEvent(keyEvent("\u00a0", { code: "Space", ctrlKey: true, altKey: true }), "macos"),+ ).toEqual(createShortcutChord("Space", { control: true, alt: true }));+ // Named keys and ASCII output keep their logical key.+ expect(+ shortcutFromEvent(keyEvent("ArrowUp", { code: "ArrowUp", altKey: true }), "macos"),+ ).toEqual(createShortcutChord("Up", { alt: true }));+ // Option chords now reach the reserved policy with their real key.+ expect(+ isReservedShortcut(+ shortcutFromEvent(keyEvent("ˆ", { code: "KeyI", metaKey: true, altKey: true }), "macos")!,+ "macos",+ "desktop",+ ),+ ).toBe(true);+ });++ it("keeps matching Option chords saved under their composed glyph", () => {+ const event = keyEvent("©", { code: "KeyG", metaKey: true, altKey: true });+ expect(+ shortcutMatchesEvent(createShortcutChord("©", { primary: true, alt: true }), event, "macos"),+ ).toBe(true);+ expect(+ shortcutMatchesEvent(createShortcutChord("G", { primary: true, alt: true }), event, "macos"),+ ).toBe(true);+ expect(+ shortcutMatchesEvent(createShortcutChord("G", { primary: true }), event, "macos"),+ ).toBe(false);+ });++ it("treats AltGraph as Option on macOS but as character input elsewhere", () => {+ const altGraph = (fields: Parameters<typeof keyEvent>[1]) => ({+ ...keyEvent("©", { code: "KeyG", altKey: true, ...fields }),+ getModifierState: (modifier: string) => modifier === "AltGraph",+ }) as KeyboardEvent;+ expect(shortcutFromEvent(altGraph({ metaKey: true }), "macos")).toEqual(+ createShortcutChord("G", { primary: true, alt: true }),+ );+ expect(shortcutFromEvent(altGraph({ ctrlKey: true }), "windows")).toBeNull();+ });+it("allows recording bare Cmd/Ctrl+P for an action on desktop only", () => {const cmdP = createShortcutChord("P", { primary: true });expect(isShortcutAllowedForAction("openSearch", cmdP, "macos", "desktop")).toBe(true);diff --git a/packages/core/shortcuts/definitions.ts b/packages/core/shortcuts/definitions.tsindex a54ec9cd1c..2f042d1f8d 100644--- a/packages/core/shortcuts/definitions.ts+++ b/packages/core/shortcuts/definitions.ts@@ -90,7 +90,7 @@ export const SHORTCUT_ACTIONS: readonly ShortcutActionDefinition[] = [},// Mod+J follows the "toggle a docked panel" convention, and is one of the few// letters this module's own policy leaves free on every platform and runtime:- // it is neither app-owned (PRIMARY_RESERVED_KEYS) nor browser-owned+ // it is neither app-owned (PRIMARY_RESERVED_VARIANTS) nor browser-owned// (BROWSER_ONLY_PRIMARY_RESERVED_KEYS). `allowInEditable` because the point of// the binding is reaching — and dismissing — chat without a mouse, which has// to keep working while the caret sits in the chat composer itself.@@ -122,7 +122,7 @@ export const SHORTCUT_ACTIONS: readonly ShortcutActionDefinition[] = [allowInEditable: true,},// Browser-style history navigation (Mod+[ / Mod+]). Neither bracket is- // app-owned (PRIMARY_RESERVED_KEYS) nor browser-owned+ // app-owned (PRIMARY_RESERVED_VARIANTS) nor browser-owned// (BROWSER_ONLY_PRIMARY_RESERVED_KEYS), so both are recordable on every// platform and runtime. `allowInEditable` is false so the chord never steps// away from the page while the caret sits in an input, textarea, or editor.@@ -166,10 +166,51 @@ const KEY_LABELS: Record<string, string> = {"_": "Underscore",};-function eventKey(event: KeyboardEvent): string | null {+const CODE_KEYS: Record<string, string> = {+ Space: "Space",+ Minus: "Minus",+ Equal: "Equals",+ BracketLeft: "[",+ BracketRight: "]",+ Backslash: "\\",+ Semicolon: ";",+ Quote: "'",+ Comma: ",",+ Period: ".",+ Slash: "/",+ Backquote: "`",+};++function keyFromCode(code: unknown): string | null {+ if (typeof code !== "string") return null;+ const match = /^(?:Key([A-Z])|Digit([0-9]))$/.exec(code);+ if (match) return match[1] ?? match[2] ?? null;+ return CODE_KEYS[code] ?? null;+}++// Option is a glyph modifier on macOS: ⌥G arrives as "©" and ⌥E as a dead+// key, even with Command held. Those chords are named by physical key instead.+function isComposedOptionKey(key: string): boolean {+ return key === "Dead" || (key.length === 1 && key.charCodeAt(0) > 0x7e);+}++function eventKey(+ event: KeyboardEvent,+ platform: ShortcutPlatform,+ physicalOption: boolean,+): string | null {// Synthetic events (e.g. Chrome autofill) may omit `key` entirely.if (typeof event.key !== "string") return null;- if (MODIFIER_KEYS.has(event.key) || NON_ACTIONABLE_KEYS.has(event.key)) return null;+ if (MODIFIER_KEYS.has(event.key)) return null;+ if (+ physicalOption &&+ platform === "macos" &&+ event.altKey &&+ isComposedOptionKey(event.key)+ ) {+ return keyFromCode(event.code);+ }+ if (NON_ACTIONABLE_KEYS.has(event.key)) return null;const key = KEY_LABELS[event.key] ?? event.key;if (key.length === 1 && /[a-z]/i.test(key)) return key.toUpperCase();return key;@@ -181,15 +222,22 @@ export function isShortcutChordActionable(shortcut: ShortcutChord): boolean {!NON_ACTIONABLE_KEYS.has(shortcut.key);}-/** Convert a key event into a platform-aware, structured chord. */-export function shortcutFromEvent(+/** Whether `key` is a modifier pressed on its own, on the way to a chord. */+export function isShortcutModifierKey(key: unknown): boolean {+ return typeof key === "string" && MODIFIER_KEYS.has(key);+}++function chordFromEvent(event: KeyboardEvent,- platform: ShortcutPlatform = getShortcutPlatform(),+ platform: ShortcutPlatform,+ physicalOption: boolean,): ShortcutChord | null {- if (event.getModifierState?.("AltGraph")) return null;- const key = eventKey(event);- if (!key) return null;const mac = platform === "macos";+ // Firefox on macOS reports Option as AltGraph; elsewhere AltGraph means the+ // key is typing a character, not forming a chord.+ if (!mac && event.getModifierState?.("AltGraph")) return null;+ const key = eventKey(event, platform, physicalOption);+ if (!key) return null;return createShortcutChord(key, {primary: mac ? event.metaKey : event.ctrlKey,control: mac ? event.ctrlKey : false,@@ -199,6 +247,14 @@ export function shortcutFromEvent(});}+/** Convert a key event into a platform-aware, structured chord. */+export function shortcutFromEvent(+ event: KeyboardEvent,+ platform: ShortcutPlatform = getShortcutPlatform(),+): ShortcutChord | null {+ return chordFromEvent(event, platform, true);+}+export function shortcutChordEquals(left: ShortcutChord | null,right: ShortcutChord | null,@@ -227,7 +283,13 @@ export function shortcutMatchesEvent(// when comparing persisted values.if (!shortcut) return false;const eventShortcut = shortcutFromEvent(event, platform);- return eventShortcut !== null && shortcutChordEquals(shortcut, eventShortcut);+ if (eventShortcut !== null && shortcutChordEquals(shortcut, eventShortcut)) {+ return true;+ }+ // Option chords recorded before they were named by physical key persisted+ // the composed symbol (⌘⌥G as "©") and must keep firing.+ const composedShortcut = chordFromEvent(event, platform, false);+ return composedShortcut !== null && shortcutChordEquals(shortcut, composedShortcut);}export function isPlainShortcut(@@ -307,24 +369,76 @@ export function isPortalLayerShortcutTarget(target: EventTarget | null): booleanreturn target instanceof Element && target.closest(PORTAL_LAYER_SELECTOR) !== null;}-const PRIMARY_RESERVED_KEYS = new Set([- // Window operations the app itself owns on every runtime: W closes the- // tab, R/F5 is the reload guard, Q quits.- "W", "R", "Q",+/**+ * Which modifier combinations on top of Command/Ctrl are taken for a key:+ * "any", or the exact extra modifiers ("" bare, "shift", "alt+shift", ...)+ * in the order produced by `extraModifiers`. Everything not listed stays+ * free, so ⌘⇧X is recordable even though ⌘X is Cut.+ */+type ReservedVariants = "any" | readonly string[];++const PRIMARY_RESERVED_VARIANTS: Record<string, ReservedVariants> = {+ // Window operations the app itself owns on every runtime: W closes the tab+ // (Shift+W the window), R/F5 is the reload guard, Q quits (Shift+Q logs out+ // on macOS).+ W: "any", R: "any", Q: "any",// Preferences: the desktop app opens Settings from the main process, and on// web the browser opens its own settings — neither leaves the chord free for// a product action.- ",",- // Fundamental editing operations should never become product actions.- "A", "C", "V", "X", "Y", "Z",+ ",": "any",// Zoom accelerators: fixed app shortcuts on desktop, browser zoom on web.- "Equals", "Plus", "Minus", "Underscore", "0",+ Equals: "any", Plus: "any", Minus: "any", Underscore: "any", "0": "any",// Browser-style direct tab selection: browsers own these on web and the- // desktop main process owns them for product tabs. Keeping them reserved- // also sanitizes any conflicting shortcut override persisted by an older- // app version.- "1", "2", "3", "4", "5", "6", "7", "8", "9",-]);+ // desktop main process owns them for product tabs (Shift+Cmd+3/4/5 are also+ // macOS screenshots). Keeping them reserved also sanitizes any conflicting+ // shortcut override persisted by an older app version.+ "1": "any", "2": "any", "3": "any", "4": "any", "5": "any",+ "6": "any", "7": "any", "8": "any", "9": "any",+ // Editing operations, plus the editing variants the OS and Electron's+ // default menu assign: Shift+V / Alt+Shift+V paste as plain text, Shift+Z+ // redoes. Browser DevTools chords are not listed — a page can claim them.+ A: [""],+ C: [""],+ V: ["", "shift", "alt+shift"],+ X: [""],+ Y: [""],+ Z: ["", "shift"],+};++const MACOS_PRIMARY_RESERVED_VARIANTS: Record<string, ReservedVariants> = {+ // Spotlight, input-source switching, emoji picker, app switcher.+ Space: "any", Tab: "any",+ // Hide / Hide Others and Minimize / Minimize All.+ H: ["", "alt"], M: ["", "alt"],+ // Control+Command+F toggles full screen.+ F: ["control"],+};++// Toggle Developer Tools in Electron's default menu, whose accelerators fire+// even when the page handles the keydown. Browsers let a page claim the same+// chord, so these stay recordable on web.+const MACOS_DESKTOP_PRIMARY_RESERVED_VARIANTS: Record<string, ReservedVariants> = {+ I: ["alt"],+};++const OTHER_DESKTOP_PRIMARY_RESERVED_VARIANTS: Record<string, ReservedVariants> = {+ I: ["shift"],+};++function extraModifiers({ control, meta, alt, shift }: ShortcutModifiers): string {+ return [control && "control", meta && "meta", alt && "alt", shift && "shift"]+ .filter(Boolean)+ .join("+");+}++function isReservedIn(+ table: Record<string, ReservedVariants>,+ shortcut: ShortcutChord,+): boolean {+ if (!Object.prototype.hasOwnProperty.call(table, shortcut.key)) return false;+ const variants = table[shortcut.key];+ return variants === "any" || variants!.includes(extraModifiers(shortcut.modifiers));+}// Accelerators owned by the browser UI around a tab: print, address bar,// new tab/window, bookmark, view source. A web page cannot reliably own@@ -347,15 +461,22 @@ export function isReservedShortcut(): boolean {const { modifiers, key } = shortcut;if (key === "F5") return true;- if (modifiers.primary && PRIMARY_RESERVED_KEYS.has(key)) return true;- if (modifiers.primary && BROWSER_ONLY_PRIMARY_RESERVED_KEYS.has(key)) {- const barePrimary =- !modifiers.control && !modifiers.meta && !modifiers.alt && !modifiers.shift;- if (runtime !== "desktop" || !barePrimary) return true;+ if (modifiers.primary) {+ if (isReservedIn(PRIMARY_RESERVED_VARIANTS, shortcut)) return true;+ if (BROWSER_ONLY_PRIMARY_RESERVED_KEYS.has(key)) {+ if (runtime !== "desktop" || extraModifiers(modifiers) !== "") return true;+ }+ const mac = platform === "macos";+ if (mac && isReservedIn(MACOS_PRIMARY_RESERVED_VARIANTS, shortcut)) return true;+ if (runtime === "desktop") {+ const desktopVariants = mac+ ? MACOS_DESKTOP_PRIMARY_RESERVED_VARIANTS+ : OTHER_DESKTOP_PRIMARY_RESERVED_VARIANTS;+ if (isReservedIn(desktopVariants, shortcut)) return true;+ }}if (platform === "macos") {- if (modifiers.primary && (key === "Space" || key === "Tab" || key === "M" || key === "H")) return true;if (modifiers.control && ["Up", "Down", "Left", "Right"].includes(key)) return true;} else {// Windows/Super shortcuts are owned by the shell/window manager and oftendiff --git a/packages/core/shortcuts/index.ts b/packages/core/shortcuts/index.tsindex 07e9f0f1f6..ae3d757784 100644--- a/packages/core/shortcuts/index.ts+++ b/packages/core/shortcuts/index.ts@@ -11,6 +11,7 @@ export {isPortalLayerShortcutTarget,isReservedShortcut,isShortcutAllowedForAction,+ isShortcutModifierKey,type ShortcutActionDefinition,type ShortcutActionId,type ShortcutCategory,diff --git a/packages/core/shortcuts/store.test.ts b/packages/core/shortcuts/store.test.tsindex f72b8a16b0..223d9e75d0 100644--- a/packages/core/shortcuts/store.test.ts+++ b/packages/core/shortcuts/store.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, it } from "vitest";import { createShortcutChord } from "./definitions";-import { configureShortcutRuntime } from "./platform";+import { configureShortcutPlatform, configureShortcutRuntime } from "./platform";import {findShortcutConflict,getShortcut,@@ -11,6 +11,7 @@ import {afterEach(() => {useShortcutStore.getState().resetAll();+ configureShortcutPlatform(null);configureShortcutRuntime(null);});@@ -107,6 +108,36 @@ describe("shortcut store", () => {expect(findShortcutConflict("goChat", custom)).toBe("goInbox");});+ it("treats an Option chord saved under its glyph as taken by the same keypress", () => {+ configureShortcutPlatform("macos");+ useShortcutStore.getState().setShortcut(+ "goInbox",+ createShortcutChord("©", { primary: true, alt: true }),+ );+ const event = {+ key: "©",+ code: "KeyG",+ metaKey: true,+ altKey: true,+ ctrlKey: false,+ shiftKey: false,+ } as KeyboardEvent;+ const physical = createShortcutChord("G", { primary: true, alt: true });+ expect(findShortcutConflict("goChat", physical)).toBeNull();+ expect(findShortcutConflict("goChat", physical, event)).toBe("goInbox");+ });++ it("keeps a persisted Ctrl+Shift+I override on web but not on desktop", () => {+ const devTools = createShortcutChord("I", { primary: true, shift: true });+ configureShortcutPlatform("windows");+ configureShortcutRuntime("web");+ expect(sanitizeShortcutOverrides({ openSearch: devTools })).toEqual({+ openSearch: devTools,+ });+ configureShortcutRuntime("desktop");+ expect(sanitizeShortcutOverrides({ openSearch: devTools })).toEqual({});+ });+it("migrates v1 string overrides without losing disabled actions", () => {expect(migrateShortcutState({diff --git a/packages/core/shortcuts/store.ts b/packages/core/shortcuts/store.tsindex 1cbf64f979..d226362d41 100644--- a/packages/core/shortcuts/store.ts+++ b/packages/core/shortcuts/store.ts@@ -9,6 +9,7 @@ import {isShortcutAllowedForAction,parseLegacyShortcut,shortcutChordEquals,+ shortcutMatchesEvent,type ShortcutActionId,type ShortcutChord,} from "./definitions";@@ -166,14 +167,21 @@ export function getShortcut(actionId: ShortcutActionId): ShortcutChord | null {return resolveShortcut(useShortcutStore.getState().overrides, actionId);}+/**+ * Pass the recorded `event` so bindings stored in an older form that the same+ * keypress would also trigger (an Option chord saved as "©") count as taken.+ */export function findShortcutConflict(actionId: ShortcutActionId,shortcut: ShortcutChord,+ event?: KeyboardEvent,): ShortcutActionId | null {for (const action of SHORTCUT_ACTIONS) {+ if (action.id === actionId) continue;+ const existing = getShortcut(action.id);if (- action.id !== actionId &&- shortcutChordEquals(getShortcut(action.id), shortcut)+ shortcutChordEquals(existing, shortcut) ||+ (event !== undefined && shortcutMatchesEvent(existing, event))) {return action.id;}diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.jsonindex 11f6cb1fd0..18de3a4529 100644--- a/packages/views/locales/en/settings.json+++ b/packages/views/locales/en/settings.json@@ -393,6 +393,7 @@"reserved_error": "Reserved by the browser or desktop window.","send_error": "Send can only use Enter or Mod+Enter.","unsafe_error": "This key would interfere with typing or basic keyboard navigation.",+ "unrecognized_error": "This key combination can't be recorded. Try another one.","send_enter_hint": "Shift+Enter inserts a paragraph, continues a list, or adds a code-block newline.","categories": {"general": "General",diff --git a/packages/views/locales/es/settings.json b/packages/views/locales/es/settings.jsonindex c97dbed0c5..52b496a7b9 100644--- a/packages/views/locales/es/settings.json+++ b/packages/views/locales/es/settings.json@@ -393,6 +393,7 @@"reserved_error": "Reservado por el navegador o la ventana de escritorio.","send_error": "Enviar solo puede usar Enter o Mod+Enter.","unsafe_error": "Esta tecla interferiría con la escritura o la navegación básica del teclado.",+ "unrecognized_error": "No se puede grabar esta combinación. Prueba con otra.","send_enter_hint": "Shift+Enter inserta un párrafo, continúa una lista o añade un salto de línea en un bloque de código.","categories": {"general": "General",diff --git a/packages/views/locales/fr/settings.json b/packages/views/locales/fr/settings.jsonindex d995f3fac8..8367cd13ce 100644--- a/packages/views/locales/fr/settings.json+++ b/packages/views/locales/fr/settings.json@@ -393,6 +393,7 @@"reserved_error": "Réservé par le navigateur ou la fenêtre de bureau.","send_error": "Envoyer ne peut utiliser que Entrée ou Mod+Entrée.","unsafe_error": "Cette touche gênerait la saisie ou la navigation clavier de base.",+ "unrecognized_error": "Impossible d'enregistrer cette combinaison. Essayez-en une autre.","send_enter_hint": "Maj+Entrée insère un paragraphe, poursuit une liste, ou ajoute un saut de ligne dans un bloc de code.","categories": {"general": "Général",diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.jsonindex 0dcbd594d4..55e490a71b 100644--- a/packages/views/locales/ja/settings.json+++ b/packages/views/locales/ja/settings.json@@ -387,6 +387,7 @@"reserved_error": "ブラウザまたはデスクトップウィンドウで予約されています。","send_error": "送信には Enter または Mod+Enter のみ使用できます。","unsafe_error": "このキーは文字入力や基本的なキーボード操作と競合します。",+ "unrecognized_error": "このキーの組み合わせは記録できません。別の組み合わせをお試しください。","send_enter_hint": "Shift+Enterで段落の挿入、リストの継続、コードブロック内の改行ができます。","categories": {"general": "一般",diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.jsonindex e07b5d6460..6caa1038c4 100644--- a/packages/views/locales/ko/settings.json+++ b/packages/views/locales/ko/settings.json@@ -387,6 +387,7 @@"reserved_error": "브라우저 또는 데스크톱 창에서 예약된 단축키입니다.","send_error": "보내기는 Enter 또는 Mod+Enter만 사용할 수 있습니다.","unsafe_error": "이 키는 텍스트 입력이나 기본 키보드 탐색을 방해합니다.",+ "unrecognized_error": "이 키 조합은 기록할 수 없습니다. 다른 조합을 사용해 보세요.","send_enter_hint": "Shift+Enter로 단락을 삽입하거나 목록을 이어가고 코드 블록에서 줄을 바꿀 수 있습니다.","categories": {"general": "일반",diff --git a/packages/views/locales/ru/settings.json b/packages/views/locales/ru/settings.jsonindex 4adffcafc0..89b6103910 100644--- a/packages/views/locales/ru/settings.json+++ b/packages/views/locales/ru/settings.json@@ -404,6 +404,7 @@"reserved_error": "Зарезервировано браузером или окном приложения.","send_error": "Для отправки можно использовать только Enter или Mod+Enter.","unsafe_error": "Эта клавиша будет мешать вводу текста или базовой навигации с клавиатуры.",+ "unrecognized_error": "Это сочетание клавиш нельзя записать. Попробуйте другое.","send_enter_hint": "Shift+Enter вставляет абзац, продолжает список или добавляет перенос строки в блоке кода.","categories": {"general": "Общие",diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.jsonindex ddc78bcdac..dcc48bc3ed 100644--- a/packages/views/locales/zh-Hans/settings.json+++ b/packages/views/locales/zh-Hans/settings.json@@ -387,6 +387,7 @@"reserved_error": "该快捷键已被浏览器或桌面窗口占用。","send_error": "发送只能使用 Enter 或 Mod + Enter。","unsafe_error": "这个按键会干扰文字输入或基础键盘导航。",+ "unrecognized_error": "无法录制这个组合键,请换一个试试。","send_enter_hint": "Shift+Enter 可插入段落、继续列表,或在代码块中换行。","categories": {"general": "常规",diff --git a/packages/views/locales/zh-Hant/settings.json b/packages/views/locales/zh-Hant/settings.jsonindex 09155e042a..f6d36e35e8 100644--- a/packages/views/locales/zh-Hant/settings.json+++ b/packages/views/locales/zh-Hant/settings.json@@ -387,6 +387,7 @@"reserved_error": "該快捷鍵已被瀏覽器或桌面視窗占用。","send_error": "傳送只能使用 Enter 或 Mod + Enter。","unsafe_error": "這個按鍵會干擾文字輸入或基礎鍵盤導航。",+ "unrecognized_error": "無法錄製這個組合鍵,請換一個試試。","send_enter_hint": "Shift+Enter 可插入段落、繼續列表,或在程式碼塊中換行。","categories": {"general": "常規",diff --git a/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx b/packages/views/settings/components/keyboard-shortcuts-tab.test.tsxindex 5db971db57..21c4f230a6 100644--- a/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx+++ b/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx@@ -87,6 +87,70 @@ describe("KeyboardShortcutsTab", () => {expect(screen.queryByRole("alert")).not.toBeInTheDocument();});+ it("records macOS Option chords by physical key, including dead keys", () => {+ configureShortcutPlatform("macos");+ renderWithI18n(<KeyboardShortcutsTab />);+ const recorder = screen.getByRole("button", {+ name: "Change shortcut for Open search",+ });++ fireEvent.click(recorder);+ fireEvent.keyDown(recorder, {+ key: "Dead",+ code: "KeyE",+ metaKey: true,+ altKey: true,+ });++ expect(getShortcut("openSearch")).toEqual(+ createShortcutChord("E", { primary: true, alt: true }),+ );+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();+ });++ it("reports a conflict with an Option chord saved under its glyph", () => {+ configureShortcutPlatform("macos");+ const legacy = createShortcutChord("©", { primary: true, alt: true });+ useShortcutStore.getState().setShortcut("openSearch", legacy);+ renderWithI18n(<KeyboardShortcutsTab />);+ const recorder = screen.getByRole("button", {+ name: "Change shortcut for Create issue",+ });++ fireEvent.click(recorder);+ fireEvent.keyDown(recorder, {+ key: "©",+ code: "KeyG",+ metaKey: true,+ altKey: true,+ });++ expect(getShortcut("createIssue")).toEqual(createShortcutChord("C"));+ expect(getShortcut("openSearch")).toEqual(legacy);+ expect(screen.getByRole("alert")).toHaveTextContent(+ "Already used by Open search.",+ );+ });++ it("explains a key it cannot record instead of ignoring it", () => {+ renderWithI18n(<KeyboardShortcutsTab />);+ const recorder = screen.getByRole("button", {+ name: "Change shortcut for Open search",+ });++ fireEvent.click(recorder);+ fireEvent.keyDown(recorder, { key: "Control", ctrlKey: true });+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();++ fireEvent.keyDown(recorder, { key: "Unidentified", ctrlKey: true });+ expect(getShortcut("openSearch")).toEqual(+ createShortcutChord("K", { primary: true }),+ );+ expect(screen.getByRole("alert")).toHaveTextContent(+ "This key combination can't be recorded. Try another one.",+ );+ });+it("only captures keys while the recorder is active", () => {renderWithI18n(<KeyboardShortcutsTab />);const recorder = screen.getByRole("button", {diff --git a/packages/views/settings/components/keyboard-shortcuts-tab.tsx b/packages/views/settings/components/keyboard-shortcuts-tab.tsxindex 7313201918..e68e280b89 100644--- a/packages/views/settings/components/keyboard-shortcuts-tab.tsx+++ b/packages/views/settings/components/keyboard-shortcuts-tab.tsx@@ -21,6 +21,7 @@ import {createShortcutChord,isReservedShortcut,isShortcutAllowedForAction,+ isShortcutModifierKey,isPlainShortcut,resolveShortcut,shortcutFromEvent,@@ -46,6 +47,7 @@ type CaptureError =| { kind: "reserved" }| { kind: "send" }| { kind: "unsafe" }+ | { kind: "unrecognized" }| null;export function KeyboardShortcutsTab() {@@ -92,7 +94,12 @@ export function KeyboardShortcutsTab() {}const shortcut = shortcutFromEvent(event.nativeEvent);- if (!shortcut) return;+ if (!shortcut) {+ if (!isShortcutModifierKey(event.key)) {+ setCaptureError({ kind: "unrecognized" });+ }+ return;+ }if (isReservedShortcut(shortcut)) {setCaptureError({ kind: "reserved" });return;@@ -101,7 +108,7 @@ export function KeyboardShortcutsTab() {setCaptureError({ kind: actionId === "send" ? "send" : "unsafe" });return;}- const conflict = findShortcutConflict(actionId, shortcut);+ const conflict = findShortcutConflict(actionId, shortcut, event.nativeEvent);if (conflict) {setCaptureError({ kind: "conflict", actionId: conflict });return;@@ -275,6 +282,8 @@ function ShortcutRow({? t(($) => $.shortcuts.send_error): error?.kind === "unsafe"? t(($) => $.shortcuts.unsafe_error)+ : error?.kind === "unrecognized"+ ? t(($) => $.shortcuts.unrecognized_error): error?.kind === "conflict"? t(($) => $.shortcuts.conflict_error, {action: t(($) => $.shortcuts.actions[error.actionId].label),