Skip to content

Commit c0b3d0e

Browse files
gonfunkocwillisf
authored andcommitted
fix: preserve toolbox scroll position when switching between sprites/the stage (#10)
1 parent 5de68f1 commit c0b3d0e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/scratch-gui/src/containers/blocks.jsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,13 @@ class Blocks extends React.Component {
239239
updateToolbox () {
240240
this.toolboxUpdateTimeout = false;
241241

242-
// const categoryId = this.workspace.toolbox_.getSelectedItem().getId();
243-
// const offset = this.workspace.toolbox_.getCategoryScrollOffset();
242+
const scale = this.workspace.getFlyout().getWorkspace().scale;
243+
const selectedCategoryName = this.workspace.getToolbox().getSelectedItem().getName();
244+
const selectedCategoryScrollPosition = this.workspace.getFlyout().getCategoryScrollPosition(
245+
selectedCategoryName).y * scale;
246+
const offsetWithinCategory = (this.workspace.getFlyout().getWorkspace().getMetrics().viewTop
247+
- selectedCategoryScrollPosition);
248+
244249
this.workspace.updateToolbox(this.props.toolboxXML);
245250
this.workspace.refreshToolboxSelection();
246251
this._renderedToolboxXML = this.props.toolboxXML;
@@ -250,13 +255,10 @@ class Blocks extends React.Component {
250255
// Using the setter function will rerender the entire toolbox which we just rendered.
251256
this.workspace.toolboxRefreshEnabled_ = true;
252257

253-
// const currentCategoryPos = this.workspace.toolbox_.getCategoryPositionById(categoryId);
254-
// const currentCategoryLen = this.workspace.toolbox_.getCategoryLengthById(categoryId);
255-
// if (offset < currentCategoryLen) {
256-
// this.workspace.toolbox_.setFlyoutScrollPos(currentCategoryPos + offset);
257-
// } else {
258-
// this.workspace.toolbox_.setFlyoutScrollPos(currentCategoryPos);
259-
// }
258+
const newCategoryScrollPosition = this.workspace.getFlyout().getCategoryScrollPosition(
259+
selectedCategoryName).y * scale;
260+
this.workspace.getFlyout().getWorkspace().scrollbar.setY(
261+
newCategoryScrollPosition + offsetWithinCategory);
260262

261263
const queue = this.toolboxUpdateQueue;
262264
this.toolboxUpdateQueue = [];

0 commit comments

Comments
 (0)