Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve reliability of block value reporting #77

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/block_reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions src/checkable_continuous_flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
gonfunko marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -51,7 +52,7 @@ export {CheckableContinuousFlyout};
export function inject(container, options) {
Object.assign(options, {
plugins: {
toolbox: ContinuousToolbox,
toolbox: ScratchContinuousToolbox,
flyoutsVerticalToolbox: CheckableContinuousFlyout,
metricsManager: ContinuousMetrics,
},
Expand Down
12 changes: 12 additions & 0 deletions src/scratch_continuous_toolbox.js
Original file line number Diff line number Diff line change
@@ -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() {
gonfunko marked this conversation as resolved.
Show resolved Hide resolved
super.refreshSelection();
}
}