diff --git a/HISTORY.md b/HISTORY.md index 77ac362f..5f01cb56 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -12,6 +12,7 @@ ### 2022-03-01 * blocks: adjusted restoring inputs for relabelling to / from variadic infix reporters +* blocks: refactored adding and removing inputs in variadic slots ### 2022-02-28 * blocks, objects, threads, store: made addition reporter variadic diff --git a/src/blocks.js b/src/blocks.js index c3048501..2e1267da 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -12614,7 +12614,7 @@ MultiArgMorph.prototype.refresh = function () { */ MultiArgMorph.prototype.deleteSlot = function (anInput) { - if (this.children.length <= this.minInputs + 1) { + if (this.inputs().length <= this.minInputs) { return; } this.removeChild(anInput); @@ -12625,7 +12625,7 @@ MultiArgMorph.prototype.insertNewInputBefore = function (anInput, contents) { var idx = this.children.indexOf(anInput), newPart = this.labelPart(this.slotSpec); - if (this.maxInputs && (this.children.length > this.maxInputs)) { + if (this.maxInputs && (this.inputs().length >= this.maxInputs)) { return; } if (contents) { @@ -12692,9 +12692,10 @@ MultiArgMorph.prototype.addInfix = function () { }; MultiArgMorph.prototype.removeInput = function () { - var oldPart, scripts; - if (this.children.length > 1) { - oldPart = this.children[this.children.length - 2]; + var len = this.inputs().length, + oldPart, scripts; + if (len > 0) { + oldPart = this.inputs()[len - 1]; this.removeChild(oldPart); if (oldPart instanceof BlockMorph && !(oldPart instanceof RingMorph && !oldPart.contents())) {