feat(browser): route find-next and previous shortcuts from the focused pane

This commit is contained in:
Luke Parker 2026-11-16 19:26:04 +10:00
parent c7af0521b9
commit 30db113897
6 changed files with 32 additions and 6 deletions

View file

@ -51,6 +51,10 @@ test.each([
test("forwards browser and shell shortcuts while leaving page editing, reload and in-page chords to the page", () => {
const cases: [modifiers: string, key: string, mac: boolean, forwarded: string | undefined, code?: string][] = [
// Browser tab, window and shell chords forwarded from the page.
["mod", "g", true, "g"], ["mod+shift", "G", true, "g"],
["mod", "g", false, "g"], ["mod+shift", "G", false, "g"],
["", "F3", false, "F3"], ["shift", "F3", false, "F3"],
["", "F3", true, undefined], ["ctrl", "g", true, undefined],
["mod", "t", true, "t"],
["mod", "t", false, "t"],
// Dvorak: T is on the physical K key and Y on the physical T key; the character decides.
@ -119,8 +123,6 @@ test("forwards browser and shell shortcuts while leaving page editing, reload an
// Find, reload, history, and the pane's own picker and zoom chords.
["mod", "f", true, "f"],
["mod", "f", false, "f"],
["mod", "g", true, undefined],
["mod+shift", "G", true, undefined],
["mod", "r", true, undefined],
["mod", "r", false, undefined],
["mod", "[", true, undefined],

View file

@ -30,12 +30,12 @@ export type PageShortcut = {
// Unshifted chords with the platform's modifier that belong to the app shell or browser pane rather than the page:
// opening, closing or switching tabs, focusing the address field, opening settings, and toggling the file tree.
const shellKeys = ["t", "w", "l", "f", "n", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", "\\"]
const shellKeys = ["t", "w", "l", "f", "g", "n", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", "\\"]
// Shifted chords with the platform's modifier that belong to the app shell rather than the page: reopening a tab,
// switching side-panel tabs, toggling the side panel, opening the command palette, or running session commands. New Window and Close Window
// (⇧⌘N, ⇧⌘W) stay unclaimed: only their menu accelerators handle them, and claiming a chord also blocks the menu.
const shellShiftKeys = ["t", "[", "]", "r", "p", "l", "e", "o", "s"]
const shellShiftKeys = ["t", "[", "]", "r", "g", "p", "l", "e", "o", "s"]
// The side panel's launchers: Review, Browser and Open file, with ⌃⌘ on macOS and Ctrl+Alt elsewhere. Only a typed
// Latin letter counts, so AltGr (Ctrl+Alt) typing on other layouts stays with the page.
@ -82,6 +82,7 @@ export function pageShortcut(input: PageKey, mac: boolean): PageShortcut | undef
const launcher = mac ? input.meta && input.control && !input.alt : input.control && input.alt && !input.meta
const matched =
(!mac && key === "f3" && !input.control && !input.meta && !input.alt) ||
(input.control && !input.meta && !input.alt && (key === "tab" || (key === "`" && !input.shift))) ||
(launcher && !input.shift && launcherKeys.includes(input.key.toLowerCase())) ||
(mod &&

View file

@ -82,6 +82,7 @@ type PaneHandle = {
/** Focuses the address field and selects its text. */
focusAddress: () => void
find: () => void
findMatch: (direction: "next" | "previous") => void
/** Runs a key press the page handed to the app, as if it was pressed in this pane. */
press: (event: ShortcutEvent) => void
/** Marks the pane as holding the user's focus, which the page took outside the window's document. */

View file

@ -43,6 +43,12 @@ export function createPageFind(contents: WebContents, report: (view: FindView |
}
const previous = state
if (state.status === "closed" && (action.type === "previous" || action.type === "next")) {
state = transitionFind(state, { type: "open" })
report(findView(state))
}
state = transitionFind(state, action)
const view = findView(state)
@ -50,7 +56,7 @@ export function createPageFind(contents: WebContents, report: (view: FindView |
clearTimeout(timer)
if (action.type === "previous" || action.type === "next")
return search(action.type === "next", previous.status === "editing")
return search(action.type === "next", previous.status === "editing" || previous.status === "closed")
report(view)
if (!state.query) return contents.stopFindInPage("clearSelection")

View file

@ -206,7 +206,7 @@ export default function SessionBrowserPane(props: {
const tab = state()
// Nothing to search while a dialog blocks the page; the bar would also sit beside the dialog's focus trap.
if (!tab || (action.type === "open" && promptKey(true))) return
if (!tab || (action.type !== "close" && promptKey(true))) return
if (action.type === "open" && findInput?.isConnected) {
findInput.focus()
@ -426,6 +426,7 @@ export default function SessionBrowserPane(props: {
inspect: toggleInspect,
focusAddress,
find: () => find({ type: "open" }),
findMatch: (type) => find({ type }),
// Dispatched inside the pane, so keybinds scoped to it, such as closing the browser tab, apply.
press: (event) => {
if (!visible()) return

View file

@ -199,6 +199,21 @@ const setup: Plugin.Setup<typeof definition> = (ctx) => {
}
})
for (const direction of ["next", "previous"] as const) {
const shift = direction === "previous" ? "shift+" : ""
ctx.add(Command, (): Command | undefined => {
const pane = model()?.pane()
if (!pane) return
return {
id: `find.${direction}`, title: ctx.t(`find.${direction}`), group: ctx.t("command.category.view"),
bind: mac ? `mod+${shift}g` : `mod+${shift}g,${shift}f3`, scope: "#browser-panel", editable: true,
enabled: pane.visible() && pane.inspectable(), run: () => pane.findMatch(direction),
}
})
}
// The system browser's address shortcut, in the pane and, forwarded like mod+t and mod+w, from a page with focus.
// Ctrl+L focuses the composer outside the pane on Windows and Linux.
ctx.add(Command, (): Command | undefined => {