Skip to content

Commit

Permalink
fix: Enable blocks if user can't manually enable them.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnesky committed Jul 18, 2024
1 parent f8025a1 commit ca23567
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,25 @@ export class Block implements IASTNodeLocation {
* update whether the block is currently disabled for this reason.
*/
setDisabledReason(disabled: boolean, reason: string): void {
// Workspaces that were serialized before the reason for being disabled
// could be specified may have blocks that are disabled without a known
// reason. On being loaded, these blocks will default to having the manually
// disabled reason. However, if the user isn't allowed to manually disable
// or enable blocks, then this manually disabled reason cannot be removed.
// For backward compatibility with these legacy workspaces, when removing
// any disabled reason and the workspace does not allow manually disabling
// but the block is manually disabled, then remove the manually disabled
// reason in addition to the more specific reason. For example, when an
// orphaned block is no longer orphaned, the block should be enabled again.
if (
!disabled &&
!this.workspace.options.disable &&
this.hasDisabledReason(constants.MANUALLY_DISABLED) &&
reason != constants.MANUALLY_DISABLED
) {
this.setDisabledReason(false, constants.MANUALLY_DISABLED);
}

if (this.disabledReasons.has(reason) !== disabled) {
if (disabled) {
this.disabledReasons.add(reason);
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/blocks/procedures_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {defineRowBlock} from '../test_helpers/block_definitions.js';
suite('Procedures', function () {
setup(function () {
sharedTestSetup.call(this, {fireEventsNow: false});
this.workspace = Blockly.inject('blocklyDiv', {});
this.workspace = Blockly.inject('blocklyDiv', {disable: true});
this.workspace.createVariable('preCreatedVar', '', 'preCreatedVarId');
this.workspace.createVariable(
'preCreatedTypedVar',
Expand Down

0 comments on commit ca23567

Please sign in to comment.