Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix search bar bug #50118

Merged
merged 1 commit into from Apr 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/librustdoc/html/static/main.js
Expand Up @@ -1375,13 +1375,17 @@

function search(e) {
var params = getQueryStringParams();
var query = getQuery(document.getElementsByClassName('search-input')[0].value.trim());
var search_input = document.getElementsByClassName('search-input')[0];
var query = getQuery(search_input.value.trim());

if (e) {
e.preventDefault();
}

if (!query.query || query.id === currentResults) {
if (query.query.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this bite us if this block is entered from !query.query? Can query.query be undefined here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this code, I'd say no. This is why I'm complaining about such conditions: it's difficult to understand what we're checking. I think the "real" condition here is if (query.query.length === 0 || query.id === currentResults) {.

putBackSearch(search_input);
}
return;
}

Expand Down Expand Up @@ -2072,19 +2076,23 @@
};
});

function putBackSearch(search_input) {
if (search_input.value !== "") {
addClass(document.getElementById("main"), "hidden");
removeClass(document.getElementById("search"), "hidden");
if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value,
"",
"?search=" + encodeURIComponent(search_input.value));
}
}
}

var search_input = document.getElementsByClassName("search-input")[0];

if (search_input) {
search_input.onfocus = function() {
if (search_input.value !== "") {
addClass(document.getElementById("main"), "hidden");
removeClass(document.getElementById("search"), "hidden");
if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value,
"",
"?search=" + encodeURIComponent(search_input.value));
}
}
putBackSearch(this);
};
}

Expand Down