File tree 2 files changed +41
-2
lines changed
2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -1408,13 +1408,13 @@ class Runtime extends EventEmitter {
1408
1408
if ( ! blockInfo . disableMonitor && context . inputList . length === 0 ) {
1409
1409
blockJSON . checkboxInFlyout = true ;
1410
1410
}
1411
- } else if ( blockInfo . blockType === BlockType . LOOP ) {
1411
+ } else if ( blockInfo . blockType === BlockType . LOOP || blockInfo . branchIconURI ) {
1412
1412
// Add icon to the bottom right of a loop block
1413
1413
blockJSON [ `lastDummyAlign${ outLineNum } ` ] = 'RIGHT' ;
1414
1414
blockJSON [ `message${ outLineNum } ` ] = '%1' ;
1415
1415
blockJSON [ `args${ outLineNum } ` ] = [ {
1416
1416
type : 'field_image' ,
1417
- src : './static/blocks-media/repeat.svg' , // TODO: use a constant or make this configurable?
1417
+ src : blockInfo . branchIconURI || './static/blocks-media/repeat.svg' ,
1418
1418
width : 24 ,
1419
1419
height : 24 ,
1420
1420
alt : '*' , // TODO remove this since we don't use collapsed blocks in scratch
Original file line number Diff line number Diff line change
1
+ const { test} = require ( 'tap' ) ;
2
+ const VirtualMachine = require ( '../../src/virtual-machine' ) ;
3
+ const BlockType = require ( '../../src/extension-support/block-type' ) ;
4
+
5
+ test ( 'branchIconURI' , t => {
6
+ const vm = new VirtualMachine ( ) ;
7
+ vm . extensionManager . _registerInternalExtension ( {
8
+ getInfo : ( ) => ( {
9
+ id : 'testextension' ,
10
+ name : 'test' ,
11
+ blocks : [
12
+ {
13
+ blockType : BlockType . LOOP ,
14
+ opcode : 'block1' ,
15
+ text : 'no custom icon'
16
+ } ,
17
+ {
18
+ blockType : BlockType . LOOP ,
19
+ opcode : 'block2' ,
20
+ text : 'LOOP with custom icon' ,
21
+ branchIconURI : 'data:whatever1'
22
+ } ,
23
+ {
24
+ blockType : BlockType . CONDITIONAL ,
25
+ opcode : 'block2' ,
26
+ text : 'CONDITIONAL with custom icon' ,
27
+ branchIconURI : 'data:whatever2'
28
+ }
29
+ ]
30
+ } )
31
+ } ) ;
32
+
33
+ const blocks = vm . runtime . getBlocksJSON ( ) ;
34
+ t . equal ( blocks [ 0 ] . args2 [ 0 ] . src , './static/blocks-media/repeat.svg' , 'default custom icon' ) ;
35
+ t . equal ( blocks [ 1 ] . args2 [ 0 ] . src , 'data:whatever1' , 'LOOP with custom icon' ) ;
36
+ t . equal ( blocks [ 2 ] . args2 [ 0 ] . src , 'data:whatever2' , 'CONDITIONAL with custom icon' ) ;
37
+
38
+ t . end ( ) ;
39
+ } ) ;
You can’t perform that action at this time.
0 commit comments