mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-09 06:21:59 -05:00
feat: ability to clear flyout blocks when language changes
This commit is contained in:
parent
f930aa61a9
commit
2581446907
3 changed files with 28 additions and 0 deletions
|
@ -831,6 +831,14 @@ class Blocks {
|
||||||
this.emitProjectChanged();
|
this.emitProjectChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all blocks and their associated scripts.
|
||||||
|
*/
|
||||||
|
deleteAllBlocks () {
|
||||||
|
const blockIds = Object.keys(this._blocks);
|
||||||
|
blockIds.forEach(blockId => this.deleteBlock(blockId));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a map of all references to variables or lists from blocks
|
* Returns a map of all references to variables or lists from blocks
|
||||||
* in this block container.
|
* in this block container.
|
||||||
|
|
|
@ -1198,6 +1198,13 @@ class VirtualMachine extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all of the flyout blocks.
|
||||||
|
*/
|
||||||
|
clearFlyoutBlocks () {
|
||||||
|
this.runtime.flyoutBlocks.deleteAllBlocks();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an editing target. An editor UI can use this function to switch
|
* Set an editing target. An editor UI can use this function to switch
|
||||||
* between editing different targets, sprites, etc.
|
* between editing different targets, sprites, etc.
|
||||||
|
|
|
@ -1055,3 +1055,16 @@ test('toJSON encodes Infinity/NaN as 0, not null', t => {
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('clearFlyoutBlocks removes all of the flyout blocks', t => {
|
||||||
|
const vm = new VirtualMachine();
|
||||||
|
const flyoutBlocks = vm.runtime.flyoutBlocks;
|
||||||
|
|
||||||
|
flyoutBlocks.createBlock(adapter(events.mockVariableBlock)[0]);
|
||||||
|
t.equal(Object.keys(flyoutBlocks._blocks).length, 1);
|
||||||
|
|
||||||
|
vm.clearFlyoutBlocks();
|
||||||
|
t.equal(Object.keys(flyoutBlocks._blocks).length, 0);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue