From def80b3f31beb379a42fdeed620265c7fbbd8ab9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 11 Sep 2024 12:37:32 -0700 Subject: [PATCH] fix: improve flyout performance (#8571) * fix: improve flyout performance * refactor: don't call position() in show() The later call to reflow() itself winds up calling position(), so this calculation is redundant. --- core/flyout_base.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/core/flyout_base.ts b/core/flyout_base.ts index 18f84480c..2ea85a0df 100644 --- a/core/flyout_base.ts +++ b/core/flyout_base.ts @@ -402,7 +402,14 @@ export abstract class Flyout this.wheel_, ), ); - this.filterWrapper = this.filterForCapacity.bind(this); + this.filterWrapper = (event) => { + if ( + event.type === eventUtils.BLOCK_CREATE || + event.type === eventUtils.BLOCK_DELETE + ) { + this.filterForCapacity(); + } + }; this.targetWorkspace.addChangeListener(this.filterWrapper); // Dragging the flyout up and down. @@ -704,10 +711,17 @@ export abstract class Flyout this.filterForCapacity(); - // Correctly position the flyout's scrollbar when it opens. - this.position(); - - this.reflowWrapper = this.reflow.bind(this); + // Listen for block change events, and reflow the flyout in response. This + // accommodates e.g. resizing a non-autoclosing flyout in response to the + // user typing long strings into fields on the blocks in the flyout. + this.reflowWrapper = (event) => { + if ( + event.type === eventUtils.BLOCK_CHANGE || + event.type === eventUtils.BLOCK_FIELD_INTERMEDIATE_CHANGE + ) { + this.reflow(); + } + }; this.workspace_.addChangeListener(this.reflowWrapper); this.emptyRecycledBlocks(); }