Skip to content

Commit

Permalink
fix: shadows in insertion markers being displayed as shadows (#7609)
Browse files Browse the repository at this point in the history
* fix: shadows in insertion markers being displayed as shadows

* chore: add unit tests

* chore: remove only
  • Loading branch information
BeksOmega authored Nov 3, 2023
1 parent 9d11767 commit 0ad57f4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/insertion_marker_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
73 changes: 73 additions & 0 deletions tests/mocha/insertion_marker_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 0ad57f4

Please sign in to comment.