mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-13 17:04:39 -04:00
Merge pull request #2045 from paulkaplan/fix-adding-custom-input
Allow for situation where we get a move event to attach a shadow.
This commit is contained in:
commit
8d4be4eec5
2 changed files with 43 additions and 0 deletions
|
@ -735,6 +735,12 @@ class Blocks {
|
|||
if (this._blocks[e.newParent].inputs.hasOwnProperty(e.newInput)) {
|
||||
oldShadow = this._blocks[e.newParent].inputs[e.newInput].shadow;
|
||||
}
|
||||
|
||||
// If the block being attached is itself a shadow, make sure to set
|
||||
// both block and shadow to that blocks ID. This happens when adding
|
||||
// inputs to a custom procedure.
|
||||
if (this._blocks[e.id].shadow) oldShadow = e.id;
|
||||
|
||||
this._blocks[e.newParent].inputs[e.newInput] = {
|
||||
name: e.newInput,
|
||||
block: e.id,
|
||||
|
|
|
@ -358,6 +358,43 @@ test('move no obscure shadow', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('move - attaching new shadow', t => {
|
||||
const b = new Blocks(new Runtime());
|
||||
// Block/shadow are null to mimic state right after a procedure_call block
|
||||
// is mutated by adding an input. The "move" will attach the new shadow.
|
||||
b.createBlock({
|
||||
id: 'foo',
|
||||
opcode: 'TEST_BLOCK',
|
||||
next: null,
|
||||
fields: {},
|
||||
inputs: {
|
||||
fooInput: {
|
||||
name: 'fooInput',
|
||||
block: null,
|
||||
shadow: null
|
||||
}
|
||||
},
|
||||
topLevel: true
|
||||
});
|
||||
b.createBlock({
|
||||
id: 'bar',
|
||||
opcode: 'TEST_BLOCK',
|
||||
shadow: true,
|
||||
next: null,
|
||||
fields: {},
|
||||
inputs: {},
|
||||
topLevel: true
|
||||
});
|
||||
b.moveBlock({
|
||||
id: 'bar',
|
||||
newInput: 'fooInput',
|
||||
newParent: 'foo'
|
||||
});
|
||||
t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');
|
||||
t.equal(b._blocks.foo.inputs.fooInput.shadow, 'bar');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('change', t => {
|
||||
const b = new Blocks(new Runtime());
|
||||
b.createBlock({
|
||||
|
|
Loading…
Reference in a new issue