Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,17 +951,20 @@ export class BlockSvg
/**
* Encode a block for copying.
*
* @param addNextBlocks If true, copy subsequent blocks attached to this one
* as well.
*
* @returns Copy metadata, or null if the block is an insertion marker.
*/
toCopyData(): BlockCopyData | null {
toCopyData(addNextBlocks = false): BlockCopyData | null {
if (this.isInsertionMarker_) {
return null;
}
return {
paster: BlockPaster.TYPE,
blockState: blocks.save(this, {
addCoordinates: true,
addNextBlocks: false,
addNextBlocks,
saveIds: false,
}) as blocks.State,
typeCounts: common.getBlockTypeCounts(this, true),
Expand Down
25 changes: 25 additions & 0 deletions tests/mocha/clipboard_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ suite('Clipboard', function () {
);
});

test('pasting blocks includes next blocks if requested', function () {
const block = Blockly.serialization.blocks.append(
{
'type': 'controls_if',
'id': 'blockId',
'next': {
'block': {
'type': 'controls_if',
'id': 'blockId2',
},
},
},
this.workspace,
);
assert.equal(this.workspace.getBlocksByType('controls_if').length, 2);
// Both blocks should be copied
const data = block.toCopyData(true);
this.clock.runAll();

Blockly.clipboard.paste(data, this.workspace);
this.clock.runAll();
// After pasting, we should have gone from 2 to 4 blocks.
assert.equal(this.workspace.getBlocksByType('controls_if').length, 4);
});

test('copied from a mutator pastes them into the mutator', async function () {
const block = Blockly.serialization.blocks.append(
{
Expand Down
Loading