@@ -25,6 +25,12 @@ import {StatementInput} from './renderers/zelos/zelos.js';
2525import { Coordinate } from './utils/coordinate.js' ;
2626import type { WorkspaceSvg } from './workspace_svg.js' ;
2727
28+ function isFullBlockField ( block ?: BlockSvg ) {
29+ if ( ! block || ! block . isSimpleReporter ( ) ) return false ;
30+ const firstField = block . getFields ( ) . next ( ) . value ;
31+ return firstField ?. isFullBlockField ( ) ;
32+ }
33+
2834/**
2935 * Option to undo previous action.
3036 */
@@ -362,19 +368,24 @@ export function registerComment() {
362368 preconditionFn ( scope : Scope ) {
363369 const block = scope . block ;
364370 if (
365- ! block ! . isInFlyout &&
366- block ! . workspace . options . comments &&
367- ! block ! . isCollapsed ( ) &&
368- block ! . isEditable ( )
371+ block &&
372+ ! block . isInFlyout &&
373+ block . workspace . options . comments &&
374+ ! block . isCollapsed ( ) &&
375+ block . isEditable ( ) &&
376+ // Either block already has a comment so let us remove it,
377+ // or the block isn't just one full-block field block, which
378+ // shouldn't be allowed to have comments as there's no way to read them.
379+ ( block . hasIcon ( CommentIcon . TYPE ) || ! isFullBlockField ( block ) )
369380 ) {
370381 return 'enabled' ;
371382 }
372383 return 'hidden' ;
373384 } ,
374385 callback ( scope : Scope ) {
375386 const block = scope . block ;
376- if ( block ! . hasIcon ( CommentIcon . TYPE ) ) {
377- block ! . setCommentText ( null ) ;
387+ if ( block && block . hasIcon ( CommentIcon . TYPE ) ) {
388+ block . setCommentText ( null ) ;
378389 } else {
379390 block ! . setCommentText ( '' ) ;
380391 }
0 commit comments