Skip to content

Commit

Permalink
refactor: Make the RecyclableBlockFlyoutInflater inert for non-contin…
Browse files Browse the repository at this point in the history
…uous flyouts.
  • Loading branch information
gonfunko committed Nov 8, 2024
1 parent 7c0a08c commit a538e7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions plugins/continuous-toolbox/src/ContinuousFlyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
this.selectCategoryByScrollPosition(-this.getWorkspace().scrollY);
}
});

this.setRecyclingEnabled(true);
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a538e7e

Please sign in to comment.