Skip to content

Commit

Permalink
fix: group context menu collapse blocks events (google#5501)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaimio authored Oct 18, 2021
1 parent 063c8ad commit d71b9c6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/contextmenu_items.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
goog.module('Blockly.ContextMenuItems');

const ContextMenuRegistry = goog.require('Blockly.ContextMenuRegistry');
const Events = goog.require('Blockly.Events');
const Msg = goog.require('Blockly.Msg');
/* eslint-disable-next-line no-unused-vars */
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
Expand Down Expand Up @@ -128,10 +129,20 @@ exports.registerCleanup = registerCleanup;
const toggleOption_ = function(shouldCollapse, topBlocks) {
const DELAY = 10;
let ms = 0;
let timeoutCounter = 0;
const timeoutFn = function(block) {
timeoutCounter--;
block.setCollapsed(shouldCollapse);
if (timeoutCounter === 0) {
Events.setGroup(false);
}
};
Events.setGroup(true);
for (let i = 0; i < topBlocks.length; i++) {
let block = topBlocks[i];
while (block) {
setTimeout(block.setCollapsed.bind(block, shouldCollapse), ms);
timeoutCounter++;
setTimeout(timeoutFn.bind(null, block), ms);
block = block.getNextBlock();
ms += DELAY;
}
Expand Down

0 comments on commit d71b9c6

Please sign in to comment.