Skip to content

Commit 7476290

Browse files
authored
fix: Fix scrolling and API issues with the continuous toolbox plugin. (#2485)
* fix: Fix bugs when scrolling between categories. * feat: Readd `getCategoryScrollPosition`. * chore: Placate the linter. * chore: Note units in docstring.
1 parent 1fba9c5 commit 7476290

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

plugins/continuous-toolbox/src/ContinuousFlyout.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
8989
.forEach((label) => {
9090
this.scrollPositions.set(
9191
label.getButtonText(),
92-
label.getPosition().y - label.height,
92+
Math.max(0, label.getPosition().y - this.GAP_Y / 2),
9393
);
9494
});
9595
}
@@ -114,6 +114,21 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
114114
);
115115
}
116116

117+
/**
118+
* Returns the scroll position for the given category name.
119+
*
120+
* @param name Category name.
121+
* @returns Scroll position for given category in workspace units, or null if
122+
* not found.
123+
*/
124+
getCategoryScrollPosition(name: string): number | null {
125+
const position = this.scrollPositions.get(name);
126+
if (position === undefined) {
127+
console.warn(`Scroll position not recorded for category ${name}`);
128+
}
129+
return position ?? null;
130+
}
131+
117132
/**
118133
* Selects an item in the toolbox based on the scroll position of the flyout.
119134
*
@@ -161,7 +176,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
161176
*/
162177
scrollToCategory(category: Blockly.ISelectableToolboxItem) {
163178
const position = this.scrollPositions.get(category.getName());
164-
if (!position) {
179+
if (position === undefined) {
165180
console.warn(`Scroll position not recorded for category ${name}`);
166181
return;
167182
}
@@ -173,8 +188,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
173188
* a scroll target, and request the next frame if necessary.
174189
*/
175190
private stepScrollAnimation() {
176-
if (!this.scrollTarget) return;
177-
191+
if (this.scrollTarget === undefined) return;
178192
const currentScrollPos = -this.getWorkspace().scrollY;
179193
const diff = this.scrollTarget - currentScrollPos;
180194
if (Math.abs(diff) < 1) {

0 commit comments

Comments
 (0)