From 42f9ecb841fa3103fa0b584254cbd482f250900c Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Fri, 22 Jun 2018 15:39:09 +0530 Subject: [PATCH] search: Remove a redundant preventDefault & export is_using_input_method. Return false is equivalent to preventDefault and stopPropogation. is_using_input_method is exported for node testing. --- static/js/search.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/static/js/search.js b/static/js/search.js index 7e94f213d4..417a54e955 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -2,11 +2,15 @@ var search = (function () { var exports = {}; -var is_using_input_method = false; +// Exported for unit testing +exports.is_using_input_method = false; function narrow_or_search_for_term(search_string) { var search_query_box = $("#search_query"); - if (is_using_input_method) { + if (exports.is_using_input_method) { + // Neither narrow nor search when using input tools as + // `updater` is also triggered when 'enter' is triggered + // while using input tool return search_query_box.val(); } ui_util.change_tab_to('#home'); @@ -82,7 +86,7 @@ exports.initialize = function () { // we suppress searching triggered by this enter key by checking // `is_using_input_method` before searching. // More details in the commit message that added this line. - is_using_input_method = true; + exports.is_using_input_method = true; }); searchbox_form.keydown(function (e) { @@ -92,12 +96,11 @@ exports.initialize = function () { // Don't submit the form so that the typeahead can instead // handle our Enter keypress. Any searching that needs // to be done will be handled in the keyup. - e.preventDefault(); return false; } }).keyup(function (e) { - if (is_using_input_method) { - is_using_input_method = false; + if (exports.is_using_input_method) { + exports.is_using_input_method = false; return; } var code = e.which;