From a03cba38f1aac7685f91957e9eaa00ab9962019d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 22 Apr 2021 13:50:23 +0200 Subject: [PATCH] Prevent control, shift and alt keys to make search input lose focus --- src/librustdoc/html/static/search.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index eb232a9608122..9fab435de49c8 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -935,6 +935,9 @@ window.initSearch = function(rawSearchIndex) { }); current += 1; }); + var SHIFT = 16; + var CTRL = 17; + var ALT = 18; var currentTab = searchState.currentTab; if (e.which === 38) { // up @@ -967,10 +970,10 @@ window.initSearch = function(rawSearchIndex) { e.preventDefault(); } else if (e.which === 13) { // return if (actives[currentTab].length) { - document.location.href = - actives[currentTab][0].getElementsByTagName("a")[0].href; + var elem = actives[currentTab][0].getElementsByTagName("a")[0]; + document.location.href = elem.href; } - } else if (e.which === 16) { // shift + } else if ([SHIFT, CTRL, ALT].indexOf(e.which) !== -1) { // Does nothing, it's just to avoid losing "focus" on the highlighted element. } else if (actives[currentTab].length > 0) { removeClass(actives[currentTab][0], "highlighted");