Rollup merge of #72968 - integer32llc:docs-arrow-keys, r=GuillaumeGomez
Only highlight doc search results via mouseover if mouse has moved ## What happens - Go to https://doc.rust-lang.org/stable/std/index.html - Put your mouse cursor somewhere in the middle where search results will appear and then don't move the mouse - Press 's' to focus the search box - Type a query that brings up enough search results to go under where your mouse cursor is - Press the down arrow - The search result that is one below where your mouse cursor is will be highlighted. ## What I expected When not currently using the mouse, I expect doing a search and then pressing the down arrow to always highlight the first search result immediately below the search box. ## The fix This feels a bit hacky to me; I'm open to other solutions. This introduces a global JS var that keeps track of whether the person searching has moved their mouse after doing a search or not, and only uses the mouse position to highlight search results if the person HAS moved the mouse AFTER doing a search.
This commit is contained in:
commit
bf59152c01
|
@ -100,6 +100,8 @@ function defocusSearchBar() {
|
||||||
// 2 for "In Return Types"
|
// 2 for "In Return Types"
|
||||||
var currentTab = 0;
|
var currentTab = 0;
|
||||||
|
|
||||||
|
var mouseMovedAfterSearch = true;
|
||||||
|
|
||||||
var titleBeforeSearch = document.title;
|
var titleBeforeSearch = document.title;
|
||||||
|
|
||||||
function clearInputTimeout() {
|
function clearInputTimeout() {
|
||||||
|
@ -162,6 +164,7 @@ function defocusSearchBar() {
|
||||||
}
|
}
|
||||||
addClass(main, "hidden");
|
addClass(main, "hidden");
|
||||||
removeClass(search, "hidden");
|
removeClass(search, "hidden");
|
||||||
|
mouseMovedAfterSearch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSearchResults(search) {
|
function hideSearchResults(search) {
|
||||||
|
@ -424,6 +427,12 @@ function defocusSearchBar() {
|
||||||
document.addEventListener("keypress", handleShortcut);
|
document.addEventListener("keypress", handleShortcut);
|
||||||
document.addEventListener("keydown", handleShortcut);
|
document.addEventListener("keydown", handleShortcut);
|
||||||
|
|
||||||
|
function resetMouseMoved(ev) {
|
||||||
|
mouseMovedAfterSearch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("mousemove", resetMouseMoved);
|
||||||
|
|
||||||
var handleSourceHighlight = (function() {
|
var handleSourceHighlight = (function() {
|
||||||
var prev_line_id = 0;
|
var prev_line_id = 0;
|
||||||
|
|
||||||
|
@ -1353,6 +1362,7 @@ function defocusSearchBar() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var mouseover_func = function(e) {
|
var mouseover_func = function(e) {
|
||||||
|
if (mouseMovedAfterSearch) {
|
||||||
var el = e.target;
|
var el = e.target;
|
||||||
// to retrieve the real "owner" of the event.
|
// to retrieve the real "owner" of the event.
|
||||||
while (el.tagName !== "TR") {
|
while (el.tagName !== "TR") {
|
||||||
|
@ -1367,6 +1377,7 @@ function defocusSearchBar() {
|
||||||
});
|
});
|
||||||
addClass(el, "highlighted");
|
addClass(el, "highlighted");
|
||||||
}, 20);
|
}, 20);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
onEachLazy(document.getElementsByClassName("search-results"), function(e) {
|
onEachLazy(document.getElementsByClassName("search-results"), function(e) {
|
||||||
onEachLazy(e.getElementsByClassName("result"), function(i_e) {
|
onEachLazy(e.getElementsByClassName("result"), function(i_e) {
|
||||||
|
|
Loading…
Reference in New Issue