Fix browser history shortcuts for Logitech side-button remaps (#5569)
This commit is contained in:
@@ -497,6 +497,31 @@ describe('setupGuestShortcutForwarding', () => {
|
||||
expect(rendererSendMock).toHaveBeenNthCalledWith(6, 'ui:zoomBrowserPage', 'in')
|
||||
})
|
||||
|
||||
it('forwards browser history shortcuts from focused guest pages', () => {
|
||||
setupGuestShortcutForwarding({
|
||||
browserTabId,
|
||||
guest: makeGuest(),
|
||||
resolveRenderer: () => makeRenderer()
|
||||
})
|
||||
|
||||
const backInput =
|
||||
process.platform === 'darwin'
|
||||
? { code: 'BracketLeft', key: '[', meta: true, control: false, alt: false }
|
||||
: { code: 'ArrowLeft', key: 'ArrowLeft', meta: false, control: false, alt: true }
|
||||
const forwardInput =
|
||||
process.platform === 'darwin'
|
||||
? { code: 'BracketRight', key: ']', meta: true, control: false, alt: false }
|
||||
: { code: 'ArrowRight', key: 'ArrowRight', meta: false, control: false, alt: true }
|
||||
|
||||
const backPreventDefault = triggerBeforeInput(backInput)
|
||||
const forwardPreventDefault = triggerBeforeInput(forwardInput)
|
||||
|
||||
expect(backPreventDefault).toHaveBeenCalledTimes(1)
|
||||
expect(forwardPreventDefault).toHaveBeenCalledTimes(1)
|
||||
expect(rendererSendMock).toHaveBeenNthCalledWith(1, 'ui:browserHistoryNavigate', 'back')
|
||||
expect(rendererSendMock).toHaveBeenNthCalledWith(2, 'ui:browserHistoryNavigate', 'forward')
|
||||
})
|
||||
|
||||
it('consumes guest zoom shortcuts even when the renderer is unavailable', () => {
|
||||
setupGuestShortcutForwarding({
|
||||
browserTabId,
|
||||
|
||||
@@ -419,6 +419,15 @@ export function setupGuestShortcutForwarding(args: {
|
||||
// guest handle it natively would open Chromium's built-in find UI inside
|
||||
// the guest frame, which is invisible behind Orca's chrome.
|
||||
renderer.send('ui:findInBrowserPage')
|
||||
} else if (keybindingMatchesAction('browser.back', input, process.platform, keybindings)) {
|
||||
// Why: macOS Logitech side-button remaps arrive as browser history
|
||||
// keystrokes, not mouse/app-command events. Forward out of the guest so
|
||||
// the renderer-owned webview ref can call goBack().
|
||||
renderer.send('ui:browserHistoryNavigate', 'back')
|
||||
} else if (keybindingMatchesAction('browser.forward', input, process.platform, keybindings)) {
|
||||
// Why: same as browser.back; the focused guest cannot call the
|
||||
// renderer-owned parked webview's goForward() path directly.
|
||||
renderer.send('ui:browserHistoryNavigate', 'forward')
|
||||
} else if (keybindingMatchesAction('tab.close', input, process.platform, keybindings)) {
|
||||
renderer.send('ui:closeActiveTab')
|
||||
} else if (keybindingMatchesAction('tab.nextSameType', input, process.platform, keybindings)) {
|
||||
|
||||
@@ -2327,6 +2327,7 @@ export type PreloadApi = {
|
||||
onFocusBrowserAddressBar: (callback: () => void) => () => void
|
||||
onFindInBrowserPage: (callback: () => void) => () => void
|
||||
onReloadBrowserPage: (callback: () => void) => () => void
|
||||
onBrowserHistoryNavigate: (callback: (direction: 'back' | 'forward') => void) => () => void
|
||||
onZoomBrowserPage: (callback: (direction: 'in' | 'out' | 'reset') => void) => () => void
|
||||
onHardReloadBrowserPage: (callback: () => void) => () => void
|
||||
onCloseActiveTab: (callback: () => void) => () => void
|
||||
|
||||
@@ -2855,6 +2855,12 @@ const api = {
|
||||
ipcRenderer.on('ui:reloadBrowserPage', listener)
|
||||
return () => ipcRenderer.removeListener('ui:reloadBrowserPage', listener)
|
||||
},
|
||||
onBrowserHistoryNavigate: (callback: (direction: 'back' | 'forward') => void): (() => void) => {
|
||||
const listener = (_event: Electron.IpcRendererEvent, direction: 'back' | 'forward'): void =>
|
||||
callback(direction)
|
||||
ipcRenderer.on('ui:browserHistoryNavigate', listener)
|
||||
return () => ipcRenderer.removeListener('ui:browserHistoryNavigate', listener)
|
||||
},
|
||||
onZoomBrowserPage: (callback: (direction: 'in' | 'out' | 'reset') => void): (() => void) => {
|
||||
const listener = (_event: Electron.IpcRendererEvent, direction: 'in' | 'out' | 'reset') =>
|
||||
callback(direction)
|
||||
|
||||
@@ -914,6 +914,7 @@ function RemoteBrowserPagePane({
|
||||
const createBrowserTab = useAppStore((s) => s.createBrowserTab)
|
||||
const closeBrowserPage = useAppStore((s) => s.closeBrowserPage)
|
||||
const closeBrowserTab = useAppStore((s) => s.closeBrowserTab)
|
||||
const keybindings = useAppStore((state) => state.keybindings)
|
||||
|
||||
currentBrowserTabIdRef.current = browserTab.id
|
||||
currentBrowserTabUrlRef.current = browserTab.url
|
||||
@@ -1931,6 +1932,31 @@ function RemoteBrowserPagePane({
|
||||
[runRemoteNavigation]
|
||||
)
|
||||
|
||||
// Browser history shortcuts for SSH/runtime browsers.
|
||||
// Why: remote browser panes have no local webview ref, so history shortcuts
|
||||
// must route through the runtime RPC methods rather than desktop WebContents.
|
||||
useEffect(() => {
|
||||
if (!isActive) {
|
||||
return
|
||||
}
|
||||
const shortcutPlatform = getShortcutPlatform()
|
||||
const handleKeyDown = (e: KeyboardEvent): void => {
|
||||
const method = keybindingMatchesAction('browser.back', e, shortcutPlatform, keybindings)
|
||||
? 'browser.back'
|
||||
: keybindingMatchesAction('browser.forward', e, shortcutPlatform, keybindings)
|
||||
? 'browser.forward'
|
||||
: null
|
||||
if (method === null) {
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
void runRemoteNavigation(method)
|
||||
}
|
||||
window.addEventListener('keydown', handleKeyDown, true)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown, true)
|
||||
}, [isActive, keybindings, runRemoteNavigation])
|
||||
|
||||
const submitAddressBar = (): void => {
|
||||
const searchEngine = useAppStore.getState().browserDefaultSearchEngine
|
||||
const kagiSessionLink = useAppStore.getState().browserKagiSessionLink
|
||||
@@ -2593,6 +2619,17 @@ function BrowserPagePane({
|
||||
browserTabIdRef.current = browserTab.id
|
||||
const inputLockedRef = useRef(inputLocked)
|
||||
inputLockedRef.current = inputLocked
|
||||
const navigateBrowserHistoryRef = useRef<(direction: 'back' | 'forward') => void>(() => {})
|
||||
navigateBrowserHistoryRef.current = (direction: 'back' | 'forward'): void => {
|
||||
// Why: Logitech Options+ side-button remaps on macOS arrive as these
|
||||
// keyboard shortcuts. This local pane owns the webview ref, so route the
|
||||
// remap through the same navigation path as the toolbar buttons.
|
||||
if (direction === 'back') {
|
||||
webviewRef.current?.goBack()
|
||||
} else {
|
||||
webviewRef.current?.goForward()
|
||||
}
|
||||
}
|
||||
const keybindings = useAppStore((state) => state.keybindings)
|
||||
const browserDefaultZoomLevel = useAppStore(
|
||||
(state) => state.browserDefaultZoomLevel ?? DEFAULT_BROWSER_PAGE_ZOOM_LEVEL
|
||||
@@ -3225,6 +3262,45 @@ function BrowserPagePane({
|
||||
})
|
||||
}, [isActive])
|
||||
|
||||
// Browser history shortcuts (renderer path: focus on browser chrome)
|
||||
// Why: macOS cannot deliver Logitech side-button navigation to Electron, but
|
||||
// Logi Options+ can remap those buttons to standard browser history chords.
|
||||
// Handle the chords here when focus is on the toolbar or address bar.
|
||||
useEffect(() => {
|
||||
if (!isActive) {
|
||||
return
|
||||
}
|
||||
const shortcutPlatform = getShortcutPlatform()
|
||||
const handleKeyDown = (e: KeyboardEvent): void => {
|
||||
const direction = keybindingMatchesAction('browser.back', e, shortcutPlatform, keybindings)
|
||||
? 'back'
|
||||
: keybindingMatchesAction('browser.forward', e, shortcutPlatform, keybindings)
|
||||
? 'forward'
|
||||
: null
|
||||
if (direction === null) {
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
navigateBrowserHistoryRef.current(direction)
|
||||
}
|
||||
window.addEventListener('keydown', handleKeyDown, true)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown, true)
|
||||
}, [isActive, keybindings])
|
||||
|
||||
// Browser history shortcuts (IPC path: focus inside webview guest)
|
||||
// Why: a focused webview is a separate WebContents. Main forwards the same
|
||||
// remapped history chords back here so page focus and toolbar focus behave
|
||||
// identically.
|
||||
useEffect(() => {
|
||||
if (!isActive) {
|
||||
return
|
||||
}
|
||||
return window.api.ui.onBrowserHistoryNavigate((direction) => {
|
||||
navigateBrowserHistoryRef.current(direction)
|
||||
})
|
||||
}, [isActive])
|
||||
|
||||
// Close find bar when tab is deactivated
|
||||
useEffect(() => {
|
||||
if (!isActive) {
|
||||
|
||||
@@ -2008,6 +2008,7 @@ function createWebUiApi(): NonNullable<Partial<PreloadApi>['ui']> {
|
||||
onFocusBrowserAddressBar: () => noopUnsubscribe,
|
||||
onFindInBrowserPage: () => noopUnsubscribe,
|
||||
onReloadBrowserPage: () => noopUnsubscribe,
|
||||
onBrowserHistoryNavigate: () => noopUnsubscribe,
|
||||
onZoomBrowserPage: () => noopUnsubscribe,
|
||||
onHardReloadBrowserPage: () => noopUnsubscribe,
|
||||
onCloseActiveTab: () => noopUnsubscribe,
|
||||
|
||||
@@ -238,6 +238,43 @@ describe('keybindings', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('defines browser history shortcuts for Logitech side-button remaps', () => {
|
||||
expect(getEffectiveKeybindingsForAction('browser.back', 'darwin')).toEqual(['Mod+BracketLeft'])
|
||||
expect(getEffectiveKeybindingsForAction('browser.forward', 'darwin')).toEqual([
|
||||
'Mod+BracketRight'
|
||||
])
|
||||
expect(getEffectiveKeybindingsForAction('browser.back', 'linux')).toEqual(['Alt+ArrowLeft'])
|
||||
expect(getEffectiveKeybindingsForAction('browser.forward', 'win32')).toEqual(['Alt+ArrowRight'])
|
||||
expect(
|
||||
keybindingMatchesAction(
|
||||
'browser.back',
|
||||
{
|
||||
key: '[',
|
||||
code: 'BracketLeft',
|
||||
meta: true,
|
||||
control: false,
|
||||
alt: false,
|
||||
shift: false
|
||||
},
|
||||
'darwin'
|
||||
)
|
||||
).toBe(true)
|
||||
expect(
|
||||
keybindingMatchesAction(
|
||||
'browser.forward',
|
||||
{
|
||||
key: 'ArrowRight',
|
||||
code: 'ArrowRight',
|
||||
meta: false,
|
||||
control: false,
|
||||
alt: true,
|
||||
shift: false
|
||||
},
|
||||
'linux'
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('binds close-all editor tabs to Mod+Alt+W beside tab.close', () => {
|
||||
expect(getEffectiveKeybindingsForAction('tab.closeAll', 'darwin')).toEqual(['Mod+Alt+W'])
|
||||
expect(getEffectiveKeybindingsForAction('tab.closeAll', 'linux')).toEqual(['Mod+Alt+W'])
|
||||
|
||||
@@ -73,6 +73,8 @@ export type KeybindingActionId =
|
||||
| 'tab.nextTerminal'
|
||||
| 'tab.previousTerminal'
|
||||
| 'browser.find'
|
||||
| 'browser.back'
|
||||
| 'browser.forward'
|
||||
| 'browser.reload'
|
||||
| 'browser.hardReload'
|
||||
| 'browser.focusAddressBar'
|
||||
@@ -582,6 +584,30 @@ export const KEYBINDING_DEFINITIONS: readonly KeybindingDefinition[] = [
|
||||
searchKeywords: ['shortcut', 'browser', 'find', 'search'],
|
||||
defaultBindings: platformBindings(['Mod+F'])
|
||||
},
|
||||
{
|
||||
id: 'browser.back',
|
||||
title: 'Go Back in Browser',
|
||||
group: 'Browser',
|
||||
scope: 'browser',
|
||||
searchKeywords: ['shortcut', 'browser', 'history', 'back', 'previous'],
|
||||
defaultBindings: {
|
||||
darwin: ['Mod+BracketLeft'],
|
||||
linux: ['Alt+ArrowLeft'],
|
||||
win32: ['Alt+ArrowLeft']
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'browser.forward',
|
||||
title: 'Go Forward in Browser',
|
||||
group: 'Browser',
|
||||
scope: 'browser',
|
||||
searchKeywords: ['shortcut', 'browser', 'history', 'forward', 'next'],
|
||||
defaultBindings: {
|
||||
darwin: ['Mod+BracketRight'],
|
||||
linux: ['Alt+ArrowRight'],
|
||||
win32: ['Alt+ArrowRight']
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'browser.reload',
|
||||
title: 'Reload Browser Page',
|
||||
|
||||
Reference in New Issue
Block a user