Skip to content

Commit eb42882

Browse files
authored
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
1 parent 43ea416 commit eb42882

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

core/events/events_block_change.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class BlockChange extends BlockBase {
193193
break;
194194
}
195195
case 'comment':
196-
block.setCommentText((value as string) || null);
196+
block.setCommentText((value as string) ?? null);
197197
break;
198198
case 'collapsed':
199199
block.setCollapsed(!!value);

tests/mocha/comment_test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,49 @@ suite('Comments', function () {
167167
assertBubbleLocation(this.comment, 100, 100);
168168
});
169169
});
170+
suite('Undo/Redo', function () {
171+
test('Adding an empty comment can be undone', function () {
172+
const block = this.workspace.newBlock('empty_block');
173+
block.setCommentText('');
174+
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
175+
assert.equal(block.getCommentText(), '');
176+
177+
this.workspace.undo(false);
178+
179+
assert.isUndefined(block.getIcon(Blockly.icons.IconType.COMMENT));
180+
assert.isNull(block.getCommentText());
181+
});
182+
183+
test('Adding an empty comment can be redone', function () {
184+
const block = this.workspace.newBlock('empty_block');
185+
block.setCommentText('');
186+
this.workspace.undo(false);
187+
this.workspace.undo(true);
188+
189+
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
190+
assert.equal(block.getCommentText(), '');
191+
});
192+
193+
test('Adding a non-empty comment can be undone', function () {
194+
const block = this.workspace.newBlock('empty_block');
195+
block.setCommentText('hey there');
196+
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
197+
assert.equal(block.getCommentText(), 'hey there');
198+
199+
this.workspace.undo(false);
200+
201+
assert.isUndefined(block.getIcon(Blockly.icons.IconType.COMMENT));
202+
assert.isNull(block.getCommentText());
203+
});
204+
205+
test('Adding a non-empty comment can be redone', function () {
206+
const block = this.workspace.newBlock('empty_block');
207+
block.setCommentText('hey there');
208+
this.workspace.undo(false);
209+
this.workspace.undo(true);
210+
211+
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
212+
assert.equal(block.getCommentText(), 'hey there');
213+
});
214+
});
170215
});

0 commit comments

Comments
 (0)