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

Prevent automatic page change when using history #75806

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,14 +1576,18 @@ function defocusSearchBar() {
}

function showResults(results) {
if (results.others.length === 1 &&
getCurrentValue("rustdoc-go-to-only-result") === "true") {
var search = getSearchElement();
if (results.others.length === 1
&& getCurrentValue("rustdoc-go-to-only-result") === "true"
&& (!search.firstChild || search.firstChild.innerText !== getSearchLoadingText()))
Copy link
Contributor

Choose a reason for hiding this comment

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

In what cases will !search.firstChild happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

By default it's empty. So it's not empty when you already performed a search and "cancelled" it (meaning, you pressed ESC or remove all the content from the search input) or if there is the "loading search result" text when you arrive on the page with a search parameter in your URL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does not look that straightforward to me but I understand after you explain.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a comment then.

{
var elem = document.createElement("a");
elem.href = results.others[0].href;
elem.style.display = "none";
// For firefox, we need the element to be in the DOM so it can be clicked.
document.body.appendChild(elem);
elem.click();
return;
}
var query = getQuery(search_input.value);

Expand All @@ -1602,7 +1606,6 @@ function defocusSearchBar() {
"</div><div id=\"results\">" +
ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";

var search = getSearchElement();
search.innerHTML = output;
showSearchResults(search);
var tds = search.getElementsByTagName("td");
Expand Down Expand Up @@ -2679,6 +2682,10 @@ function defocusSearchBar() {
}
}

function getSearchLoadingText() {
return "Loading search results...";
}

if (search_input) {
search_input.onfocus = function() {
putBackSearch(this);
Expand All @@ -2688,7 +2695,7 @@ function defocusSearchBar() {
var params = getQueryStringParams();
if (params && params.search) {
var search = getSearchElement();
search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>";
search.innerHTML = "<h3 style=\"text-align: center;\">" + getSearchLoadingText() + "</h3>";
showSearchResults(search);
}

Expand Down