diff --git a/core/field_textinput.js b/core/field_textinput.js index e75f84576..305e45e04 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -161,7 +161,17 @@ Blockly.FieldTextInput.prototype.render_ = function() { // This logic is done in render_ rather than doValueInvalid_ or // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { - this.resizeEditor_(); + if (this.sourceBlock_.RTL) { + // in RTL, we need to let the browser reflow before resizing + // in order to get the correct bounding box of the borderRect + // avoiding issue #2777. + var field = this; + setTimeout(function() { + field.resizeEditor_(); + }, 0); + } else { + this.resizeEditor_(); + } if (!this.isTextValid_) { Blockly.utils.dom.addClass(this.htmlInput_, 'blocklyInvalidInput'); } else { @@ -247,7 +257,11 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { htmlInput.value = htmlInput.defaultValue = this.value_; htmlInput.untypedDefaultValue_ = this.value_; htmlInput.oldValue_ = null; - this.resizeEditor_(); + // Ensure the browser reflows before resizing to avoid issue #2777. + var field = this; + setTimeout(function() { + field.resizeEditor_(); + }, 0); this.bindInputEvents_(htmlInput);