Skip to content

Commit

Permalink
fix: select new variable blocks' monitor checkboxes after creation (#140
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gonfunko authored Aug 28, 2024
1 parent ef7911c commit 3811d93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/scratch_continuous_toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import * as Blockly from "blockly/core";
import { ContinuousToolbox } from "@blockly/continuous-toolbox";

export class ScratchContinuousToolbox extends ContinuousToolbox {
postRenderCallbacks = [];

refreshSelection() {
// Intentionally a no-op, Scratch manually manages refreshing the toolbox via forceRerender().
}

forceRerender() {
super.refreshSelection();
let callback;
while ((callback = this.postRenderCallbacks.shift())) {
callback();
}
}

runAfterRerender(callback) {
this.postRenderCallbacks.push(callback);
}
}
4 changes: 2 additions & 2 deletions src/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export function createVariable(workspace, opt_callback, opt_type) {

var flyout = workspace.isFlyout ? workspace : workspace.getFlyout();
var variableBlockId = variable.getId();
if (flyout.setCheckboxState) {
workspace.getToolbox().runAfterRerender(() => {
flyout.setCheckboxState(variableBlockId, true);
}
});

if (opt_callback) {
opt_callback(variableBlockId);
Expand Down

0 comments on commit 3811d93

Please sign in to comment.