fix: shadows in insertion markers being displayed as shadows (#7609)

* fix: shadows in insertion markers being displayed as shadows

* chore: add unit tests

* chore: remove only
This commit is contained in:
Beka Westberg
2023-11-03 18:19:30 +00:00
committed by GitHub
parent 9d117674ce
commit 0ad57f4fd3
2 changed files with 77 additions and 0 deletions

View File

@@ -271,6 +271,10 @@ export class InsertionMarkerManager {
}
}
for (const block of result.getDescendants(false)) {
block.setInsertionMarker(true);
}
result.setCollapsed(sourceBlock.isCollapsed());
result.setInputsInline(sourceBlock.getInputsInline());

View File

@@ -177,6 +177,79 @@ suite('Insertion marker manager', function () {
const markers = manager.getInsertionMarkers();
chai.assert.equal(markers.length, 2);
});
suite('children being set as insertion markers', function () {
setup(function () {
Blockly.Blocks['shadows_in_init'] = {
init: function () {
this.appendValueInput('test').connection.setShadowState({
'type': 'math_number',
});
this.setPreviousStatement(true);
},
};
Blockly.Blocks['shadows_in_load'] = {
init: function () {
this.appendValueInput('test');
this.setPreviousStatement(true);
},
loadExtraState: function () {
this.getInput('test').connection.setShadowState({
'type': 'math_number',
});
},
saveExtraState: function () {
return true;
},
};
});
teardown(function () {
delete Blockly.Blocks['shadows_in_init'];
delete Blockly.Blocks['shadows_in_load'];
});
test('Shadows added in init are set as insertion markers', function () {
const state = {
'blocks': {
'blocks': [
{
'id': 'first',
'type': 'shadows_in_init',
},
],
},
};
const manager = createBlocksAndManager(this.workspace, state);
const markers = manager.getInsertionMarkers();
chai.assert.isTrue(
markers[0].getChildren()[0].isInsertionMarker(),
'Expected the shadow block to be an insertion maker',
);
});
test('Shadows added in `loadExtraState` are set as insertion markers', function () {
const state = {
'blocks': {
'blocks': [
{
'id': 'first',
'type': 'shadows_in_load',
},
],
},
};
const manager = createBlocksAndManager(this.workspace, state);
const markers = manager.getInsertionMarkers();
chai.assert.isTrue(
markers[0].getChildren()[0].isInsertionMarker(),
'Expected the shadow block to be an insertion maker',
);
});
});
});
suite('Would delete block', function () {