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