diff --git a/plugins/workspace-minimap/src/focus_region.ts b/plugins/workspace-minimap/src/focus_region.ts index 70b5b6fba..82ec22514 100644 --- a/plugins/workspace-minimap/src/focus_region.ts +++ b/plugins/workspace-minimap/src/focus_region.ts @@ -19,6 +19,7 @@ const blockEvents = new Set([ Blockly.Events.BLOCK_DELETE, Blockly.Events.BLOCK_DRAG, Blockly.Events.BLOCK_MOVE, + Blockly.Events.VAR_RENAME, ]); const borderRadius = 6; diff --git a/plugins/workspace-minimap/src/minimap.ts b/plugins/workspace-minimap/src/minimap.ts index 953b0a76d..d38b0555b 100644 --- a/plugins/workspace-minimap/src/minimap.ts +++ b/plugins/workspace-minimap/src/minimap.ts @@ -21,6 +21,9 @@ const blockEvents = new Set([ Blockly.Events.BLOCK_DELETE, Blockly.Events.BLOCK_DRAG, Blockly.Events.BLOCK_MOVE, + Blockly.Events.VAR_CREATE, + Blockly.Events.VAR_DELETE, + Blockly.Events.VAR_RENAME, ]); /** Default primary-workspace pixels to pan per arrow keypress. */ diff --git a/plugins/workspace-minimap/test/minimap_tests.mocha.js b/plugins/workspace-minimap/test/minimap_tests.mocha.js index a40b9523b..b876b36f5 100644 --- a/plugins/workspace-minimap/test/minimap_tests.mocha.js +++ b/plugins/workspace-minimap/test/minimap_tests.mocha.js @@ -435,6 +435,45 @@ suite('Positioning the minimap in the primary workspace', function () { }); }); +suite('Mirroring events', function () { + setup(function () { + this.jsdomCleanup = require('jsdom-global')( + '
', + ); + global.SVGElement = window.SVGElement; + window.requestAnimationFrame = (callback) => setTimeout(callback, 0); + window.cancelAnimationFrame = (id) => clearTimeout(id); + this.workspace = Blockly.inject('blocklyDiv', { + move: {scrollbars: true}, + }); + this.minimap = new Minimap(this.workspace); + this.minimap.init(); + }); + + teardown(function () { + this.minimap.dispose(); + this.workspace.dispose(); + this.jsdomCleanup(); + }); + + test('Renaming a variable updates the minimap', async function () { + const variable = this.workspace.getVariableMap().createVariable('a'); + const block = this.workspace.newBlock('variables_set'); + block.getField('VAR').setValue(variable.getId()); + await new Promise((resolve) => setTimeout(resolve, 0)); + + this.workspace.getVariableMap().renameVariable(variable, 'b'); + await new Promise((resolve) => setTimeout(resolve, 0)); + + const minimapBlock = this.minimap.minimapWorkspace.getBlockById(block.id); + assert.equal( + minimapBlock.getField('VAR').getText(), + 'b', + 'Minimap block should show the renamed variable', + ); + }); +}); + suite('Keyboard navigation', function () { setup(function () { this.jsdomCleanup = require('jsdom-global')(