From 9236b4e207c40053e976de8b961a362198d07308 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 13 Mar 2023 08:55:00 -0700 Subject: [PATCH] fix: improve performance of modifying block shape (#6884) --- core/block_svg.ts | 10 +++++----- core/input.ts | 2 +- tests/mocha/block_test.js | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/block_svg.ts b/core/block_svg.ts index befb621fd..5f3eab7bb 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -1263,7 +1263,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, super.setPreviousStatement(newBoolean, opt_check); if (this.rendered) { - this.render(); + this.queueRender(); this.bumpNeighbours(); } } @@ -1280,7 +1280,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, super.setNextStatement(newBoolean, opt_check); if (this.rendered) { - this.render(); + this.queueRender(); this.bumpNeighbours(); } } @@ -1296,7 +1296,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, super.setOutput(newBoolean, opt_check); if (this.rendered) { - this.render(); + this.queueRender(); this.bumpNeighbours(); } } @@ -1310,7 +1310,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, super.setInputsInline(newBoolean); if (this.rendered) { - this.render(); + this.queueRender(); this.bumpNeighbours(); } } @@ -1346,7 +1346,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, super.moveNumberedInputBefore(inputIndex, refIndex); if (this.rendered) { - this.render(); + this.queueRender(); // Moving an input will cause the block to change shape. this.bumpNeighbours(); } diff --git a/core/input.ts b/core/input.ts index 5b25f5797..09a8a2dc6 100644 --- a/core/input.ts +++ b/core/input.ts @@ -244,7 +244,7 @@ export class Input { this.align = align; if (this.sourceBlock.rendered) { const sourceBlock = this.sourceBlock as BlockSvg; - sourceBlock.render(); + sourceBlock.queueRender(); } return this; } diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index d04868b56..b9eadedfa 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -1114,6 +1114,7 @@ suite('Blocks', function() { const block = createRenderedBlock(this.workspace, 'empty_block'); block.setOutput(true); + this.clock.runAll(); this.clock.runAll(); chai.assert.equal(this.getOutputs().length, 1); @@ -1130,6 +1131,7 @@ suite('Blocks', function() { const block = createRenderedBlock(this.workspace, 'empty_block'); block.setPreviousStatement(true); + this.clock.runAll(); this.clock.runAll(); chai.assert.equal(this.getPrevious().length, 1); @@ -1138,6 +1140,7 @@ suite('Blocks', function() { const block = createRenderedBlock(this.workspace, 'empty_block'); block.setNextStatement(true); + this.clock.runAll(); this.clock.runAll(); chai.assert.equal(this.getNext().length, 1);