From c762d42e1fc5a45d1345b805156ee8d1d9cb38c1 Mon Sep 17 00:00:00 2001 From: priya-rjb <143019215+priya-rjb@users.noreply.github.com> Date: Sun, 24 Sep 2023 08:08:10 +0545 Subject: [PATCH] fix: non-nullable check for block variable and removed ! in layout_ #7522 (#7537) * #7522 edits -- collaborated with Hinal Patel, Swedhaa Sri Elango, & Yuchi Hsieh * #7522 edits: collaborated with Hinal Patel, Swedhaa Sri Elango, & Yuchi Hsieh * fix: non-nullable check for block variable and removed ! in layout_ #7522 * fix: non-nullable check for block variable and removed ! in layout_ --- core/flyout_horizontal.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/flyout_horizontal.ts b/core/flyout_horizontal.ts index 372b40c84..b344f41fd 100644 --- a/core/flyout_horizontal.ts +++ b/core/flyout_horizontal.ts @@ -267,29 +267,35 @@ export class HorizontalFlyout extends Flyout { for (let i = 0, item; (item = contents[i]); i++) { if (item.type === 'block') { const block = item.block; - const allBlocks = block!.getDescendants(false); + + if (block === undefined || block === null) { + continue; + } + + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such // a block. child.isInFlyout = true; } - const root = block!.getSvgRoot(); - const blockHW = block!.getHeightWidth(); + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); // Figure out where to place the block. - const tab = block!.outputConnection ? this.tabWidth_ : 0; + const tab = block.outputConnection ? this.tabWidth_ : 0; let moveX; if (this.RTL) { moveX = cursorX + blockHW.width; } else { moveX = cursorX - tab; } - block!.moveBy(moveX, cursorY); + block.moveBy(moveX, cursorY); - const rect = this.createRect_(block!, moveX, cursorY, blockHW, i); + const rect = this.createRect_(block, moveX, cursorY, blockHW, i); cursorX += blockHW.width + gaps[i]; - this.addBlockListeners_(root, block!, rect); + this.addBlockListeners_(root, block, rect); } else if (item.type === 'button') { const button = item.button as FlyoutButton; this.initFlyoutButton_(button, cursorX, cursorY);