Skip to content

Commit a50f502

Browse files
authored
Rollup merge of #84433 - GuillaumeGomez:search-input-blur, r=jsha
Prevent control, shift and alt keys to make search input lose focus Part of #84384. r? ````@jsha````
2 parents a050a49 + a03cba3 commit a50f502

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/librustdoc/html/static/search.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ window.initSearch = function(rawSearchIndex) {
935935
});
936936
current += 1;
937937
});
938+
var SHIFT = 16;
939+
var CTRL = 17;
940+
var ALT = 18;
938941

939942
var currentTab = searchState.currentTab;
940943
if (e.which === 38) { // up
@@ -967,10 +970,10 @@ window.initSearch = function(rawSearchIndex) {
967970
e.preventDefault();
968971
} else if (e.which === 13) { // return
969972
if (actives[currentTab].length) {
970-
document.location.href =
971-
actives[currentTab][0].getElementsByTagName("a")[0].href;
973+
var elem = actives[currentTab][0].getElementsByTagName("a")[0];
974+
document.location.href = elem.href;
972975
}
973-
} else if (e.which === 16) { // shift
976+
} else if ([SHIFT, CTRL, ALT].indexOf(e.which) !== -1) {
974977
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
975978
} else if (actives[currentTab].length > 0) {
976979
removeClass(actives[currentTab][0], "highlighted");

0 commit comments

Comments
 (0)