From 40c6d9c490a18a5efa5c232b1894d420efba15d6 Mon Sep 17 00:00:00 2001 From: John Nesky Date: Mon, 22 Jul 2024 09:21:51 -0700 Subject: [PATCH] fix: Enable blocks if user can't manually enable them. (#8354) * fix: Enable blocks if user can't manually enable them. * Only change the affected test method. --- core/block.ts | 19 +++++++++++++++++++ tests/mocha/blocks/procedures_test.js | 1 + 2 files changed, 20 insertions(+) diff --git a/core/block.ts b/core/block.ts index 52191d63c..6a911d557 100644 --- a/core/block.ts +++ b/core/block.ts @@ -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); diff --git a/tests/mocha/blocks/procedures_test.js b/tests/mocha/blocks/procedures_test.js index 684237006..600aefa6a 100644 --- a/tests/mocha/blocks/procedures_test.js +++ b/tests/mocha/blocks/procedures_test.js @@ -862,6 +862,7 @@ suite('Procedures', function () { 'if a procedure caller block was already disabled before ' + 'its definition was disabled, it is not reenabled', function () { + this.workspace.options.disable = true; const defBlock = createProcDefBlock(this.workspace); const callBlock = createProcCallBlock(this.workspace); this.clock.runAll();