Skip to content

Commit ad3e0f8

Browse files
authored
fix color field dropdown position (microsoft#11487)
1 parent 9dc539e commit ad3e0f8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎pxtblocks/fields/field_colour.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ export class FieldColorNumber extends FieldGridDropdown implements FieldCustom {
201201
return super.getSize();
202202
}
203203

204+
override getScaledBBox(): Blockly.utils.Rect {
205+
// the default implementation of getScaledBBox uses the borderRect_, but we set the
206+
// display of the borderRect_ to none in applyColour when the field is a full block field.
207+
// this implementation comes from getScaledBboxOfBlock in blockly/core/dropdowndiv.ts
208+
if (this.borderRect_?.style?.display === "none") {
209+
const block = this.getSourceBlock() as Blockly.BlockSvg;
210+
211+
const blockSvg = block.getSvgRoot();
212+
const scale = block.workspace.scale;
213+
const scaledHeight = block.height * scale;
214+
const scaledWidth = block.width * scale;
215+
const xy = Blockly.utils.style.getPageOffset(blockSvg);
216+
return new Blockly.utils.Rect(xy.y, xy.y + scaledHeight, xy.x, xy.x + scaledWidth);
217+
}
218+
219+
return super.getScaledBBox();
220+
}
221+
204222
/**
205223
* Updates the colour of the block to reflect whether this is a full
206224
* block field or not.

0 commit comments

Comments
 (0)