@@ -15,6 +15,7 @@ import type {
1515 DesktopPreviewAutomationStatus ,
1616 DesktopPreviewColorScheme ,
1717 DesktopPreviewFavicon ,
18+ DesktopPreviewForwardedShortcut ,
1819 DesktopPreviewPointerEvent ,
1920 PreviewAnnotationPayload ,
2021 PreviewAnnotationRect ,
@@ -66,8 +67,12 @@ import * as Scope from "effect/Scope";
6667import * as SynchronizedRef from "effect/SynchronizedRef" ;
6768
6869import * as DesktopEnvironment from "../app/DesktopEnvironment.ts" ;
69- import { PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "../ipc/channels.ts" ;
70+ import {
71+ PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL ,
72+ PREVIEW_SHORTCUT_CHANNEL ,
73+ } from "../ipc/channels.ts" ;
7074import * as BrowserSession from "./BrowserSession.ts" ;
75+ import { forwardedShortcutEvent } from "./ForwardedShortcuts.ts" ;
7176import {
7277 ANNOTATION_CAPTURED_CHANNEL ,
7378 ANNOTATION_THEME_CHANNEL ,
@@ -694,6 +699,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
694699 const agentDrivenWebContents = new WeakSet < Electron . WebContents > ( ) ;
695700 let frameCaptureWindowOpen = true ;
696701 let currentMainWindow : BrowserWindow | undefined ;
702+ // Read synchronously from before-input-event, so it lives outside a Ref.
703+ let forwardedShortcuts : ReadonlyArray < DesktopPreviewForwardedShortcut > = [ ] ;
697704 let mainWindowCleanupFiber : Fiber . Fiber < void , never > | undefined ;
698705 const tabLifecycleLocks = new Map <
699706 string ,
@@ -2045,6 +2052,24 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
20452052 ) ;
20462053 return ;
20472054 }
2055+ // Browser and panel shortcuts belong to the app while a person has the
2056+ // 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 ) ;
2065+ if ( ! shortcut ) return ;
2066+ event . preventDefault ( ) ;
2067+ runFork (
2068+ attempt ( { operation : "shortcut.forward" , tabId, webContentsId : wc . id } , ( ) => {
2069+ const host = currentMainWindow ?. webContents ;
2070+ if ( host && ! host . isDestroyed ( ) ) host . send ( PREVIEW_SHORTCUT_CHANNEL , shortcut ) ;
2071+ } ) . pipe ( Effect . ignore ) ,
2072+ ) ;
20482073 } ;
20492074 yield * Scope . addFinalizer (
20502075 scope ,
@@ -4722,6 +4747,10 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
47224747 setAnnotationTheme,
47234748 setAudioMuted,
47244749 setColorScheme,
4750+ setForwardedShortcuts : ( shortcuts : ReadonlyArray < DesktopPreviewForwardedShortcut > ) =>
4751+ Effect . sync ( ( ) => {
4752+ forwardedShortcuts = shortcuts ;
4753+ } ) ,
47254754 setMainWindow,
47264755 startRecording,
47274756 closePictureInPicture,
@@ -5135,6 +5164,9 @@ export class PreviewManager extends Context.Service<
51355164 tabId : string ,
51365165 input : PreviewAutomationWaitForInput ,
51375166 ) => Effect . Effect < void , PreviewManagerError > ;
5167+ readonly setForwardedShortcuts : (
5168+ shortcuts : ReadonlyArray < DesktopPreviewForwardedShortcut > ,
5169+ ) => Effect . Effect < void > ;
51385170 readonly subscribeStateChanges : ( listener : Listener ) => Effect . Effect < void , never , Scope . Scope > ;
51395171 readonly subscribePointerEvents : (
51405172 listener : PointerEventListener ,
@@ -5235,6 +5267,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
52355267 automationScroll : operations . automationScroll ,
52365268 automationEvaluate : operations . automationEvaluate ,
52375269 automationWaitFor : operations . automationWaitFor ,
5270+ setForwardedShortcuts : operations . setForwardedShortcuts ,
52385271 subscribeStateChanges : operations . subscribeStateChanges ,
52395272 subscribePointerEvents : operations . subscribePointerEvents ,
52405273 subscribeRecordingFrames : operations . subscribeRecordingFrames ,
0 commit comments