@@ -37,12 +37,18 @@ describe("resolveAnnotationSubmission", () => {
3737} ) ;
3838
3939const dispatchKey = (
40- input : { inOverlay ?: boolean ; commentFocused ?: boolean ; canSend ?: boolean } = { } ,
40+ input : {
41+ inOverlay ?: boolean ;
42+ commentFocused ?: boolean ;
43+ canSend ?: boolean ;
44+ isTrusted ?: boolean ;
45+ } = { } ,
4146 overrides : Partial < Parameters < typeof resolveAnnotationSubmission > [ 0 ] > = { } ,
4247 type = "keydown" ,
4348) => {
4449 const window = new EventTarget ( ) ;
4550 const event = Object . assign ( new Event ( type , { cancelable : true } ) , keyboardEvent ( overrides ) ) ;
51+ Object . defineProperty ( event , "isTrusted" , { value : input . isTrusted ?? true } ) ;
4652 const actions : Array < ReturnType < typeof handleAnnotationKeyEvent > > = [ ] ;
4753 let pageEvents = 0 ;
4854 window . addEventListener ( type , ( ) => {
@@ -102,6 +108,18 @@ describe("annotation keyboard isolation", () => {
102108 } ) ;
103109 } ) ;
104110
111+ it ( "ignores page-generated submission and cancellation events on the overlay host" , ( ) => {
112+ expect ( dispatchKey ( { isTrusted : false } ) ) . toEqual ( {
113+ action : null ,
114+ pageEvents : 0 ,
115+ defaultPrevented : false ,
116+ } ) ;
117+ expect ( dispatchKey ( { isTrusted : false } , { ctrlKey : true } ) . action ) . toBeNull ( ) ;
118+ expect ( dispatchKey ( { isTrusted : false } , { metaKey : true } ) . action ) . toBeNull ( ) ;
119+ expect ( dispatchKey ( { isTrusted : false } , { key : "Escape" } ) . action ) . toBeNull ( ) ;
120+ expect ( dispatchKey ( { isTrusted : false , inOverlay : false } , { key : "r" } ) . action ) . toBeNull ( ) ;
121+ } ) ;
122+
105123 it ( "leaves page keyboard input and tool selection outside the overlay available" , ( ) => {
106124 expect ( dispatchKey ( { inOverlay : false } , { key : " " } ) . pageEvents ) . toBe ( 1 ) ;
107125 expect ( dispatchKey ( { inOverlay : false } , { key : "r" } ) . action ) . toBe ( "marquee" ) ;
0 commit comments