@@ -169,16 +169,65 @@ export class NotebookKeyboardPage extends BasePage {
169169 return this . getPlatform ( ) === 'darwin' ;
170170 }
171171
172+ private async executeWebkitShortcut ( formattedShortcut : string ) : Promise < void > {
173+ const parts = formattedShortcut . split ( '+' ) ;
174+ const mainKey = parts [ parts . length - 1 ] ;
175+ const hasControl = formattedShortcut . includes ( 'control' ) ;
176+ const hasShift = formattedShortcut . includes ( 'shift' ) ;
177+ const hasAlt = formattedShortcut . includes ( 'alt' ) ;
178+ const keyMap : Record < string , string > = {
179+ arrowup : 'ArrowUp' ,
180+ arrowdown : 'ArrowDown' ,
181+ enter : 'Enter'
182+ } ;
183+ const resolvedKey = keyMap [ mainKey ] || mainKey . toUpperCase ( ) ;
184+
185+ if ( hasAlt ) {
186+ await this . page . keyboard . down ( 'Alt' ) ;
187+ }
188+ if ( hasShift ) {
189+ await this . page . keyboard . down ( 'Shift' ) ;
190+ }
191+ if ( hasControl ) {
192+ await this . page . keyboard . down ( 'Control' ) ;
193+ }
194+
195+ await this . page . keyboard . press ( resolvedKey , { delay : 50 } ) ;
196+
197+ if ( hasControl ) {
198+ await this . page . keyboard . up ( 'Control' ) ;
199+ }
200+ if ( hasShift ) {
201+ await this . page . keyboard . up ( 'Shift' ) ;
202+ }
203+ if ( hasAlt ) {
204+ await this . page . keyboard . up ( 'Alt' ) ;
205+ }
206+ }
207+
208+ private async executeStandardShortcut ( formattedShortcut : string ) : Promise < void > {
209+ const isMac = this . isMacOS ( ) ;
210+ const formattedKey = formattedShortcut
211+ . replace ( / a l t / g, 'Alt' )
212+ . replace ( / s h i f t / g, 'Shift' )
213+ . replace ( / a r r o w u p / g, 'ArrowUp' )
214+ . replace ( / a r r o w d o w n / g, 'ArrowDown' )
215+ . replace ( / e n t e r / g, 'Enter' )
216+ . replace ( / c o n t r o l / g, isMac ? 'Meta' : 'Control' )
217+ . replace ( / \+ ( [ a - z 0 - 9 - = ] ) $ / , ( _ , c ) => `+${ c . toUpperCase ( ) } ` ) ;
218+
219+ console . log ( 'Final key combination:' , formattedKey ) ;
220+ await this . page . keyboard . press ( formattedKey , { delay : 50 } ) ;
221+ }
222+
172223 // Platform-aware keyboard shortcut execution
173224 private async executePlatformShortcut ( shortcuts : string | string [ ] ) : Promise < void > {
174225 const shortcutArray = Array . isArray ( shortcuts ) ? shortcuts : [ shortcuts ] ;
175- const isMac = this . isMacOS ( ) ;
176226 const browserName = test . info ( ) . project . name ;
177227
178228 for ( const shortcut of shortcutArray ) {
179229 try {
180230 const formatted = shortcut . toLowerCase ( ) . replace ( / \. / g, '+' ) ;
181-
182231 console . log ( 'Shortcut:' , shortcut , '->' , formatted , 'on' , browserName ) ;
183232
184233 await this . page . evaluate ( ( ) => {
@@ -189,54 +238,9 @@ export class NotebookKeyboardPage extends BasePage {
189238 } ) ;
190239
191240 if ( browserName === 'webkit' ) {
192- const parts = formatted . split ( '+' ) ;
193- const mainKey = parts [ parts . length - 1 ] ;
194-
195- const hasControl = formatted . includes ( 'control' ) ;
196- const hasShift = formatted . includes ( 'shift' ) ;
197- const hasAlt = formatted . includes ( 'alt' ) ;
198-
199- // Key mapping for special keys
200- const keyMap : Record < string , string > = {
201- arrowup : 'ArrowUp' ,
202- arrowdown : 'ArrowDown' ,
203- enter : 'Enter'
204- } ;
205- const resolvedKey = keyMap [ mainKey ] || mainKey . toUpperCase ( ) ;
206-
207- if ( hasAlt ) {
208- await this . page . keyboard . down ( 'Alt' ) ;
209- }
210- if ( hasShift ) {
211- await this . page . keyboard . down ( 'Shift' ) ;
212- }
213- if ( hasControl ) {
214- await this . page . keyboard . down ( 'Control' ) ;
215- }
216-
217- await this . page . keyboard . press ( resolvedKey , { delay : 50 } ) ;
218-
219- if ( hasControl ) {
220- await this . page . keyboard . up ( 'Control' ) ;
221- }
222- if ( hasShift ) {
223- await this . page . keyboard . up ( 'Shift' ) ;
224- }
225- if ( hasAlt ) {
226- await this . page . keyboard . up ( 'Alt' ) ;
227- }
241+ await this . executeWebkitShortcut ( formatted ) ;
228242 } else {
229- const formattedKey = formatted
230- . replace ( / a l t / g, 'Alt' )
231- . replace ( / s h i f t / g, 'Shift' )
232- . replace ( / a r r o w u p / g, 'ArrowUp' )
233- . replace ( / a r r o w d o w n / g, 'ArrowDown' )
234- . replace ( / e n t e r / g, 'Enter' )
235- . replace ( / c o n t r o l / g, isMac ? 'Meta' : 'Control' )
236- . replace ( / \+ ( [ a - z 0 - 9 - = ] ) $ / , ( _ , c ) => `+${ c . toUpperCase ( ) } ` ) ;
237-
238- console . log ( 'Final key combination:' , formattedKey ) ;
239- await this . page . keyboard . press ( formattedKey , { delay : 50 } ) ;
243+ await this . executeStandardShortcut ( formatted ) ;
240244 }
241245
242246 return ;
0 commit comments