From 7b2d16c75e02cb41d225383cf991fc120202b294 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 30 Apr 2024 15:37:44 -0700 Subject: [PATCH] fix: preserve toolbox scroll position when switching between sprites/the stage --- src/containers/blocks.jsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx index 49f83a7e20e..2cba5b47081 100644 --- a/src/containers/blocks.jsx +++ b/src/containers/blocks.jsx @@ -239,8 +239,13 @@ class Blocks extends React.Component { updateToolbox () { this.toolboxUpdateTimeout = false; - // const categoryId = this.workspace.toolbox_.getSelectedItem().getId(); - // const offset = this.workspace.toolbox_.getCategoryScrollOffset(); + const scale = this.workspace.getFlyout().getWorkspace().scale; + const selectedCategoryName = this.workspace.getToolbox().getSelectedItem().getName(); + const selectedCategoryScrollPosition = this.workspace.getFlyout().getCategoryScrollPosition( + selectedCategoryName).y * scale; + const offsetWithinCategory = (this.workspace.getFlyout().getWorkspace().getMetrics().viewTop + - selectedCategoryScrollPosition); + this.workspace.updateToolbox(this.props.toolboxXML); this.workspace.refreshToolboxSelection(); this._renderedToolboxXML = this.props.toolboxXML; @@ -250,13 +255,10 @@ class Blocks extends React.Component { // Using the setter function will rerender the entire toolbox which we just rendered. this.workspace.toolboxRefreshEnabled_ = true; - // const currentCategoryPos = this.workspace.toolbox_.getCategoryPositionById(categoryId); - // const currentCategoryLen = this.workspace.toolbox_.getCategoryLengthById(categoryId); - // if (offset < currentCategoryLen) { - // this.workspace.toolbox_.setFlyoutScrollPos(currentCategoryPos + offset); - // } else { - // this.workspace.toolbox_.setFlyoutScrollPos(currentCategoryPos); - // } + const newCategoryScrollPosition = this.workspace.getFlyout().getCategoryScrollPosition( + selectedCategoryName).y * scale; + this.workspace.getFlyout().getWorkspace().scrollbar.setY( + newCategoryScrollPosition + offsetWithinCategory); const queue = this.toolboxUpdateQueue; this.toolboxUpdateQueue = [];