fix: dont add comments to full block fields (#9263)

* fix: dont add comments to full block fields

* chore: remove some nonnull assertions
This commit is contained in:
Maribeth Moffatt
2025-08-04 16:14:44 -04:00
committed by GitHub
parent 683a4357ff
commit f24940e781
2 changed files with 18 additions and 7 deletions

View File

@@ -1118,7 +1118,7 @@ export class Block {
*
* @yields A generator that can be used to iterate the fields on the block.
*/
*getFields(): Generator<Field> {
*getFields(): Generator<Field, undefined, void> {
for (const input of this.inputList) {
for (const field of input.fieldRow) {
yield field;

View File

@@ -25,6 +25,12 @@ import {StatementInput} from './renderers/zelos/zelos.js';
import {Coordinate} from './utils/coordinate.js';
import type {WorkspaceSvg} from './workspace_svg.js';
function isFullBlockField(block?: BlockSvg) {
if (!block || !block.isSimpleReporter()) return false;
const firstField = block.getFields().next().value;
return firstField?.isFullBlockField();
}
/**
* Option to undo previous action.
*/
@@ -362,10 +368,15 @@ export function registerComment() {
preconditionFn(scope: Scope) {
const block = scope.block;
if (
!block!.isInFlyout &&
block!.workspace.options.comments &&
!block!.isCollapsed() &&
block!.isEditable()
block &&
!block.isInFlyout &&
block.workspace.options.comments &&
!block.isCollapsed() &&
block.isEditable() &&
// Either block already has a comment so let us remove it,
// or the block isn't just one full-block field block, which
// shouldn't be allowed to have comments as there's no way to read them.
(block.hasIcon(CommentIcon.TYPE) || !isFullBlockField(block))
) {
return 'enabled';
}
@@ -373,8 +384,8 @@ export function registerComment() {
},
callback(scope: Scope) {
const block = scope.block;
if (block!.hasIcon(CommentIcon.TYPE)) {
block!.setCommentText(null);
if (block && block.hasIcon(CommentIcon.TYPE)) {
block.setCommentText(null);
} else {
block!.setCommentText('');
}