feat(web): the right panel works like a browser from the keyboard #15035
Closedbmdavis419(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromfeat/right-panel-keybindingsopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/desktop/src/preview/ForwardedShortcuts.ts lines 62 to 62OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +42,21 @@42+ if (/^[a-z]$/.test(layoutKey)) return new Set([layoutKey]);43+ const keys = new Set([layoutKey === "esc" ? "escape" : layoutKey]);44+ const letter = /^Key([A-Z])$/.exec(input.code)?.[1];45+ if (letter) keys.add(letter.toLowerCase());46+ const physicalKey = CODE_KEYS[input.code];47+ if (physicalKey) keys.add(physicalKey);48+ return keys;49+};50+51+/**52+ * The event to hand back to the app when a press in a focused preview page is53+ * one of the app's forwarded shortcuts, or null when the page keeps the key.54+ * Presses without Command or Control are typing, so they always stay with the55+ * page unless they are function keys.56+ */57+export const forwardedShortcutEvent = (58+ input: ShortcutInput,59+ shortcuts: ReadonlyArray<DesktopPreviewForwardedShortcut>,60+): DesktopPreviewShortcutEvent | null => {61+ if (input.type !== "keyDown") return null;62+ if (!input.meta && !input.control && !/^F\d{1,2}$/.test(input.key)) return null;apps/desktop/src/preview/Manager.ts line 2058OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2045,3 +2052,7 @@20452052 );20462053 return;20472054 }2055+ // Browser and panel shortcuts belong to the app while a person has the2056+ // page focused. Agent keystrokes and native editing stay with the page.2057+ if (2058+ agentDrivenWebContents.has(wc) ||apps/web/src/components/preview/PreviewView.tsx line 686OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -678,5 +678,9 @@678678 };679679 }, [runtimeTabId]);680680681- // Subscribe only while visible; `toggle-panel` is owned by ChatView's682- // URL-aware handler regardless of whether the panel is currently mounted.681+ // `toggle-panel` is owned by ChatView's URL-aware handler regardless of682+ // whether the panel is currently mounted.683+ const previewActionHandlers: Record<Exclude<PreviewAction, "toggle-panel">, () => void> = {684+ refresh: handleRefresh,685+ "hard-refresh": () => {686+ if (previewBridge && runtimeTabId) void previewBridge.hardReload(runtimeTabId);
- @@ -2045,3 +2052,13 @@20452052 );20462053 return;20472054 }2055+ // Browser and panel shortcuts belong to the app while a person has the2056+ // page focused. Agent keystrokes and native editing stay with the page.2057+ if (2058+ agentDrivenWebContents.has(wc) ||2059+ webContents.getFocusedWebContents() !== wc ||2060+ isPreviewEditingShortcut(input, hostPlatform)2061+ ) {2062+ return;2063+ }2064+ const shortcut = forwardedShortcutEvent(input, forwardedShortcuts);
juliusmarminge closed this
bmdavis419(GitHub profile, opens in a new tab) reopened this
- @@ -0,0 +1,10 @@1+import { normalizePreviewUrl } from "@t3tools/shared/preview";2+3+/** Resolve address-bar input without changing URL-only navigation used by agents. */4+export function resolveAddressBarInput(input: string): string {5+ const text = input.trim();6+ if (!text || /^[a-z][a-z\d+.-]*:\/\//i.test(text)) return normalizePreviewUrl(text);7+8+ const authority = text.split(/[/?#]/, 1)[0] ?? "";9+ const looksLikeAddress =10+ !/\s/.test(authority) &&apps/web/src/components/ChatView.tsx line 7503Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -7463,0 +7493,21 @@7493+ command,7494+ );7495+ if (!target) return;7496+ event.preventDefault();7497+ event.stopPropagation();7498+ if (target.id !== activeRightPanelSurface?.id) activateRightPanelSurface(target);7499+ // The outgoing surface may unmount with focus inside it; keep focus in7500+ // the panel so the next tab shortcut still applies. Terminals take7501+ // focus themselves.7502+ if (target.kind !== "terminal") {7503+ window.requestAnimationFrame(() => {7504+ document7505+ .querySelector<HTMLElement>(`[data-right-panel-tab="${CSS.escape(target.id)}"]`)7506+ ?.focus();7507+ });7508+ }7509+ return;7510+ }7511+7512+ if (command === "preview.newTab") {7513+ event.preventDefault();@@ -1315,4 +1313,4 @@13151313 }13161314 return (13171315 activeElement.closest(1318- '[role="dialog"], [role="alertdialog"], [data-slot$="-popup"], [data-terminal-owner]',1316+ '[role="dialog"], [role="alertdialog"], [data-slot$="-popup"], [data-terminal-owner], [data-preview-panel-mode]',apps/web/src/components/ChatView.tsx lines 5428 to 5430OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5407,11 +5413,18 @@54075413 if (activeThreadRef) {54085414 // Closing the panel on a live browser or device floats it instead of dropping it.54095415 if (activeRightPanelSurface?.kind === "preview" && activeRightPanelSurface.resourceId) {5410- usePreviewMiniPlayerStore5411- .getState()5412- .open(activeThreadRef, browserMiniPlayerSource(activeRightPanelSurface.resourceId));5416+ const snapshot = activePreviewState.sessions[activeRightPanelSurface.resourceId];5417+ if (snapshot && snapshot.navStatus._tag !== "Idle") {5418+ usePreviewMiniPlayerStore5419+ .getState()5420+ .open(activeThreadRef, browserMiniPlayerSource(activeRightPanelSurface.resourceId));5421+ } else {5422+ usePreviewMiniPlayerStore.getState().close(activeThreadRef);5423+ }54135424 } else if (activeRightPanelSurface?.kind === "device" && activeRightPanelSurface.target) {54145425 usePreviewMiniPlayerStore54155426 .getState()54165427 .open(activeThreadRef, { kind: "device", ...activeRightPanelSurface.target });5428+ } else if (activePreviewMiniPlayer?.source.kind === "browser") {5429+ usePreviewMiniPlayerStore.getState().close(activeThreadRef);54175430 }
- @@ -2045,3 +2052,13 @@20452052 );20462053 return;20472054 }2055+ // Browser and panel shortcuts belong to the app while a person has the2056+ // page focused. Agent keystrokes and native editing stay with the page.2057+ // getFocusedWebContents() can return a hidden guest after switching tabs;2058+ // check the guest receiving this event instead.2059+ if (2060+ agentDrivenWebContents.has(wc) ||2061+ !wc.isFocused() ||2062+ isPreviewEditingShortcut(input, hostPlatform)2063+ ) {2064+ return;
juliusmarminge added labelsmacroscope-review
- apps/server/src/keybindings.ts line 131OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -119,3 +119,13 @@119119 return leftContext === rightContext;120120 }121121122+/**123+ * Whether two rules can fire on the same key press on some platform, whatever124+ * their `when`. `mod` is Command on macOS and Control elsewhere.125+ */126+function canShareChord(left: KeybindingRule, right: KeybindingRule): boolean {127+ const leftShortcut = parseKeybindingShortcut(left.key);128+ const rightShortcut = parseKeybindingShortcut(right.key);129+ if (!leftShortcut || !rightShortcut) return false;130+ if (131+ leftShortcut.key !== rightShortcut.key ||
- packages/shared/src/keybindings.ts lines 93 to 99Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -89,3 +90,10 @@8990 command,9091 when: "modelPickerOpen && isDesktop",9192 })),93+ // A terminal tab from a terminal, a browser tab from anywhere else in a thread.94+ { key: "mod+t", command: "rightPanel.newTab" },95+ // The right panel behaves like a browser window while it has focus. These96+ // sit after the global rules they shadow (thread traversal and jumps,97+ // navigation history, copy reference, model picker) so they win there.98+ { key: "mod+shift+r", command: "preview.hardRefresh", when: "previewFocus && previewOpen" },99+ { key: "mod+[", command: "preview.back", when: "previewFocus && previewOpen" },
juliusmarminge requested changes
tanstack-source added labelsfeature
bmdavis419(GitHub profile, opens in a new tab) linked this to fix #17915
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.



Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
408ff8a· PR result:095d83c· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.