Skip to content

Commit f24940e

Browse files
authored
fix: dont add comments to full block fields (#9263)
* fix: dont add comments to full block fields * chore: remove some nonnull assertions
1 parent 683a435 commit f24940e

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

core/block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ export class Block {
11181118
*
11191119
* @yields A generator that can be used to iterate the fields on the block.
11201120
*/
1121-
*getFields(): Generator<Field> {
1121+
*getFields(): Generator<Field, undefined, void> {
11221122
for (const input of this.inputList) {
11231123
for (const field of input.fieldRow) {
11241124
yield field;

core/contextmenu_items.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import {StatementInput} from './renderers/zelos/zelos.js';
2525
import {Coordinate} from './utils/coordinate.js';
2626
import 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

Comments
 (0)