fix: Fix bug that prevented redoing adding empty block comments (#9568)

* fix: Fix bug that prevented redoing adding empty block comments

* test: Add tests for undoing/redoing adding comments

* test: Add tests for un/redoing adding non-empty comments
This commit is contained in:
Aaron Dodson
2026-01-13 14:52:19 -08:00
committed by GitHub
parent 43ea4161c0
commit eb4288219e
2 changed files with 46 additions and 1 deletions

View File

@@ -193,7 +193,7 @@ export class BlockChange extends BlockBase {
break;
}
case 'comment':
block.setCommentText((value as string) || null);
block.setCommentText((value as string) ?? null);
break;
case 'collapsed':
block.setCollapsed(!!value);

View File

@@ -167,4 +167,49 @@ suite('Comments', function () {
assertBubbleLocation(this.comment, 100, 100);
});
});
suite('Undo/Redo', function () {
test('Adding an empty comment can be undone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('');
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), '');
this.workspace.undo(false);
assert.isUndefined(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.isNull(block.getCommentText());
});
test('Adding an empty comment can be redone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('');
this.workspace.undo(false);
this.workspace.undo(true);
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), '');
});
test('Adding a non-empty comment can be undone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('hey there');
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), 'hey there');
this.workspace.undo(false);
assert.isUndefined(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.isNull(block.getCommentText());
});
test('Adding a non-empty comment can be redone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('hey there');
this.workspace.undo(false);
this.workspace.undo(true);
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), 'hey there');
});
});
});