File tree Expand file tree Collapse file tree 4 files changed +61
-2
lines changed Expand file tree Collapse file tree 4 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export enum SHORTCUT_NAMES {
3232 DISCONNECT = 'disconnect' ,
3333 TOOLBOX = 'toolbox' ,
3434 EXIT = 'exit' ,
35+ MENU = 'menu' ,
3536 COPY = 'keyboard_nav_copy' ,
3637 CUT = 'keyboard_nav_cut' ,
3738 PASTE = 'keyboard_nav_paste' ,
Original file line number Diff line number Diff line change @@ -167,7 +167,8 @@ export class LineCursor extends Marker {
167167 case ASTNode . types . NEXT :
168168 return ! ( location as Blockly . Connection ) . isConnected ( ) ;
169169 case ASTNode . types . FIELD :
170- return true ;
170+ // @ts -expect-error isFullBlockField is a protected method.
171+ return ! ( location as Blockly . Field ) . isFullBlockField ( ) ;
171172 default :
172173 return false ;
173174 }
Original file line number Diff line number Diff line change @@ -1242,7 +1242,17 @@ export class Navigation {
12421242 if ( nodeType == Blockly . ASTNode . types . FIELD ) {
12431243 ( curNode . getLocation ( ) as Blockly . Field ) . showEditor ( ) ;
12441244 } else if ( nodeType == Blockly . ASTNode . types . BLOCK ) {
1245- this . openActionMenu ( curNode ) ;
1245+ const block = curNode . getLocation ( ) as Blockly . Block ;
1246+ if ( ! tryShowFullBlockFieldEditor ( block ) ) {
1247+ const metaKey = navigator . platform . startsWith ( 'Mac' ) ? 'Cmd' : 'Ctrl' ;
1248+ const canMoveInHint = `Press right arrow to move in or ${ metaKey } + Enter for more options` ;
1249+ const genericHint = `Press ${ metaKey } + Enter for options` ;
1250+ const hint =
1251+ curNode . in ( ) ?. getSourceBlock ( ) === block
1252+ ? canMoveInHint
1253+ : genericHint ;
1254+ alert ( hint ) ;
1255+ }
12461256 } else if (
12471257 curNode . isConnection ( ) ||
12481258 nodeType == Blockly . ASTNode . types . WORKSPACE
@@ -1430,3 +1440,22 @@ function fakeEventForNode(node: Blockly.ASTNode): PointerEvent {
14301440 clientY : clientY + 5 ,
14311441 } ) ;
14321442}
1443+
1444+ /**
1445+ * If this block has a full block field then show its editor.
1446+ *
1447+ * @param block A block.
1448+ * @returns True if we showed the editor, false otherwise.
1449+ */
1450+ function tryShowFullBlockFieldEditor ( block : Blockly . Block ) : boolean {
1451+ for ( const input of block . inputList ) {
1452+ for ( const field of input . fieldRow ) {
1453+ // @ts -expect-error isFullBlockField is a protected method.
1454+ if ( field . isClickable ( ) && field . isFullBlockField ( ) ) {
1455+ field . showEditor ( ) ;
1456+ return true ;
1457+ }
1458+ }
1459+ }
1460+ return false ;
1461+ }
Original file line number Diff line number Diff line change @@ -552,6 +552,34 @@ export class NavigationController {
552552 keyCodes : [ KeyCodes . ENTER ] ,
553553 } ,
554554
555+ /**
556+ * Cmd/Ctrl/Alt+Enter key:
557+ *
558+ * Shows the action menu.
559+ */
560+ menu : {
561+ name : Constants . SHORTCUT_NAMES . MENU ,
562+ preconditionFn : ( workspace ) => this . canCurrentlyNavigate ( workspace ) ,
563+ callback : ( workspace ) => {
564+ switch ( this . navigation . getState ( workspace ) ) {
565+ case Constants . STATE . WORKSPACE : {
566+ const node = workspace . getCursor ( ) ?. getCurNode ( ) ;
567+ if ( node ?. getType ( ) === Blockly . ASTNode . types . BLOCK )
568+ this . navigation . openActionMenu ( node ) ;
569+
570+ return true ;
571+ }
572+ default :
573+ return false ;
574+ }
575+ } ,
576+ keyCodes : [
577+ createSerializedKey ( KeyCodes . ENTER , [ KeyCodes . CTRL ] ) ,
578+ createSerializedKey ( KeyCodes . ENTER , [ KeyCodes . ALT ] ) ,
579+ createSerializedKey ( KeyCodes . ENTER , [ KeyCodes . META ] ) ,
580+ ] ,
581+ } ,
582+
555583 /** Disconnect two blocks. */
556584 disconnect : {
557585 name : Constants . SHORTCUT_NAMES . DISCONNECT ,
You can’t perform that action at this time.
0 commit comments