Skip to content

Commit f368a18

Browse files
committed
Rollup merge of rust-lang#28736 - nagisa:rustdocjsfix, r=alexcrichton
2 parents bfb2603 + f38bc2c commit f368a18

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/librustdoc/html/static/main.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
$(document).on("keypress", handleShortcut);
134134
$(document).on("keydown", handleShortcut);
135135
$(document).on("click", function(ev) {
136-
if (!$(e.target).closest("#help > div").length) {
136+
if (!$(ev.target).closest("#help > div").length) {
137137
$("#help").addClass("hidden");
138138
$("body").removeClass("blur");
139139
}
@@ -515,23 +515,20 @@
515515
var $active = $results.filter('.highlighted');
516516

517517
if (e.which === 38) { // up
518-
e.preventDefault();
519518
if (!$active.length || !$active.prev()) {
520519
return;
521520
}
522521

523522
$active.prev().addClass('highlighted');
524523
$active.removeClass('highlighted');
525524
} else if (e.which === 40) { // down
526-
e.preventDefault();
527525
if (!$active.length) {
528526
$results.first().addClass('highlighted');
529527
} else if ($active.next().length) {
530528
$active.next().addClass('highlighted');
531529
$active.removeClass('highlighted');
532530
}
533531
} else if (e.which === 13) { // return
534-
e.preventDefault();
535532
if ($active.length) {
536533
document.location.href = $active.find('a').prop('href');
537534
}
@@ -722,20 +719,29 @@
722719
}
723720

724721
function startSearch() {
725-
726-
$(".search-input").on("keyup",function() {
722+
var searchTimeout;
723+
$(".search-input").on("keyup input",function() {
724+
clearTimeout(searchTimeout);
727725
if ($(this).val().length === 0) {
728726
window.history.replaceState("", "std - Rust", "?search=");
729727
$('#main.content').removeClass('hidden');
730728
$('#search.content').addClass('hidden');
729+
} else {
730+
searchTimeout = setTimeout(search, 500);
731731
}
732732
});
733-
734-
var keyUpTimeout;
735-
$('.do-search').on('click', search);
736-
$('.search-input').on('keyup', function() {
737-
clearTimeout(keyUpTimeout);
738-
keyUpTimeout = setTimeout(search, 500);
733+
$('.search-form').on('submit', function(e){
734+
e.preventDefault();
735+
clearTimeout(searchTimeout);
736+
search();
737+
});
738+
$('.search-input').on('change paste', function(e) {
739+
// Do NOT e.preventDefault() here. It will prevent pasting.
740+
clearTimeout(searchTimeout);
741+
// zero-timeout necessary here because at the time of event handler execution the
742+
// pasted content is not in the input field yet. Shouldn’t make any difference for
743+
// change, though.
744+
setTimeout(search, 0);
739745
});
740746

741747
// Push and pop states are used to add search results to the browser

0 commit comments

Comments
 (0)