From f4f9a679035eebdc2bc39345b93e7b8715b7121e Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Tue, 8 Oct 2019 16:48:31 -0700 Subject: [PATCH] Fixed field editor disposal (#3109) * Fixed field editor disposal. --- core/field_angle.js | 4 +++- core/field_colour.js | 2 +- core/field_dropdown.js | 2 +- core/field_textinput.js | 20 +++++++------------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/core/field_angle.js b/core/field_angle.js index a8f9fb869..7e88f154c 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -304,13 +304,15 @@ Blockly.FieldAngle.prototype.dropdownCreate_ = function() { }; /** - * Dispose of events belonging to the angle editor. + * Disposes of events and dom-references belonging to the angle editor. * @private */ Blockly.FieldAngle.prototype.dropdownDispose_ = function() { Blockly.unbindEvent_(this.clickWrapper_); Blockly.unbindEvent_(this.clickSurfaceWrapper_); Blockly.unbindEvent_(this.moveSurfaceWrapper_); + this.gauge_ = null; + this.line_ = null; }; /** diff --git a/core/field_colour.js b/core/field_colour.js index 88c9891d4..abc481243 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -556,7 +556,7 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { }; /** - * Dispose of events belonging to the colour editor. + * Disposes of events and dom-references belonging to the colour editor. * @private */ Blockly.FieldColour.prototype.dropdownDispose_ = function() { diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 44be889fa..238eb7f07 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -269,7 +269,7 @@ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { }; /** - * Dispose of events belonging to the dropdown editor. + * Disposes of events and dom-references belonging to the dropdown editor. * @private */ Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { diff --git a/core/field_textinput.js b/core/field_textinput.js index 46bcb7bc5..f9079fc31 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -292,34 +292,28 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { }; /** - * Close the editor, save the results, and dispose any events bound to the - * text input's editor. + * Closes the editor, saves the results, and disposes of any events or + * dom-references belonging to the editor. * @private */ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { - // Finalize value. + // Non-disposal related things that we do when the editor closes. this.isBeingEdited_ = false; this.isTextValid_ = true; - - // Always re-render when the we close the editor as value - // set on the field's node may be inconsistent with the field's - // internal value. + // Make sure the field's node matches the field's internal value. this.forceRerender(); - - // Call onFinishEditing - // TODO: Get rid of this or make it less of a hack. + // TODO(#2496): Make this less of a hack. if (this.onFinishEditing_) { this.onFinishEditing_(this.value_); } - // Remove htmlInput events. + // Actual disposal. this.unbindInputEvents_(); - - // Delete style properties. var style = Blockly.WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; + this.htmlInput_ = null; }; /**