@@ -1103,27 +1103,6 @@ Blockly.BlockSvg.prototype.renderCompute_ = function(iconWidth) {
11031103 previousRow = row ;
11041104 }
11051105
1106- // fix incorrect width calculations for mega-chin blocks
1107- // ie, C- or E- shaped blocks with labels and/or inputs on the end branch
1108- if ( hasStatement ) {
1109- // the mega-chin block issue only happens to blocks with images
1110- const input = inputList [ inputList . length - 1 ] ;
1111- const field = input . fieldRow [ 0 ] ;
1112- if ( field instanceof Blockly . FieldImage ) {
1113- // check for inputs before the last branch
1114- const measureables = [ ] ;
1115- for ( var i = inputList . length - 1 ; i -- ; ) {
1116- if ( inputList [ i ] . type == Blockly . NEXT_STATEMENT ) break ;
1117- measureables . push ( inputList [ i ] ) ;
1118- }
1119-
1120- if ( measureables . length ) {
1121- const newWidth = measureables . reduce ( ( w , input ) => w + ( input . fieldWidth ) , 0 ) ;
1122- input . fieldWidth = newWidth * ( Blockly . BlockSvg . BOX_FIELD_PADDING / 4 ) ;
1123- }
1124- }
1125- }
1126-
11271106 // Compute padding for output blocks.
11281107 // Data is attached to the row.
11291108 this . computeOutputPadding_ ( inputRows ) ;
@@ -2134,8 +2113,32 @@ Blockly.BlockSvg.getInputShapeInfo_ = function(shape) {
21342113Blockly . BlockSvg . getAlignedCursor_ = function ( cursorX , input , rightEdge ) {
21352114 // Align inline field rows (left/right/centre).
21362115 if ( input . align === Blockly . ALIGN_RIGHT ) {
2137- cursorX += rightEdge - input . fieldWidth -
2138- ( 2 * Blockly . BlockSvg . SEP_SPACE_X ) ;
2116+ const SEP_SPACE = 2 * Blockly . BlockSvg . SEP_SPACE_X ;
2117+ const offsetAmt = rightEdge - input . fieldWidth - SEP_SPACE ;
2118+ cursorX += offsetAmt ;
2119+
2120+ // fix incorrect width calculations for mega-chin blocks
2121+ // ie, branched blocks with labels and/or inputs on the end branch
2122+ const srcInputList = input . sourceBlock_ . inputList ;
2123+ const inputIndex = srcInputList . indexOf ( input ) ;
2124+ const lastBranchIndex = srcInputList . findLastIndex ( ( i ) => i . type === Blockly . NEXT_STATEMENT ) ;
2125+ const subInputs = srcInputList . slice ( lastBranchIndex + 1 , inputIndex ) ;
2126+
2127+ if ( subInputs . length ) {
2128+ // measure the widths of the fields in the block row and subtract it
2129+ // from cursorX. Without this, the row width will be doubled.
2130+ const backOffset = subInputs . reduce ( ( acc , cur ) => {
2131+ let amt = cur . fieldWidth ;
2132+ if ( cur . connection ) {
2133+ const block = cur . connection . targetBlock ( ) ;
2134+ if ( block ) amt += block . width + SEP_SPACE ;
2135+ else amt += Blockly . BlockSvg . INPUT_AND_FIELD_MIN_X + SEP_SPACE ;
2136+ }
2137+ return acc + amt ;
2138+ } , 0 ) ;
2139+
2140+ cursorX -= Math . min ( backOffset , offsetAmt ) ;
2141+ }
21392142 } else if ( input . align === Blockly . ALIGN_CENTRE ) {
21402143 cursorX = Math . max ( cursorX , rightEdge / 2 - input . fieldWidth / 2 ) ;
21412144 }
0 commit comments