-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Improve the page title switch handling between search and doc #78921
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ function defocusSearchBar() { | |
var mouseMovedAfterSearch = true; | ||
|
||
var titleBeforeSearch = document.title; | ||
var searchTitle = null; | ||
|
||
function clearInputTimeout() { | ||
if (searchTimeout !== null) { | ||
|
@@ -169,6 +170,7 @@ function defocusSearchBar() { | |
addClass(main, "hidden"); | ||
removeClass(search, "hidden"); | ||
mouseMovedAfterSearch = false; | ||
document.title = searchTitle; | ||
} | ||
|
||
function hideSearchResults(search) { | ||
|
@@ -177,6 +179,7 @@ function defocusSearchBar() { | |
} | ||
addClass(search, "hidden"); | ||
removeClass(main, "hidden"); | ||
document.title = titleBeforeSearch; | ||
} | ||
|
||
// used for special search precedence | ||
|
@@ -374,7 +377,6 @@ function defocusSearchBar() { | |
clearInputTimeout(); | ||
ev.preventDefault(); | ||
hideSearchResults(search); | ||
document.title = titleBeforeSearch; | ||
} | ||
defocusSearchBar(); | ||
hideThemeButtonState(); | ||
|
@@ -1782,7 +1784,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. | ||
|
@@ -2736,6 +2738,7 @@ function defocusSearchBar() { | |
"", | ||
"?search=" + encodeURIComponent(search_input.value)); | ||
} | ||
document.title = searchTitle; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need another variable? Why not just directly modify
document.title
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, but it's simpler in case we come back to the search instead of regenerate it once again.