Commit 59cf1468 authored by Kouji Takao's avatar Kouji Takao Committed by carlosperate

Fixed issue with pressed enter key with IME.

keyup and keypress don't care IME on or off.  so, I added handling
keydown event to check pressing enter key with IME (keycode is 229) or
without IME (keycode is 13).
parent 7aad5f51
......@@ -132,7 +132,10 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
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_ =
Blockly.bindEvent_(htmlInput, 'keyup', this, this.onHtmlInputChange_);
// Bind to keyPress -- repeatedly resize when holding down a key.
......@@ -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.
* @private
*/
Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(e) {
Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) {
var htmlInput = Blockly.FieldTextInput.htmlInput_;
if (e.keyCode == 13) {
// Enter
var enterKey = 13, escKey = 27;
if (e.keyCode == enterKey) {
Blockly.WidgetDiv.hide();
} else if (e.keyCode == 27) {
// Esc
} else if (e.keyCode == escKey) {
this.setText(htmlInput.defaultValue);
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.
var text = htmlInput.value;
if (text !== htmlInput.oldValue_) {
......@@ -238,6 +251,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() {
}
thisField.setText(text);
thisField.sourceBlock_.rendered && thisField.sourceBlock_.render();
Blockly.unbindEvent_(htmlInput.onKeyDownWrapper_);
Blockly.unbindEvent_(htmlInput.onKeyUpWrapper_);
Blockly.unbindEvent_(htmlInput.onKeyPressWrapper_);
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