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
19 changes: 14 additions & 5 deletions plugins/continuous-toolbox/src/ContinuousFlyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
*
* @returns Toolbox that owns this flyout.
*/
private getParentToolbox(): ContinuousToolbox {
return this.targetWorkspace.getToolbox() as ContinuousToolbox;
private getParentToolbox(): ContinuousToolbox | null {
const toolbox = this.targetWorkspace.getToolbox();
if (!toolbox || toolbox instanceof ContinuousToolbox) return toolbox;

console.warn(
'Expected a `ContinuousToolbox` instance but did not find one. ' +
'Make sure `registerContinuousToolbox()` has been called and the ' +
'continuous toolbox has been injected.',
);

return null;
}

/**
Expand Down Expand Up @@ -110,7 +119,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
// Note that `FlyoutButton` represents both buttons and labels.
element instanceof Blockly.FlyoutButton &&
element.isLabel() &&
this.getParentToolbox().getCategoryByName(element.getButtonText())
this.getParentToolbox()?.getCategoryByName(element.getButtonText())
);
}

Expand Down Expand Up @@ -146,7 +155,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
...this.scrollPositions.entries(),
].reverse()) {
if (scaledPosition >= position) {
this.getParentToolbox().selectCategoryByName(name);
this.getParentToolbox()?.selectCategoryByName(name);
return;
}
}
Expand Down Expand Up @@ -271,7 +280,7 @@ export class ContinuousFlyout extends Blockly.VerticalFlyout {
super.show(flyoutDef);
this.recordScrollPositions();
this.getWorkspace().resizeContents();
if (!this.getParentToolbox().getSelectedItem()) {
if (!this.getParentToolbox()?.getSelectedItem()) {
this.selectCategoryByScrollPosition(0);
}
this.getRecyclableInflater().emptyRecycledBlocks();
Expand Down
Loading