Commit d609675c authored by Neil Fraser's avatar Neil Fraser

Merge pull request #69 from smalruby/fix_ime_bug

Fixed issue with pressed enter key with IME.
parents 0b1efa2e 033a6b88
...@@ -132,7 +132,10 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) { ...@@ -132,7 +132,10 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
htmlInput.select(); htmlInput.select();
} }
// Bind to keyup -- trap Enter and Esc; resize after every keystroke. // Bind to keydown -- trap Enter without IME and Esc to hide.
htmlInput.onKeyDownWrapper_ =
Blockly.bindEvent_(htmlInput, 'keydown', this, this.onHtmlInputKeyDown_);
// Bind to keyup -- trap Enter; resize after every keystroke.
htmlInput.onKeyUpWrapper_ = htmlInput.onKeyUpWrapper_ =
Blockly.bindEvent_(htmlInput, 'keyup', this, this.onHtmlInputChange_); Blockly.bindEvent_(htmlInput, 'keyup', this, this.onHtmlInputChange_);
// Bind to keyPress -- repeatedly resize when holding down a key. // Bind to keyPress -- repeatedly resize when holding down a key.
...@@ -145,20 +148,30 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) { ...@@ -145,20 +148,30 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
}; };
/** /**
* Handle a change to the editor. * Handle key down to the editor.
* @param {!Event} e Keyboard event. * @param {!Event} e Keyboard event.
* @private * @private
*/ */
Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(e) { Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) {
var htmlInput = Blockly.FieldTextInput.htmlInput_; var htmlInput = Blockly.FieldTextInput.htmlInput_;
if (e.keyCode == 13) { var enterKey = 13, escKey = 27;
// Enter if (e.keyCode == enterKey) {
Blockly.WidgetDiv.hide(); Blockly.WidgetDiv.hide();
} else if (e.keyCode == 27) { } else if (e.keyCode == escKey) {
// Esc
this.setText(htmlInput.defaultValue); this.setText(htmlInput.defaultValue);
Blockly.WidgetDiv.hide(); Blockly.WidgetDiv.hide();
} else { }
};
/**
* Handle a change to the editor.
* @param {!Event} e Keyboard event.
* @private
*/
Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(e) {
var htmlInput = Blockly.FieldTextInput.htmlInput_;
var escKey = 27;
if (e.keyCode != escKey) {
// Update source block. // Update source block.
var text = htmlInput.value; var text = htmlInput.value;
if (text !== htmlInput.oldValue_) { if (text !== htmlInput.oldValue_) {
...@@ -238,6 +251,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { ...@@ -238,6 +251,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() {
} }
thisField.setText(text); thisField.setText(text);
thisField.sourceBlock_.rendered && thisField.sourceBlock_.render(); thisField.sourceBlock_.rendered && thisField.sourceBlock_.render();
Blockly.unbindEvent_(htmlInput.onKeyDownWrapper_);
Blockly.unbindEvent_(htmlInput.onKeyUpWrapper_); Blockly.unbindEvent_(htmlInput.onKeyUpWrapper_);
Blockly.unbindEvent_(htmlInput.onKeyPressWrapper_); Blockly.unbindEvent_(htmlInput.onKeyPressWrapper_);
Blockly.unbindEvent_(htmlInput.onWorkspaceChangeWrapper_); Blockly.unbindEvent_(htmlInput.onWorkspaceChangeWrapper_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment