Skip to content

Commit 6d41735

Browse files
Rollup merge of #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 0cd118d + 46c921d commit 6d41735

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();
@@ -1782,7 +1784,7 @@ function defocusSearchBar() {
17821784
}
17831785

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

17871789
// Because searching is incremental by character, only the most
17881790
// recent search query is added to the browser history.
@@ -2736,6 +2738,7 @@ function defocusSearchBar() {
27362738
"",
27372739
"?search=" + encodeURIComponent(search_input.value));
27382740
}
2741+
document.title = searchTitle;
27392742
}
27402743
}
27412744

0 commit comments

Comments
 (0)