@@ -38,6 +38,14 @@ export enum names {
3838 UNDO = 'undo' ,
3939 REDO = 'redo' ,
4040 MENU = 'menu' ,
41+ FOCUS_WORKSPACE = 'focus_workspace' ,
42+ START_MOVE = 'start_move' ,
43+ FINISH_MOVE = 'finish_move' ,
44+ ABORT_MOVE = 'abort_move' ,
45+ MOVE_UP = 'move_up' ,
46+ MOVE_DOWN = 'move_down' ,
47+ MOVE_LEFT = 'move_left' ,
48+ MOVE_RIGHT = 'move_right' ,
4149}
4250
4351/**
@@ -391,7 +399,7 @@ export function registerMovementShortcuts() {
391399
392400 const shortcuts : ShortcutRegistry . KeyboardShortcut [ ] = [
393401 {
394- name : 'start_move' ,
402+ name : names . START_MOVE ,
395403 preconditionFn : ( workspace ) => {
396404 const startDraggable = getCurrentDraggable ( workspace ) ;
397405 return ! ! startDraggable && KeyboardMover . mover . canMove ( startDraggable ) ;
@@ -412,23 +420,23 @@ export function registerMovementShortcuts() {
412420 keyCodes : [ KeyCodes . M ] ,
413421 } ,
414422 {
415- name : 'finish_move' ,
423+ name : names . FINISH_MOVE ,
416424 preconditionFn : ( ) => KeyboardMover . mover . isMoving ( ) ,
417425 callback : ( _workspace , e ) =>
418426 KeyboardMover . mover . finishMove ( e as KeyboardEvent ) ,
419427 keyCodes : [ KeyCodes . ENTER , KeyCodes . SPACE ] ,
420428 allowCollision : true ,
421429 } ,
422430 {
423- name : 'abort_move' ,
431+ name : names . ABORT_MOVE ,
424432 preconditionFn : ( ) => KeyboardMover . mover . isMoving ( ) ,
425433 callback : ( _workspace , e ) =>
426434 KeyboardMover . mover . abortMove ( e as KeyboardEvent ) ,
427435 keyCodes : [ KeyCodes . ESC ] ,
428436 allowCollision : true ,
429437 } ,
430438 {
431- name : 'move_left' ,
439+ name : names . MOVE_LEFT ,
432440 preconditionFn : ( ) => KeyboardMover . mover . isMoving ( ) ,
433441 callback : ( _workspace , e ) => {
434442 e . preventDefault ( ) ;
@@ -443,7 +451,7 @@ export function registerMovementShortcuts() {
443451 allowCollision : true ,
444452 } ,
445453 {
446- name : 'move_right' ,
454+ name : names . MOVE_RIGHT ,
447455 preconditionFn : ( ) => KeyboardMover . mover . isMoving ( ) ,
448456 callback : ( _workspace , e ) => {
449457 e . preventDefault ( ) ;
@@ -458,7 +466,7 @@ export function registerMovementShortcuts() {
458466 allowCollision : true ,
459467 } ,
460468 {
461- name : 'move_up' ,
469+ name : names . MOVE_UP ,
462470 preconditionFn : ( ) => KeyboardMover . mover . isMoving ( ) ,
463471 callback : ( _workspace , e ) => {
464472 e . preventDefault ( ) ;
@@ -473,7 +481,7 @@ export function registerMovementShortcuts() {
473481 allowCollision : true ,
474482 } ,
475483 {
476- name : 'move_down' ,
484+ name : names . MOVE_DOWN ,
477485 preconditionFn : ( ) => KeyboardMover . mover . isMoving ( ) ,
478486 callback : ( _workspace , e ) => {
479487 e . preventDefault ( ) ;
@@ -508,7 +516,7 @@ export function registerShowContextMenu() {
508516 preconditionFn : ( workspace ) => {
509517 return ! workspace . isDragging ( ) ;
510518 } ,
511- callback : ( workspace , e ) => {
519+ callback : ( _workspace , e ) => {
512520 const target = getFocusManager ( ) . getFocusedNode ( ) ;
513521 if ( hasContextMenu ( target ) ) {
514522 target . showContextMenu ( e ) ;
@@ -523,6 +531,33 @@ export function registerShowContextMenu() {
523531 ShortcutRegistry . registry . register ( contextMenuShortcut ) ;
524532}
525533
534+ /**
535+ * Registers keyboard shortcut to focus the workspace.
536+ */
537+ export function registerFocusWorkspace ( ) {
538+ const resolveWorkspace = ( workspace : WorkspaceSvg ) => {
539+ if ( workspace . isFlyout ) {
540+ const target = workspace . targetWorkspace ;
541+ if ( target ) {
542+ return resolveWorkspace ( target ) ;
543+ }
544+ }
545+ return workspace . getRootWorkspace ( ) ?? workspace ;
546+ } ;
547+
548+ const contextMenuShortcut : KeyboardShortcut = {
549+ name : names . FOCUS_WORKSPACE ,
550+ preconditionFn : ( workspace ) => ! workspace . isDragging ( ) ,
551+ callback : ( workspace ) => {
552+ keyboardNavigationController . setIsActive ( true ) ;
553+ getFocusManager ( ) . focusNode ( resolveWorkspace ( workspace ) ) ;
554+ return true ;
555+ } ,
556+ keyCodes : [ KeyCodes . W ] ,
557+ } ;
558+ ShortcutRegistry . registry . register ( contextMenuShortcut ) ;
559+ }
560+
526561/**
527562 * Registers all default keyboard shortcut item. This should be called once per
528563 * instance of KeyboardShortcutRegistry.
@@ -537,8 +572,17 @@ export function registerDefaultShortcuts() {
537572 registerPaste ( ) ;
538573 registerUndo ( ) ;
539574 registerRedo ( ) ;
575+ }
576+
577+ /**
578+ * Registers an extended set of keyboard shortcuts used to support deep keyboard
579+ * navigation of Blockly.
580+ */
581+ export function registerKeyboardNavigationShortcuts ( ) {
540582 registerShowContextMenu ( ) ;
541583 registerMovementShortcuts ( ) ;
584+ registerFocusWorkspace ( ) ;
542585}
543586
544587registerDefaultShortcuts ( ) ;
588+ registerKeyboardNavigationShortcuts ( ) ;
0 commit comments