66
77import {
88 Events ,
9- Msg ,
109 ShortcutRegistry ,
1110 utils as BlocklyUtils ,
1211 getFocusManager ,
@@ -54,33 +53,53 @@ export class EnterAction {
5453 */
5554 ShortcutRegistry . registry . register ( {
5655 name : Constants . SHORTCUT_NAMES . EDIT_OR_CONFIRM ,
57- preconditionFn : ( workspace ) =>
58- this . navigation . canCurrentlyEdit ( workspace ) ,
59- callback : ( workspace , event ) => {
56+ preconditionFn : ( workspace ) : boolean => {
57+ switch ( this . navigation . getState ( ) ) {
58+ case Constants . STATE . WORKSPACE :
59+ // The main workspace may or may not handle it depending on what's
60+ // selected, so always pass it through to the callback.
61+ return true ;
62+ case Constants . STATE . FLYOUT : {
63+ // If we're in the flyout the only supported actions are inserting
64+ // blocks or clicking buttons, so don't handle this if the
65+ // main workspace is read only.
66+ const targetWorkspace = workspace . isFlyout
67+ ? workspace . targetWorkspace
68+ : workspace ;
69+ return ! ! targetWorkspace && ! targetWorkspace . isReadOnly ( ) ;
70+ }
71+ default :
72+ return false ;
73+ }
74+ } ,
75+ callback : ( workspace , event ) : boolean => {
6076 event . preventDefault ( ) ;
6177
78+ const targetWorkspace = workspace . isFlyout
79+ ? workspace . targetWorkspace
80+ : workspace ;
81+ if ( ! targetWorkspace ) return false ;
82+
6283 let flyoutCursor ;
6384 let curNode ;
6485
65- switch ( this . navigation . getState ( workspace ) ) {
86+ switch ( this . navigation . getState ( ) ) {
6687 case Constants . STATE . WORKSPACE :
67- this . handleEnterForWS ( workspace ) ;
68- return true ;
88+ return this . handleEnterForWS ( workspace ) ;
6989 case Constants . STATE . FLYOUT :
70- if ( ! workspace . targetWorkspace ) return false ;
90+ if ( targetWorkspace . isReadOnly ( ) ) return false ;
7191 flyoutCursor = this . navigation . getFlyoutCursor (
72- workspace . targetWorkspace ,
92+ targetWorkspace ,
7393 ) ;
7494 if ( ! flyoutCursor ) {
7595 return false ;
7696 }
7797 curNode = flyoutCursor . getCurNode ( ) ;
7898 if ( curNode instanceof BlockSvg ) {
79- this . insertFromFlyout ( workspace . targetWorkspace ) ;
99+ this . insertFromFlyout ( targetWorkspace ) ;
80100 } else if ( curNode instanceof FlyoutButton ) {
81101 this . triggerButtonCallback ( workspace ) ;
82102 }
83-
84103 return true ;
85104 default :
86105 return false ;
@@ -94,12 +113,13 @@ export class EnterAction {
94113 * Handles hitting the enter key on the workspace.
95114 *
96115 * @param workspace The workspace.
116+ * @returns True if the enter was handled, false otherwise.
97117 */
98- private handleEnterForWS ( workspace : WorkspaceSvg ) {
118+ private handleEnterForWS ( workspace : WorkspaceSvg ) : boolean {
99119 const cursor = workspace . getCursor ( ) ;
100- if ( ! cursor ) return ;
120+ if ( ! cursor ) return false ;
101121 const curNode = cursor . getCurNode ( ) ;
102- if ( ! curNode ) return ;
122+ if ( ! curNode ) return false ;
103123 if ( curNode instanceof Field ) {
104124 curNode . showEditor ( ) ;
105125 } else if ( curNode instanceof BlockSvg ) {
@@ -114,6 +134,7 @@ export class EnterAction {
114134 } else if ( curNode instanceof icons . Icon ) {
115135 curNode . onClick ( ) ;
116136 }
137+ return true ;
117138 }
118139
119140 /**
@@ -278,7 +299,7 @@ export class EnterAction {
278299 if ( block . isSimpleReporter ( ) ) {
279300 for ( const input of block . inputList ) {
280301 for ( const field of input . fieldRow ) {
281- if ( field . isClickable ( ) && field . isFullBlockField ( ) ) {
302+ if ( field . isFullBlockField ( ) ) {
282303 field . showEditor ( ) ;
283304 return true ;
284305 }
0 commit comments