Skip to content

Commit

Permalink
don't grow flyout cache indefinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Feb 27, 2025
1 parent 6b2c568 commit 1148066
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pxtblocks/plugins/flyout/verticalFlyout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as Blockly from "blockly";

const MAX_CACHED_FLYOUTS = 20;

export class VerticalFlyout implements Blockly.IFlyout {
horizontalLayout = false;
RTL: boolean;
Expand Down Expand Up @@ -129,12 +131,21 @@ export class VerticalFlyout implements Blockly.IFlyout {
this.activeFlyout = existing;
this.activeFlyout.autoClose = this.autoClose;
this.activeFlyout.setContainerVisible(this.containerVisible);
this.activeFlyout.show(flyoutDef)
this.activeFlyout.show(flyoutDef);

// move to most recently used in the cache
this.cached.splice(this.cached.indexOf(existing), 1);
this.cached.push(existing);
return;
}

this.activeFlyout = new CachedFlyout(this.options);
this.cached.push(this.activeFlyout);

if (this.cached.length >= MAX_CACHED_FLYOUTS) {
this.cached.shift().dispose();
}

this.element.appendChild(this.activeFlyout.createDom("g"));
this.activeFlyout.init(this.targetWorkspace);

Expand Down

0 comments on commit 1148066

Please sign in to comment.