From a55c17f3979e99feed8a35fbdb6e0965ed7e2950 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 3 Oct 2026 20:54:05 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20Cmd+,=20opens=20Settings,=20Ctrl+,=20on?= =?UTF-8?q?=20Windows=20and=20Linux=20(#670:=20App=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=B2=A1=E6=9C=89=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E5=90=97=EF=BC=9Fmac=E4=B8=80=E8=88=AC=E6=98=AFcommand+?= =?UTF-8?q?=E9=80=97=E5=8F=B7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit magpie had no shortcut for Settings: only the gear in the header opened it. Now Cmd+, on the Mac and Ctrl+, elsewhere opens the Settings page from any page of the window, from a text box too, as a Mac app's does; in the tray panel it opens the window on Settings, as the gear does there. Another modifier with the comma (Ctrl on the Mac, Alt, Shift) doesn't, and a browser tab (magpie web) leaves the keys to the browser. The gear's tooltip says the shortcut, "Settings (⌘,)" or "Settings (Ctrl+,)" (data-keys, kept through a language change). magpie has no app menu of its own (Wails' default Mac menu has no Settings item), so the shortcut is the page's, beside the text size's Cmd/Ctrl + − 0. settings-shortcut.test.cjs (window, a focused text box, the panel asking for window/main?view=settings, other modifiers, the browser tab, the tooltip; en and zh) fails on the old code. go vet ./internal/..., go build -tags nogui ./... and GOOS=windows go build ./... pass; the GUI tests under WebKit pass but those that fail on main as well (33 there: cli-update, group-from-model-add, menu-scroll, old-webkit, provider-levels-scroll, redact-rule-row, routing-compact/manual/time, seg-contrast, session-identity, signin-callback, zcode-site). Chromium doesn't launch on this machine (icudtl.dat missing), so it was tried in WebKit only, not in the app's own webview. --- internal/gui/assets/app.js | 19 +++- internal/gui/assets/i18n.js | 4 + internal/gui/assets/index.html | 2 +- internal/gui/tests/settings-shortcut.test.cjs | 103 ++++++++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 internal/gui/tests/settings-shortcut.test.cjs diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 6e81be83..99b89658 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -12691,6 +12691,15 @@ if (!web) addEventListener("keydown", (e) => { setTextSize(n); status(t("Text size {n}%", { n })); }, true); +// Cmd+, (Ctrl+, off the Mac) opens Settings, as it does in a Mac app +// (#670), from the window or the panel alike and from a text box too; in a +// browser tab it is the browser's. +if (!web) addEventListener("keydown", (e) => { + const mod = /^Mac/.test(navigator.platform) ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey; + if (!mod || e.altKey || e.shiftKey || e.repeat || (e.key !== "," && e.code !== "Comma")) return; + e.preventDefault(); + openSettings(); +}, true); // applyPrefs paints and speaks as the saved settings say, costs at the // exchange rate given (rate, /api/state's fx) or the settings' own. A @@ -14447,7 +14456,15 @@ function syncURL() { if (s !== location.search) history.replaceState(null, "", s); } if (mode === "window") for (const b of $("#nav").querySelectorAll("button")) b.onclick = () => { show(b.dataset.view); b.blur(); }; -$("#prefs").onclick = () => { if (mode === "window") show("settings"); else api("window/main?view=settings", {}); $("#prefs").blur(); }; +// openSettings: the Settings page, in the window (the panel opens it there) +function openSettings() { + if (mode !== "window") { api("window/main?view=settings", {}); return; } + // a pick list or a menu open over the page is put away with it + closeProtoMenu(); + closeAgentMenu(); + show("settings"); +} +$("#prefs").onclick = () => { openSettings(); $("#prefs").blur(); }; $("#sync").onclick = async () => { const b = $("#sync"); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index b16078e6..eda776bf 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2662,6 +2662,10 @@ function translateStatic() { for (const e of document.querySelectorAll("[data-tt]")) { if (e.dataset.enTitle === undefined) e.dataset.enTitle = e.dataset.tt || e.title; e.title = t(e.dataset.enTitle); + // data-keys: its shortcut, the Mac's before the | and the others' after + // (Settings' ⌘, #670); a browser tab keeps its own + const keys = e.dataset.keys?.split("|")[/^Mac/.test(navigator.platform) ? 0 : 1]; + if (keys && !window.bootPrefs?.web) e.title += " (" + keys + ")"; } for (const e of document.querySelectorAll("[data-tp]")) { if (e.dataset.enPlaceholder === undefined) e.dataset.enPlaceholder = e.placeholder; diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index f6f86dd0..8f68ac4b 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -47,7 +47,7 @@ -