Fix setting focus for workspace (#3425)

* Fix setting focus for workspace
This commit is contained in:
alschmiedt
2019-11-11 16:44:58 -08:00
committed by GitHub
parent 3076874b2b
commit 40bdfac017
6 changed files with 32 additions and 15 deletions

View File

@@ -269,7 +269,7 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) {
this.isBeingEdited_ = true;
if (!quietInput) {
this.htmlInput_.focus();
this.htmlInput_.focus({preventScroll:true});
this.htmlInput_.select();
}
};
@@ -349,6 +349,10 @@ Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) {
this.onKeyInputWrapper_ =
Blockly.bindEventWithChecks_(
htmlInput, 'input', this, this.onHtmlInputChange_);
this.onBlurInputWrapper_ =
Blockly.bindEventWithChecks_(
htmlInput, 'blur', this, this.onHtmlInputBlur_);
};
/**
@@ -362,6 +366,9 @@ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() {
if (this.onKeyInputWrapper_) {
Blockly.unbindEvent_(this.onKeyInputWrapper_);
}
if (this.onBlurInputWrapper_) {
Blockly.unbindEvent_(this.onBlurInputWrapper_);
}
};
/**
@@ -406,6 +413,16 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) {
}
};
/**
* Handle blur for the editor.
* @param {!Event} _e Focus event.
* @protected
*/
Blockly.FieldTextInput.prototype.onHtmlInputBlur_ = function(_e) {
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
};
/**
* Set the html input value and the field's internal value. The difference
* between this and ``setValue`` is that this also updates the html input