Skip to content

Commit

Permalink
Rollup merge of rust-lang#78921 - GuillaumeGomez:search-result-title,…
Browse files Browse the repository at this point in the history
… r=jyn514

Improve the page title switch handling between search and doc

The current behavior often "forgets" to update the page title when discarding/putting back the search results. This isn't optimal which is why I wrote this fix.

r? `@jyn514`
  • Loading branch information
GuillaumeGomez authored Nov 12, 2020
2 parents b31c678 + 46c921d commit 7b25abf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function defocusSearchBar() {
var mouseMovedAfterSearch = true;

var titleBeforeSearch = document.title;
var searchTitle = null;

function clearInputTimeout() {
if (searchTimeout !== null) {
Expand Down Expand Up @@ -169,6 +170,7 @@ function defocusSearchBar() {
addClass(main, "hidden");
removeClass(search, "hidden");
mouseMovedAfterSearch = false;
document.title = searchTitle;
}

function hideSearchResults(search) {
Expand All @@ -177,6 +179,7 @@ function defocusSearchBar() {
}
addClass(search, "hidden");
removeClass(main, "hidden");
document.title = titleBeforeSearch;
}

// used for special search precedence
Expand Down Expand Up @@ -374,7 +377,6 @@ function defocusSearchBar() {
clearInputTimeout();
ev.preventDefault();
hideSearchResults(search);
document.title = titleBeforeSearch;
}
defocusSearchBar();
hideThemeButtonState();
Expand Down Expand Up @@ -1791,7 +1793,7 @@ function defocusSearchBar() {
}

// Update document title to maintain a meaningful browser history
document.title = "Results for " + query.query + " - Rust";
searchTitle = "Results for " + query.query + " - Rust";

// Because searching is incremental by character, only the most
// recent search query is added to the browser history.
Expand Down Expand Up @@ -2745,6 +2747,7 @@ function defocusSearchBar() {
"",
"?search=" + encodeURIComponent(search_input.value));
}
document.title = searchTitle;
}
}

Expand Down

0 comments on commit 7b25abf

Please sign in to comment.