Skip to content

Commit

Permalink
Only highlight results via mouseover if mouse has moved
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Jun 4, 2020
1 parent f3fadf6 commit 1bc4e45
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ function defocusSearchBar() {
// 2 for "In Return Types"
var currentTab = 0;

var mouseMovedAfterSearch = true;

var titleBeforeSearch = document.title;

function clearInputTimeout() {
Expand Down Expand Up @@ -162,6 +164,7 @@ function defocusSearchBar() {
}
addClass(main, "hidden");
removeClass(search, "hidden");
mouseMovedAfterSearch = false;
}

function hideSearchResults(search) {
Expand Down Expand Up @@ -424,6 +427,12 @@ function defocusSearchBar() {
document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);

function resetMouseMoved(ev) {
mouseMovedAfterSearch = true;
}

document.addEventListener("mousemove", resetMouseMoved);

var handleSourceHighlight = (function() {
var prev_line_id = 0;

Expand Down Expand Up @@ -1353,20 +1362,22 @@ function defocusSearchBar() {
}
};
var mouseover_func = function(e) {
var el = e.target;
// to retrieve the real "owner" of the event.
while (el.tagName !== "TR") {
el = el.parentNode;
}
clearTimeout(hoverTimeout);
hoverTimeout = setTimeout(function() {
onEachLazy(document.getElementsByClassName("search-results"), function(e) {
onEachLazy(e.getElementsByClassName("result"), function(i_e) {
removeClass(i_e, "highlighted");
if (mouseMovedAfterSearch) {
var el = e.target;
// to retrieve the real "owner" of the event.
while (el.tagName !== "TR") {
el = el.parentNode;
}
clearTimeout(hoverTimeout);
hoverTimeout = setTimeout(function() {
onEachLazy(document.getElementsByClassName("search-results"), function(e) {
onEachLazy(e.getElementsByClassName("result"), function(i_e) {
removeClass(i_e, "highlighted");
});
});
});
addClass(el, "highlighted");
}, 20);
addClass(el, "highlighted");
}, 20);
}
};
onEachLazy(document.getElementsByClassName("search-results"), function(e) {
onEachLazy(e.getElementsByClassName("result"), function(i_e) {
Expand Down

0 comments on commit 1bc4e45

Please sign in to comment.