Skip to content

Commit 7b25abf

Browse files
Rollup merge of rust-lang#78921 - GuillaumeGomez:search-result-title, 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`
2 parents b31c678 + 46c921d commit 7b25abf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/librustdoc/html/static/main.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function defocusSearchBar() {
113113
var mouseMovedAfterSearch = true;
114114

115115
var titleBeforeSearch = document.title;
116+
var searchTitle = null;
116117

117118
function clearInputTimeout() {
118119
if (searchTimeout !== null) {
@@ -169,6 +170,7 @@ function defocusSearchBar() {
169170
addClass(main, "hidden");
170171
removeClass(search, "hidden");
171172
mouseMovedAfterSearch = false;
173+
document.title = searchTitle;
172174
}
173175

174176
function hideSearchResults(search) {
@@ -177,6 +179,7 @@ function defocusSearchBar() {
177179
}
178180
addClass(search, "hidden");
179181
removeClass(main, "hidden");
182+
document.title = titleBeforeSearch;
180183
}
181184

182185
// used for special search precedence
@@ -374,7 +377,6 @@ function defocusSearchBar() {
374377
clearInputTimeout();
375378
ev.preventDefault();
376379
hideSearchResults(search);
377-
document.title = titleBeforeSearch;
378380
}
379381
defocusSearchBar();
380382
hideThemeButtonState();
@@ -1791,7 +1793,7 @@ function defocusSearchBar() {
17911793
}
17921794

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

17961798
// Because searching is incremental by character, only the most
17971799
// recent search query is added to the browser history.
@@ -2745,6 +2747,7 @@ function defocusSearchBar() {
27452747
"",
27462748
"?search=" + encodeURIComponent(search_input.value));
27472749
}
2750+
document.title = searchTitle;
27482751
}
27492752
}
27502753

0 commit comments

Comments
 (0)