@@ -73,7 +73,7 @@ function RemoteFunctions(config = {}) {
7373 "reRegisterEventHandlers" ,
7474 "handleClick" , // handle click on an icon in the tool box.
7575 // when escape key is presses in the editor, we may need to dismiss the live edit boxes.
76- "handleEscapePressFromEditor " ,
76+ "handleEscapePress " ,
7777 // interaction blocks acts as 'kill switch' to block all kinds of click handlers
7878 // this is done so that links or buttons doesn't perform their natural operation in edit mode
7979 "registerInteractionBlocker" , // to block
@@ -1364,16 +1364,23 @@ function RemoteFunctions(config = {}) {
13641364 } ) ;
13651365 }
13661366
1367- function _escapeKeyPressInEditor ( ) {
1367+ function _handleEscapeKeyPress ( ) {
13681368 enableHoverListeners ( ) ; // so that if hover lock is there it will get cleared
13691369 dismissUIAndCleanupState ( ) ;
13701370 getAllToolHandlers ( ) . forEach ( handler => {
1371- if ( handler . handleEscapePressFromEditor ) {
1372- handler . handleEscapePressFromEditor ( ) ;
1371+ if ( handler . handleEscapePress ) {
1372+ handler . handleEscapePress ( ) ;
13731373 }
13741374 } ) ;
13751375 }
13761376
1377+ document . addEventListener ( 'keydown' , function ( event ) {
1378+ if ( config . mode === 'edit' && ( event . key === 'Escape' || event . key === 'Esc' ) ) {
1379+ event . preventDefault ( ) ;
1380+ _handleEscapeKeyPress ( ) ;
1381+ }
1382+ } ) ;
1383+
13771384 // we need to refresh the config once the load is completed
13781385 // this is important because messageBroker gets ready for use only when load fires
13791386 window . addEventListener ( 'load' , function ( ) {
@@ -1397,7 +1404,7 @@ function RemoteFunctions(config = {}) {
13971404 "applyDOMEdits" : applyDOMEdits ,
13981405 "updateConfig" : updateConfig ,
13991406 "dismissUIAndCleanupState" : dismissUIAndCleanupState ,
1400- "escapeKeyPressInEditor" : _escapeKeyPressInEditor ,
1407+ "escapeKeyPressInEditor" : _handleEscapeKeyPress ,
14011408 "getMode" : function ( ) { return config . mode ; }
14021409 } ;
14031410
0 commit comments