From 48b3398feea6bfe861dfc81725f8cd5ac368a0d7 Mon Sep 17 00:00:00 2001 From: Steven Lau Date: Sat, 31 May 2025 18:46:20 +0000 Subject: [PATCH] fix: show updated field value after editing in horizontal blocks Problem: In horizontal blocks, let's say you created a control_repeat block, if you edit the number of iteration from 4 to 5, after pressing Enter, the number is still shown as 4. Cause: field.js setText function would call forceRerender. Currently, forceRerender would set this.size_.width to 0 to force a render_() call later. However, this would work only if this.getSize() is indeed called later to trigger this.render_(), which is the case for vertical blocks, but not for horizontal blocks, causing the updated value not being shown. Fix: Setting this.size_.width to 0 was a silly trick. Since our purpose is to force render_() anyway, we could have simply called render_() directly. One may argue that, render_() should not be called immediately; some setup from sourceBlock_.render() needs to be done before this.render_() maybe called. Well, this is not true. this.render_() does not depend on sourceBlock_, or anything. We can just call it immediately. --- core/field.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/field.js b/core/field.js index 692caa96a2..8a5963258b 100644 --- a/core/field.js +++ b/core/field.js @@ -655,8 +655,7 @@ Blockly.Field.prototype.setText = function(newText) { * @package */ Blockly.Field.prototype.forceRerender = function() { - // Set width to 0 to force a rerender of this field. - this.size_.width = 0; + this.render_(); if (this.sourceBlock_ && this.sourceBlock_.rendered) { this.sourceBlock_.render();