@@ -145,7 +145,8 @@ class Blocks extends React.Component { |
145 | 145 | "PROCEDURE", |
146 | 146 | this.ScratchBlocks.ScratchProcedures.getProceduresCategory |
147 | 147 | ); |
148 | | - this.workspace.addChangeListener((event) => { |
| 148 | + |
| 149 | + this.toolboxUpdateChangeListener = (event) => { |
149 | 150 | if ( |
150 | 151 | event.type === this.ScratchBlocks.Events.VAR_CREATE || |
151 | 152 | event.type === this.ScratchBlocks.Events.VAR_RENAME || |
@@ -161,7 +162,8 @@ class Blocks extends React.Component { |
161 | 162 | ) { |
162 | 163 | this.requestToolboxUpdate(); |
163 | 164 | } |
164 | | - }); |
| 165 | + }; |
| 166 | + this.workspace.addChangeListener(this.toolboxUpdateChangeListener); |
165 | 167 |
|
166 | 168 | // Register buttons under new callback keys for creating variables, |
167 | 169 | // lists, and procedures from extensions. |
@@ -515,6 +517,7 @@ class Blocks extends React.Component { |
515 | 517 |
|
516 | 518 | // Remove and reattach the workspace listener (but allow flyout events) |
517 | 519 | this.workspace.removeChangeListener(this.props.vm.blockListener); |
| 520 | + this.workspace.removeChangeListener(this.toolboxUpdateChangeListener); |
518 | 521 | const dom = this.ScratchBlocks.utils.xml.textToDom(data.xml); |
519 | 522 | try { |
520 | 523 | this.ScratchBlocks.Xml.clearWorkspaceAndLoadFromXml( |
@@ -556,6 +559,15 @@ class Blocks extends React.Component { |
556 | 559 | // fresh workspace and we don't want any changes made to another sprites |
557 | 560 | // workspace to be 'undone' here. |
558 | 561 | this.workspace.clearUndo(); |
| 562 | + // Let events get flushed before readding the toolbox-updater listener |
| 563 | + // to avoid unneeded refreshes. |
| 564 | + requestAnimationFrame(() => { |
| 565 | + setTimeout(() => { |
| 566 | + this.workspace.addChangeListener( |
| 567 | + this.toolboxUpdateChangeListener |
| 568 | + ); |
| 569 | + }); |
| 570 | + }); |
559 | 571 | } |
560 | 572 | handleMonitorsUpdate(monitors) { |
561 | 573 | // Update the checkboxes of the relevant monitors. |
|