diff --git a/packages/gui-plugins/src/browser/keys.test.ts b/packages/gui-plugins/src/browser/keys.test.ts index 4799d7bab0e..3ff94fe64f6 100644 --- a/packages/gui-plugins/src/browser/keys.test.ts +++ b/packages/gui-plugins/src/browser/keys.test.ts @@ -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], diff --git a/packages/gui-plugins/src/browser/keys.ts b/packages/gui-plugins/src/browser/keys.ts index ca9012909ab..3ef6db73a5e 100644 --- a/packages/gui-plugins/src/browser/keys.ts +++ b/packages/gui-plugins/src/browser/keys.ts @@ -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 && diff --git a/packages/gui-plugins/src/browser/model.ts b/packages/gui-plugins/src/browser/model.ts index 34fca6d935c..460ac06604c 100644 --- a/packages/gui-plugins/src/browser/model.ts +++ b/packages/gui-plugins/src/browser/model.ts @@ -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. */ diff --git a/packages/gui-plugins/src/browser/page-find.ts b/packages/gui-plugins/src/browser/page-find.ts index b165b9cfd16..382205c7df2 100644 --- a/packages/gui-plugins/src/browser/page-find.ts +++ b/packages/gui-plugins/src/browser/page-find.ts @@ -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") diff --git a/packages/gui-plugins/src/browser/panel.tsx b/packages/gui-plugins/src/browser/panel.tsx index 74feeb129fb..544565a205c 100644 --- a/packages/gui-plugins/src/browser/panel.tsx +++ b/packages/gui-plugins/src/browser/panel.tsx @@ -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 diff --git a/packages/gui-plugins/src/browser/renderer.tsx b/packages/gui-plugins/src/browser/renderer.tsx index b8584e531c6..a59085728ac 100644 --- a/packages/gui-plugins/src/browser/renderer.tsx +++ b/packages/gui-plugins/src/browser/renderer.tsx @@ -199,6 +199,21 @@ const setup: Plugin.Setup = (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 => {