MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / toggleOption_

Function toggleOption_

packages/blockly/core/contextmenu_items.ts:118–139  ·  view source on GitHub ↗

* Creates a callback to collapse or expand top blocks. * * @param shouldCollapse Whether a block should collapse. * @param topBlocks Top blocks in the workspace.

(shouldCollapse: boolean, topBlocks: BlockSvg[])

Source from the content-addressed store, hash-verified

116 * @param topBlocks Top blocks in the workspace.
117 */
118function toggleOption_(shouldCollapse: boolean, topBlocks: BlockSvg[]) {
119 const DELAY = 10;
120 let ms = 0;
121 let timeoutCounter = 0;
122 function timeoutFn(block: BlockSvg) {
123 timeoutCounter--;
124 block.setCollapsed(shouldCollapse);
125 if (timeoutCounter === 0) {
126 Events.setGroup(false);
127 }
128 }
129 Events.setGroup(true);
130 for (let i = 0; i < topBlocks.length; i++) {
131 let block: BlockSvg | null = topBlocks[i];
132 while (block) {
133 timeoutCounter++;
134 setTimeout(timeoutFn.bind(null, block), ms);
135 block = block.getNextBlock();
136 ms += DELAY;
137 }
138 }
139}
140
141/**
142 * Option to collapse all blocks.

Callers 1

callbackFunction · 0.85

Calls 1

getNextBlockMethod · 0.45

Tested by

no test coverage detected