From 36135ac62ba2e5a3de1a06b22689e11f8d5e25d0 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini <16690124+samelhusseini@users.noreply.github.com> Date: Wed, 7 Aug 2019 10:54:36 -0700 Subject: [PATCH] Fix RTL text field positioning bug by ensuring a reflow (#2779) --- core/field_textinput.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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);