Skip to content

Commit

Permalink
fix: Include padding above category labels when jumping to a category. (
Browse files Browse the repository at this point in the history
google#2218)

* fix: Include padding above category labels when jumping to a category.

* fix: Add JSDoc to layout_().

* fix: Format ContinuousFlyout.js.
  • Loading branch information
gonfunko committed Feb 22, 2024
1 parent 770d03d commit bd3cba1
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions plugins/continuous-toolbox/src/ContinuousFlyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
button.isLabel() &&
this.getParentToolbox_().getCategoryByName(button.getButtonText()),
);
for (const button of categoryLabels) {
for (const [index, button] of categoryLabels.entries()) {
if (button.isLabel()) {
const position = button.getPosition();
const adjustedPosition = new Blockly.utils.Coordinate(
position.x,
position.y - this.labelGaps[index],
);
this.scrollPositions.push({
name: button.getButtonText(),
position: button.getPosition(),
position: adjustedPosition,
});
}
}
Expand Down Expand Up @@ -120,7 +125,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
selectCategoryByScrollPosition_(position) {
// If we are currently auto-scrolling, due to selecting a category by
// clicking on it, do not update the category selection.
if (this.scrollTarget) {
if (this.scrollTarget !== null) {
return;
}
const scaledPosition = Math.round(position / this.workspace_.scale);
Expand All @@ -137,7 +142,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {

/**
* Scrolls flyout to given position.
* @param {number} position The x coordinate to scroll to.
* @param {number} position The Y coordinate to scroll to.
*/
scrollTo(position) {
// Set the scroll target to either the scaled position or the lowest
Expand All @@ -157,7 +162,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
* @private
*/
stepScrollAnimation_() {
if (!this.scrollTarget) {
if (this.scrollTarget === null) {
return;
}

Expand Down Expand Up @@ -219,6 +224,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
super.show(flyoutDef);
this.recordScrollPositions();
this.workspace_.resizeContents();
this.selectCategoryByScrollPosition_(0);
}

/**
Expand Down Expand Up @@ -286,4 +292,19 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
setRecyclingEnabled(isEnabled) {
this.recyclingEnabled_ = isEnabled;
}

/**
* Lay out the blocks in the flyout.
* @param {Array<Blockly.Flyout.FlyoutItem>} contents The blocks and buttons to lay out.
* @param {Array<number>} gaps The visible gaps between blocks.
*/
layout_(contents, gaps) {
super.layout_(contents, gaps);
this.labelGaps = [];
for (const [index, item] of contents.entries()) {
if (item.type === 'button' && item.button.isLabel()) {
this.labelGaps.push(gaps[index - 1] ?? this.MARGIN);
}
}
}
}

0 comments on commit bd3cba1

Please sign in to comment.