fix(desktop): preserve Windows editing shortcuts (#46336)

This commit is contained in:
Luke Parker 2026-08-31 14:07:42 +10:00 committed by GitHub
parent a1925de0c1
commit 8890294bf0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View file

@ -298,7 +298,7 @@ export function Titlebar(props: {
id: "home.toggle",
title: language.t("home.title"),
category: language.t("command.category.view"),
keybind: "mod+b",
keybind: windows() ? "alt+home" : "mod+b",
hidden: true,
onSelect: toggleHome,
},

View file

@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test"
import { DESKTOP_MENU } from "@/shell/commands/desktop-menu"
import { windowsMenuAccelerator } from "./windows-menu"
describe("Windows app menu", () => {
@ -11,4 +12,16 @@ describe("Windows app menu", () => {
test("ignores the accelerator without its modifiers", () => {
expect(windowsMenuAccelerator(new KeyboardEvent("keydown", { key: "N" }))).toBeUndefined()
})
test.each(["v", "c", "x", "a", "z", "y"])("leaves Ctrl+%s to the focused editor", (key) => {
expect(windowsMenuAccelerator(new KeyboardEvent("keydown", { key, ctrlKey: true }))).toBeUndefined()
})
test("preserves the paste menu action and shortcut label", () => {
expect(
DESKTOP_MENU.flatMap((menu) => menu.items ?? []).find(
(entry) => entry.type === "item" && entry.action === "edit.paste",
),
).toMatchObject({ action: "edit.paste", accelerator: { windows: "Ctrl+V" } })
})
})

View file

@ -16,6 +16,8 @@ import { useLanguage } from "@/runtime/i18n/language"
const accelerators = DESKTOP_MENU.flatMap((menu) => menu.items ?? []).flatMap((entry) => {
if (entry.type === "separator" || !entry.action || !entry.accelerator?.windows) return []
// Let the focused editor handle editing shortcuts without restoring stale menu focus.
if (entry.action.startsWith("edit.")) return []
return [{ action: entry.action, keybind: parseKeybind(entry.accelerator.windows) }]
})