GeezerVison is showing github.com — fix: improve reliability of block value reporting (#77) · scratchfoundation/scratch-blocks@cb5b068
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/block_reporting.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,16 @@ export function reportValue(id, value) { |
7 | 7 | if (!block) { |
8 | 8 | throw 'Tried to report value on block that does not exist.'; |
9 | 9 | } |
10 | | - const field = block.inputList[0].fieldRow[0]; |
| 10 | + |
| 11 | + let field; |
| 12 | + for (const input of block.inputList) { |
| 13 | + for (const f of input.fieldRow) { |
| 14 | + field = f; |
| 15 | + break; |
| 16 | + } |
| 17 | + } |
| 18 | + if (!field) return; |
| 19 | + |
11 | 20 | const contentDiv = Blockly.DropDownDiv.getContentDiv(); |
12 | 21 | const valueReportBox = document.createElement('div'); |
13 | 22 | valueReportBox.setAttribute('class', 'valueReportBox'); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/checkable_continuous_flyout.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -218,4 +218,12 @@ export class CheckableContinuousFlyout extends ContinuousFlyout { |
218 | 218 | getFlyoutScale() { |
219 | 219 | return 0.675; |
220 | 220 | } |
| 221 | + |
| 222 | + blockIsRecyclable_(block) { |
| 223 | + const recyclable = super.blockIsRecyclable_(block); |
| 224 | + // Exclude blocks with output connections, because they are able to report their current |
| 225 | + // value in a popover and recycling them interacts poorly with the VM's maintenance of its |
| 226 | + // state. |
| 227 | + return recyclable && !block.outputConnection; |
| 228 | + } |
221 | 229 | } |
Collapse file
Copy file name to clipboardExpand all lines: src/index.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,7 @@ import { |
31 | 31 | ContinuousMetrics, |
32 | 32 | } from '@blockly/continuous-toolbox'; |
33 | 33 | import {CheckableContinuousFlyout} from './checkable_continuous_flyout.js'; |
| 34 | +import {ScratchContinuousToolbox} from './scratch_continuous_toolbox.js'; |
34 | 35 | import {buildGlowFilter, glowStack} from './glows.js'; |
35 | 36 | import './scratch_continuous_category.js'; |
36 | 37 |
|
@@ -51,7 +52,7 @@ export {CheckableContinuousFlyout}; |
51 | 52 | export function inject(container, options) { |
52 | 53 | Object.assign(options, { |
53 | 54 | plugins: { |
54 | | - toolbox: ContinuousToolbox, |
| 55 | + toolbox: ScratchContinuousToolbox, |
55 | 56 | flyoutsVerticalToolbox: CheckableContinuousFlyout, |
56 | 57 | metricsManager: ContinuousMetrics, |
57 | 58 | }, |
|
Collapse file
Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import * as Blockly from 'blockly/core'; |
| 2 | +import {ContinuousToolbox} from '@blockly/continuous-toolbox'; |
| 3 | + |
| 4 | +export class ScratchContinuousToolbox extends ContinuousToolbox { |
| 5 | + refreshSelection() { |
| 6 | + // Intentionally a no-op, Scratch manually manages refreshing the toolbox via forceRerender(). |
| 7 | + } |
| 8 | + |
| 9 | + forceRerender() { |
| 10 | + super.refreshSelection(); |
| 11 | + } |
| 12 | +} |