From 20cf6abb5f03bf7c9af222113ee3d28e4c7fc39f Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 3 Jan 2017 14:09:41 -0800 Subject: [PATCH 1/3] End event groups when you finish editing a field --- core/field_colour.js | 1 + core/field_date.js | 1 + core/field_dropdown.js | 1 + core/field_textinput.js | 1 + 4 files changed, 4 insertions(+) diff --git a/core/field_colour.js b/core/field_colour.js index 30b7dc5e2..a538ba843 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -231,4 +231,5 @@ Blockly.FieldColour.widgetDispose_ = function() { if (Blockly.FieldColour.changeEventKey_) { goog.events.unlistenByKey(Blockly.FieldColour.changeEventKey_); } + Blockly.Events.setGroup(false); }; diff --git a/core/field_date.js b/core/field_date.js index 24f3239e4..9e19c63ac 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -165,6 +165,7 @@ Blockly.FieldDate.widgetDispose_ = function() { if (Blockly.FieldDate.changeEventKey_) { goog.events.unlistenByKey(Blockly.FieldDate.changeEventKey_); } + Blockly.Events.setGroup(false); }; /** diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 3976cba40..70ac3b9f4 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -133,6 +133,7 @@ Blockly.FieldDropdown.prototype.showEditor_ = function() { thisField.onItemSelected(menu, menuItem); } Blockly.WidgetDiv.hideIfOwner(thisField); + Blockly.Events.setGroup(false); } var menu = new goog.ui.Menu(); diff --git a/core/field_textinput.js b/core/field_textinput.js index e95ead82b..cf876f91d 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -290,6 +290,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { thisField.workspace_.removeChangeListener( htmlInput.onWorkspaceChangeWrapper_); Blockly.FieldTextInput.htmlInput_ = null; + Blockly.Events.setGroup(false); // Delete style properties. var style = Blockly.WidgetDiv.DIV.style; style.width = 'auto'; From 056824593e3581a77c2b75cf62bbb9749d2ccfab Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 3 Jan 2017 14:51:28 -0800 Subject: [PATCH 2/3] Now that text input's setText skips setValue, it needs to explicitly create a change event --- core/field_textinput.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/field_textinput.js b/core/field_textinput.js index cf876f91d..3d224c031 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -94,6 +94,18 @@ Blockly.FieldTextInput.prototype.setValue = function(newValue) { Blockly.Field.prototype.setValue.call(this, newValue); }; +/** + * Set the text in this field and fire a change event. + * @param {*} newText New text. + */ +Blockly.FieldTextInput.prototype.setText = function(newText) { + if (this.sourceBlock_ && Blockly.Events.isEnabled()) { + Blockly.Events.fire(new Blockly.Events.Change( + this.sourceBlock_, 'field', this.name, this.text_, newText)); + } + Blockly.Field.prototype.setText.call(this, newText); +}; + /** * Set whether this field is spellchecked by the browser. * @param {boolean} check True if checked. From 528ea86cbf587f8871282a28bd6f637772d69f1c Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 3 Jan 2017 14:58:05 -0800 Subject: [PATCH 3/3] Check if the text has changed before firing an event --- core/field_textinput.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/field_textinput.js b/core/field_textinput.js index 3d224c031..5c6e66215 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -99,6 +99,15 @@ Blockly.FieldTextInput.prototype.setValue = function(newValue) { * @param {*} newText New text. */ Blockly.FieldTextInput.prototype.setText = function(newText) { + if (newText === null) { + // No change if null. + return; + } + newText = String(newText); + if (newText === this.text_) { + // No change. + return; + } if (this.sourceBlock_ && Blockly.Events.isEnabled()) { Blockly.Events.fire(new Blockly.Events.Change( this.sourceBlock_, 'field', this.name, this.text_, newText));