File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -951,17 +951,20 @@ export class BlockSvg
951951 /**
952952 * Encode a block for copying.
953953 *
954+ * @param addNextBlocks If true, copy subsequent blocks attached to this one
955+ * as well.
956+ *
954957 * @returns Copy metadata, or null if the block is an insertion marker.
955958 */
956- toCopyData ( ) : BlockCopyData | null {
959+ toCopyData ( addNextBlocks = false ) : BlockCopyData | null {
957960 if ( this . isInsertionMarker_ ) {
958961 return null ;
959962 }
960963 return {
961964 paster : BlockPaster . TYPE ,
962965 blockState : blocks . save ( this , {
963966 addCoordinates : true ,
964- addNextBlocks : false ,
967+ addNextBlocks,
965968 saveIds : false ,
966969 } ) as blocks . State ,
967970 typeCounts : common . getBlockTypeCounts ( this , true ) ,
Original file line number Diff line number Diff line change @@ -61,6 +61,31 @@ suite('Clipboard', function () {
6161 ) ;
6262 } ) ;
6363
64+ test ( 'pasting blocks includes next blocks if requested' , function ( ) {
65+ const block = Blockly . serialization . blocks . append (
66+ {
67+ 'type' : 'controls_if' ,
68+ 'id' : 'blockId' ,
69+ 'next' : {
70+ 'block' : {
71+ 'type' : 'controls_if' ,
72+ 'id' : 'blockId2' ,
73+ } ,
74+ } ,
75+ } ,
76+ this . workspace ,
77+ ) ;
78+ assert . equal ( this . workspace . getBlocksByType ( 'controls_if' ) . length , 2 ) ;
79+ // Both blocks should be copied
80+ const data = block . toCopyData ( true ) ;
81+ this . clock . runAll ( ) ;
82+
83+ Blockly . clipboard . paste ( data , this . workspace ) ;
84+ this . clock . runAll ( ) ;
85+ // After pasting, we should have gone from 2 to 4 blocks.
86+ assert . equal ( this . workspace . getBlocksByType ( 'controls_if' ) . length , 4 ) ;
87+ } ) ;
88+
6489 test ( 'copied from a mutator pastes them into the mutator' , async function ( ) {
6590 const block = Blockly . serialization . blocks . append (
6691 {
You can’t perform that action at this time.
0 commit comments