Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions plugins/continuous-toolbox/src/ContinuousFlyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
.forEach((label) => {
this.scrollPositions.set(
label.getButtonText(),
label.getPosition().y - label.height,
Math.max(0, label.getPosition().y - this.GAP_Y / 2),
);
});
}
Expand All @@ -114,6 +114,21 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
);
}

/**
* Returns the scroll position for the given category name.
*
* @param name Category name.
* @returns Scroll position for given category in workspace units, or null if
* not found.
*/
getCategoryScrollPosition(name: string): number | null {
const position = this.scrollPositions.get(name);
if (position === undefined) {
console.warn(`Scroll position not recorded for category ${name}`);
}
return position ?? null;
}

/**
* Selects an item in the toolbox based on the scroll position of the flyout.
*
Expand Down Expand Up @@ -161,7 +176,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
*/
scrollToCategory(category: Blockly.ISelectableToolboxItem) {
const position = this.scrollPositions.get(category.getName());
if (!position) {
if (position === undefined) {
console.warn(`Scroll position not recorded for category ${name}`);
return;
}
Expand All @@ -173,8 +188,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
* a scroll target, and request the next frame if necessary.
*/
private stepScrollAnimation() {
if (!this.scrollTarget) return;

if (this.scrollTarget === undefined) return;
const currentScrollPos = -this.getWorkspace().scrollY;
const diff = this.scrollTarget - currentScrollPos;
if (Math.abs(diff) < 1) {
Expand Down
Loading