From cfa198c6a0ac5b1762d5ce7698a809fbbd4f9c78 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Fri, 17 Apr 2020 13:19:40 -0700 Subject: [PATCH] Fix bug with dropdown divs in mutator dialogs. (#3835) --- core/dropdowndiv.js | 8 +++-- tests/blocks/test_blocks.js | 70 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index 4c8c3fe2a..7add63838 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -303,9 +303,13 @@ Blockly.DropDownDiv.showPositionedByRect_ = function(bBox, field, secondaryY += opt_secondaryYOffset; } var sourceBlock = field.getSourceBlock(); - // Set bounds to workspace; show the drop-down. + // Set bounds to main workspace; show the drop-down. + var workspace = sourceBlock.workspace; + while (workspace.options.parentWorkspace) { + workspace = workspace.options.parentWorkspace; + } Blockly.DropDownDiv.setBoundsElement( - sourceBlock.workspace.getParentSvg().parentNode); + workspace.getParentSvg().parentNode); return Blockly.DropDownDiv.show( field, sourceBlock.RTL, primaryX, primaryY, secondaryX, secondaryY, opt_onHide); diff --git a/tests/blocks/test_blocks.js b/tests/blocks/test_blocks.js index 0bb9036b6..11247c6b4 100644 --- a/tests/blocks/test_blocks.js +++ b/tests/blocks/test_blocks.js @@ -657,6 +657,25 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT } ] }, + { + "type": "test_dropdowns_in_mutator", + "message0": "dropdown mutator", + "mutator": "test_dropdown_mutator" + }, + { + "type": "test_dropdowns_in_mutator_block", + "message0": "dropdown %1", + "args0": [ + { + "type": "field_dropdown", + "name": "DROPDOWN", + "options": [ + [ "option", "ONE" ], + [ "option", "TWO" ] + ] + }, + ] + }, { "type": "test_fields_angle", "message0": "angle: %1", @@ -1818,6 +1837,57 @@ Blockly.Blocks['test_dropdowns_dynamic_random'] = { } }; +/** + * Mutator methods added to the test_dropdowns_in_mutator block. + * @mixin + * @augments Blockly.Block + * @package + * @readonly + */ +var DROPDOWN_MUTATOR = { + /** + * Create XML to represent the block mutation. + * @return {Element} XML storage element. + * @this {Blockly.Block} + */ + mutationToDom: function() { + var container = Blockly.utils.xml.createElement('mutation'); + return container; + }, + /** + * Restore a block from XML. + * @param {!Element} _xmlElement XML storage element. + * @this {Blockly.Block} + */ + domToMutation: function(_xmlElement) { + }, + /** + * Populate the mutator's dialog with this block's components. + * @param {!Blockly.Workspace} workspace Mutator's workspace. + * @return {!Blockly.Block} Root block in mutator. + * @this {Blockly.Block} + */ + decompose: function(workspace) { + var containerBlock = workspace.newBlock('test_dropdowns_in_mutator_block'); + containerBlock.initSvg(); + + return containerBlock; + }, + /** + * Reconfigure this block based on the mutator dialog's components. + * @param {!Blockly.Block} _containerBlock Root block in mutator. + * @this {Blockly.Block} + */ + compose: function(_containerBlock) { + }, +}; + +/** + * Register custom mutator used by the test_dropdowns_in_mutator block. + */ +Blockly.Extensions.registerMutator('test_dropdown_mutator', + DROPDOWN_MUTATOR, null, ['test_dropdowns_in_mutator_block']); + /** * Handles "insert" button in the connection row test category. This will insert * a group of test blocks connected in a row.