Prevent TextBox from blurring unless explicity by user.

This commit is contained in:
Jonathan Frederic 2014-01-24 13:35:58 -08:00
parent d0b6e2a63d
commit c807dd29e4

View File

@ -172,7 +172,9 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
"keyup input" : "handleChanging",
"paste input" : "handleChanging",
"cut input" : "handleChanging",
"keypress input" : "handleKeypress"
"keypress input" : "handleKeypress",
"blur input" : "handleBlur",
"focusout input" : "handleFocusOut"
},
handleChanging: function(e) {
@ -188,6 +190,31 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
// Handles text submition
if (e.keyCode == 13) { // Return key
this.send({event: 'submit'});
event.stopPropagation();
event.preventDefault();
return false;
}
},
handleBlur: function(e) {
// Prevent a blur from firing if the blur was not user intended.
// This is a workaround for the return-key focus loss bug.
// TODO: Is the original bug actually a fault of the keyboard
// manager?
if (e.relatedTarget === null) {
event.stopPropagation();
event.preventDefault();
return false;
}
},
handleFocusOut: function(e) {
// Prevent a blur from firing if the blur was not user intended.
// This is a workaround for the return-key focus loss bug.
if (e.relatedTarget === null) {
event.stopPropagation();
event.preventDefault();
return false;
}
},
});