66
77import {
88 Events ,
9- Msg ,
109 ShortcutRegistry ,
1110 utils as BlocklyUtils ,
1211 getFocusManager ,
@@ -54,19 +53,41 @@ 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 :
90+ if ( targetWorkspace . isReadOnly ( ) ) return false ;
7091 flyoutCursor = this . navigation . getFlyoutCursor ( workspace ) ;
7192 if ( ! flyoutCursor ) {
7293 return false ;
@@ -91,12 +112,13 @@ export class EnterAction {
91112 * Handles hitting the enter key on the workspace.
92113 *
93114 * @param workspace The workspace.
115+ * @returns True if the enter was handled, false otherwise.
94116 */
95- private handleEnterForWS ( workspace : WorkspaceSvg ) {
117+ private handleEnterForWS ( workspace : WorkspaceSvg ) : boolean {
96118 const cursor = workspace . getCursor ( ) ;
97- if ( ! cursor ) return ;
119+ if ( ! cursor ) return false ;
98120 const curNode = cursor . getCurNode ( ) ;
99- if ( ! curNode ) return ;
121+ if ( ! curNode ) return false ;
100122 if ( curNode instanceof Field ) {
101123 curNode . showEditor ( ) ;
102124 } else if ( curNode instanceof BlockSvg ) {
@@ -111,6 +133,7 @@ export class EnterAction {
111133 } else if ( curNode instanceof icons . Icon ) {
112134 curNode . onClick ( ) ;
113135 }
136+ return true ;
114137 }
115138
116139 /**
@@ -275,7 +298,7 @@ export class EnterAction {
275298 if ( block . isSimpleReporter ( ) ) {
276299 for ( const input of block . inputList ) {
277300 for ( const field of input . fieldRow ) {
278- if ( field . isClickable ( ) && field . isFullBlockField ( ) ) {
301+ if ( field . isFullBlockField ( ) ) {
279302 field . showEditor ( ) ;
280303 return true ;
281304 }
0 commit comments