diff --git a/src/block_reporting.js b/src/block_reporting.js index 6950d57175..3cd2854cfd 100644 --- a/src/block_reporting.js +++ b/src/block_reporting.js @@ -7,7 +7,16 @@ export function reportValue(id, value) { if (!block) { throw 'Tried to report value on block that does not exist.'; } - const field = block.inputList[0].fieldRow[0]; + + let field; + for (const input of block.inputList) { + for (const f of input.fieldRow) { + field = f; + break; + } + } + if (!field) return; + const contentDiv = Blockly.DropDownDiv.getContentDiv(); const valueReportBox = document.createElement('div'); valueReportBox.setAttribute('class', 'valueReportBox'); diff --git a/src/checkable_continuous_flyout.js b/src/checkable_continuous_flyout.js index f67833ab0d..f14d9047d9 100644 --- a/src/checkable_continuous_flyout.js +++ b/src/checkable_continuous_flyout.js @@ -218,4 +218,12 @@ export class CheckableContinuousFlyout extends ContinuousFlyout { getFlyoutScale() { return 0.675; } + + blockIsRecyclable_(block) { + const recyclable = super.blockIsRecyclable_(block); + // Exclude blocks with output connections, because they are able to report their current + // value in a popover and recycling them interacts poorly with the VM's maintenance of its + // state. + return recyclable && !block.outputConnection; + } } diff --git a/src/index.js b/src/index.js index e9fba0444f..7170893fef 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,7 @@ import { ContinuousMetrics, } from '@blockly/continuous-toolbox'; import {CheckableContinuousFlyout} from './checkable_continuous_flyout.js'; +import {ScratchContinuousToolbox} from './scratch_continuous_toolbox.js'; import {buildGlowFilter, glowStack} from './glows.js'; import './scratch_continuous_category.js'; @@ -51,7 +52,7 @@ export {CheckableContinuousFlyout}; export function inject(container, options) { Object.assign(options, { plugins: { - toolbox: ContinuousToolbox, + toolbox: ScratchContinuousToolbox, flyoutsVerticalToolbox: CheckableContinuousFlyout, metricsManager: ContinuousMetrics, }, diff --git a/src/scratch_continuous_toolbox.js b/src/scratch_continuous_toolbox.js new file mode 100644 index 0000000000..0be28b0a95 --- /dev/null +++ b/src/scratch_continuous_toolbox.js @@ -0,0 +1,12 @@ +import * as Blockly from 'blockly/core'; +import {ContinuousToolbox} from '@blockly/continuous-toolbox'; + +export class ScratchContinuousToolbox extends ContinuousToolbox { + refreshSelection() { + // Intentionally a no-op, Scratch manually manages refreshing the toolbox via forceRerender(). + } + + forceRerender() { + super.refreshSelection(); + } +}