fix: improve performance of modifying block shape (#6884)

This commit is contained in:
Beka Westberg
2023-03-13 08:55:00 -07:00
committed by GitHub
parent cdb1215d95
commit 9236b4e207
3 changed files with 9 additions and 6 deletions

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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);