@@ -409,6 +409,7 @@ function generateRegisterEventHandler(
409409// Functions used for creating blocks for the toolbox.
410410
411411export function addRobotEventHandlerBlocks (
412+ workspace : Blockly . WorkspaceSvg ,
412413 events : storageModuleContent . Event [ ] ,
413414 eventHandlerBlocks : EventHandlerBlock [ ] ,
414415 contents : toolboxItems . ContentsType [ ] ) {
@@ -420,7 +421,7 @@ export function addRobotEventHandlerBlocks(
420421 events . forEach ( event => {
421422 if ( eventIds . includes ( event . eventId ) ) {
422423 // If there is already an event handler for this event, put a button in the toolbox.
423- const text = '\u00A0\u00A0when\u00A0\u00A0' + SENDER_VALUE_ROBOT + '\u00A0\u00A0' + event . name + '\u00A0\u00A0' ;
424+ const text = makeButtonText ( workspace , SENDER_VALUE_ROBOT , event . name ) ;
424425 const button = new toolboxItems . Button ( text , BUTTON_CALLBACK_KEY , BUTTON_STYLE ) ;
425426 contents . push ( button ) ;
426427 } else {
@@ -450,6 +451,7 @@ function createRobotEventHandlerBlock(
450451}
451452
452453export function addMechanismEventHandlerBlocks (
454+ workspace : Blockly . WorkspaceSvg ,
453455 mechanismInRobot : storageModuleContent . MechanismInRobot ,
454456 events : storageModuleContent . Event [ ] ,
455457 eventHandlerBlocks : EventHandlerBlock [ ] ,
@@ -462,7 +464,7 @@ export function addMechanismEventHandlerBlocks(
462464 events . forEach ( event => {
463465 if ( eventIds . includes ( event . eventId ) ) {
464466 // If there is already an event handler for this event, put a button in the toolbox.
465- const text = 'when ' + mechanismInRobot . name + ' ' + event . name ;
467+ const text = makeButtonText ( workspace , mechanismInRobot . name , event . name ) ;
466468 const button = new toolboxItems . Button ( text , BUTTON_CALLBACK_KEY , BUTTON_STYLE ) ;
467469 contents . push ( button ) ;
468470 } else {
@@ -471,6 +473,16 @@ export function addMechanismEventHandlerBlocks(
471473 } ) ;
472474}
473475
476+ function makeButtonText (
477+ workspace : Blockly . WorkspaceSvg , senderName : string , eventName : string ) : string {
478+ // Add non-breakable spaces so it looks more like an event handler block.
479+ const spaces = '\u00A0\u00A0' ;
480+ if ( workspace . RTL ) {
481+ return spaces + eventName + spaces + senderName + spaces + Blockly . Msg . WHEN + spaces ;
482+ }
483+ return spaces + Blockly . Msg . WHEN + spaces + senderName + spaces + eventName + spaces ;
484+ }
485+
474486function createMechanismEventHandlerBlock (
475487 mechanismInRobot : storageModuleContent . MechanismInRobot ,
476488 event : storageModuleContent . Event ) : toolboxItems . Block {
0 commit comments