mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
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:
@@ -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;
|
||||
|
||||
@@ -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('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user