From c807dd29e43f371ec1f112de647a2f1bef7e18bb Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 24 Jan 2014 13:35:58 -0800 Subject: [PATCH] Prevent TextBox from blurring unless explicity by user. --- .../notebook/js/widgets/widget_string.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/widgets/widget_string.js b/IPython/html/static/notebook/js/widgets/widget_string.js index 7ae3890cb..d4fd3d899 100644 --- a/IPython/html/static/notebook/js/widgets/widget_string.js +++ b/IPython/html/static/notebook/js/widgets/widget_string.js @@ -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; } }, });