GeezerVison is showing github.com — fix: select new variable blocks' monitor checkboxes after creation (#… · SnoopyMod/scratch-blocks@3811d93
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/scratch_continuous_toolbox.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,11 +2,21 @@ import * as Blockly from "blockly/core"; |
2 | 2 | import { ContinuousToolbox } from "@blockly/continuous-toolbox"; |
3 | 3 |
|
4 | 4 | export class ScratchContinuousToolbox extends ContinuousToolbox { |
| 5 | + postRenderCallbacks = []; |
| 6 | + |
5 | 7 | refreshSelection() { |
6 | 8 | // Intentionally a no-op, Scratch manually manages refreshing the toolbox via forceRerender(). |
7 | 9 | } |
8 | 10 |
|
9 | 11 | forceRerender() { |
10 | 12 | super.refreshSelection(); |
| 13 | + let callback; |
| 14 | + while ((callback = this.postRenderCallbacks.shift())) { |
| 15 | + callback(); |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + runAfterRerender(callback) { |
| 20 | + this.postRenderCallbacks.push(callback); |
11 | 21 | } |
12 | 22 | } |
Collapse file
Copy file name to clipboardExpand all lines: src/variables.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -117,9 +117,9 @@ export function createVariable(workspace, opt_callback, opt_type) { |
117 | 117 |
|
118 | 118 | var flyout = workspace.isFlyout ? workspace : workspace.getFlyout(); |
119 | 119 | var variableBlockId = variable.getId(); |
120 | | - if (flyout.setCheckboxState) { |
| 120 | + workspace.getToolbox().runAfterRerender(() => { |
121 | 121 | flyout.setCheckboxState(variableBlockId, true); |
122 | | - } |
| 122 | + }); |
123 | 123 |
|
124 | 124 | if (opt_callback) { |
125 | 125 | opt_callback(variableBlockId); |
|