fix(desktop): claim Cmd/Ctrl+R in before-input-event so it works off macOS
The application menu is only installed on macOS (#77845) — everywhere else it is set to null, which strips the role accelerators with it. A menu-only Cmd+R meant Windows and Linux got no page reload at all. Moves the claim into the same before-input-event hook Cmd+W already uses for exactly this reason, and drops the accelerator from the menu item so one keypress can't fire both paths on macOS.
This commit is contained in:
committed by
brooklyn!
parent
fae8e27a49
commit
4d1cdf83c9
@@ -6138,11 +6138,11 @@ function buildApplicationMenu() {
|
||||
// whole shell) and a focused in-app browser needs ⌘R to mean "reload
|
||||
// this page", the way it does in every other browser. ⇧⌘R
|
||||
// (`forceReload`) below stays the unconditional escape hatch.
|
||||
{
|
||||
accelerator: 'CommandOrControl+R',
|
||||
label: 'Reload',
|
||||
click: () => sendPreviewNavCommand('reload')
|
||||
},
|
||||
//
|
||||
// No accelerator: ⌘R is claimed in `installPreviewShortcut`, which works
|
||||
// on every platform (this menu exists only on macOS). Declaring it here
|
||||
// too would fire the item and the input hook for one keypress.
|
||||
{ click: () => sendPreviewNavCommand('reload'), label: 'Reload' },
|
||||
{ role: 'forceReload' },
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
@@ -6241,17 +6241,28 @@ function installDevToolsShortcut(window) {
|
||||
function installPreviewShortcut(window) {
|
||||
window.webContents.on('before-input-event', (event, input) => {
|
||||
const key = String(input.key || '').toLowerCase()
|
||||
const isCloseTabShortcut = key === 'w' && (IS_MAC ? input.meta : input.control) && !input.alt && !input.shift
|
||||
const accel = (IS_MAC ? input.meta : input.control) && !input.alt
|
||||
const isCloseTabShortcut = key === 'w' && accel && !input.shift
|
||||
|
||||
// Always claim ⌘W here (the File>Close item deliberately has no
|
||||
// accelerator, so nothing else does). The renderer decides tab-vs-window
|
||||
// — no `previewShortcutActive` gate, so it works for every closeable tab.
|
||||
if (!isCloseTabShortcut) {
|
||||
if (isCloseTabShortcut) {
|
||||
event.preventDefault()
|
||||
sendClosePreviewRequested()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
sendClosePreviewRequested()
|
||||
// ⌘R rides here rather than on the View menu item for the same reason:
|
||||
// the application menu only exists on macOS (it is set to null elsewhere,
|
||||
// see #77845), so a menu accelerator would leave Windows and Linux with no
|
||||
// way to reload a page at all. ⇧⌘R is left alone — that is `forceReload`,
|
||||
// the unconditional whole-window escape hatch.
|
||||
if (key === 'r' && accel && !input.shift) {
|
||||
event.preventDefault()
|
||||
sendPreviewNavCommand('reload')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user