From a538e7e454ec56f631e3cc3310a7359838f0b56f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 8 Nov 2024 13:34:47 -0800 Subject: [PATCH] refactor: Make the RecyclableBlockFlyoutInflater inert for non-continuous flyouts. --- .../src/ContinuousFlyout.ts | 27 ++++++++++++------- .../src/RecyclableBlockFlyoutInflater.ts | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/continuous-toolbox/src/ContinuousFlyout.ts b/plugins/continuous-toolbox/src/ContinuousFlyout.ts index d65a0ba00..76197d649 100644 --- a/plugins/continuous-toolbox/src/ContinuousFlyout.ts +++ b/plugins/continuous-toolbox/src/ContinuousFlyout.ts @@ -56,6 +56,8 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout { this.selectCategoryByScrollPosition(-this.getWorkspace().scrollY); } }); + + this.setRecyclingEnabled(true); } /** @@ -234,10 +236,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout { if (!this.getParentToolbox().getSelectedItem()) { this.selectCategoryByScrollPosition(0); } - const inflater = this.getInflaterForType('block'); - if (inflater instanceof RecyclableBlockFlyoutInflater) { - inflater.emptyRecycledBlocks(); - } + this.getRecyclableInflater().emptyRecycledBlocks(); } /** @@ -246,10 +245,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout { * @param func The function used to determine if a block is recyclable. */ setBlockIsRecyclable(func: (block: Blockly.Block) => boolean) { - const inflater = this.getInflaterForType('block'); - if (inflater instanceof RecyclableBlockFlyoutInflater) { - inflater.setRecyclingEligibilityChecker(func); - } + this.getRecyclableInflater().setRecyclingEligibilityChecker(func); } /** @@ -258,9 +254,20 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout { * @param isEnabled True to allow blocks to be recycled, false otherwise. */ setRecyclingEnabled(isEnabled: boolean) { + this.getRecyclableInflater().setRecyclingEnabled(isEnabled); + } + + /** + * Returns the recyclable block flyout inflater. + * + * @returns The recyclable inflater. + */ + protected getRecyclableInflater(): RecyclableBlockFlyoutInflater { const inflater = this.getInflaterForType('block'); - if (inflater instanceof RecyclableBlockFlyoutInflater) { - inflater.setRecyclingEnabled(isEnabled); + if (!(inflater instanceof RecyclableBlockFlyoutInflater)) { + throw new Error('The RecyclableBlockFlyoutInflater is not registered.'); } + + return inflater; } } diff --git a/plugins/continuous-toolbox/src/RecyclableBlockFlyoutInflater.ts b/plugins/continuous-toolbox/src/RecyclableBlockFlyoutInflater.ts index 6cd2f9579..69dfeba37 100644 --- a/plugins/continuous-toolbox/src/RecyclableBlockFlyoutInflater.ts +++ b/plugins/continuous-toolbox/src/RecyclableBlockFlyoutInflater.ts @@ -13,7 +13,7 @@ export class RecyclableBlockFlyoutInflater extends Blockly.BlockFlyoutInflater { /** * Whether or not block recycling is enabled. */ - private recyclingEnabled = true; + private recyclingEnabled = false; /** * Map from block type to block instance.