-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Move crate drop-down to search results page #92490
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 |
---|---|---|
|
@@ -1085,7 +1085,7 @@ window.initSearch = function(rawSearchIndex) { | |
return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>"; | ||
} | ||
|
||
function showResults(results, go_to_first) { | ||
function showResults(results, go_to_first, filterCrates) { | ||
var search = searchState.outputElement(); | ||
if (go_to_first || (results.others.length === 1 | ||
&& getSettingValue("go-to-only-result") === "true" | ||
|
@@ -1126,9 +1126,16 @@ window.initSearch = function(rawSearchIndex) { | |
} | ||
} | ||
|
||
var output = "<h1>Results for " + escape(query.query) + | ||
let crates = `<select id="crate-search"><option value="All crates">All crates</option>`; | ||
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. Isn't eslint complaining when you use backticks without 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. Nope! I wouldn't expect it to. Backticks do a bunch of things besides template expansion. They also allow multiline strings, and serve as a different delimiter so you don't have to backslash double quotes ( |
||
for (let c of window.ALL_CRATES) { | ||
crates += `<option value="${c}" ${c == filterCrates && "selected"}>${c}</option>`; | ||
} | ||
crates += `</select>`; | ||
var output = `<div id="search-settings"> | ||
<h1 class="search-results-title">Results for ${escape(query.query)} ` + | ||
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" + | ||
"<div id=\"titles\">" + | ||
` in ${crates} ` + | ||
`</div><div id="titles">` + | ||
makeTabHeader(0, "In Names", ret_others[1]) + | ||
makeTabHeader(1, "In Parameters", ret_in_args[1]) + | ||
makeTabHeader(2, "In Return Types", ret_returned[1]) + | ||
|
@@ -1141,6 +1148,7 @@ window.initSearch = function(rawSearchIndex) { | |
resultsElem.appendChild(ret_returned[0]); | ||
|
||
search.innerHTML = output; | ||
document.getElementById("crate-search").addEventListener("input", updateCrate); | ||
search.appendChild(resultsElem); | ||
// Reset focused elements. | ||
searchState.focusedByTab = [null, null, null]; | ||
|
@@ -1316,7 +1324,8 @@ window.initSearch = function(rawSearchIndex) { | |
} | ||
|
||
var filterCrates = getFilterCrates(); | ||
showResults(execSearch(query, searchWords, filterCrates), params["go_to_first"]); | ||
showResults(execSearch(query, searchWords, filterCrates), | ||
params["go_to_first"], filterCrates); | ||
} | ||
|
||
function buildIndex(rawSearchIndex) { | ||
|
@@ -1552,19 +1561,6 @@ window.initSearch = function(rawSearchIndex) { | |
} | ||
}); | ||
|
||
|
||
var selectCrate = document.getElementById("crate-search"); | ||
if (selectCrate) { | ||
selectCrate.onchange = function() { | ||
updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value); | ||
// In case you "cut" the entry from the search input, then change the crate filter | ||
// before paste back the previous search, you get the old search results without | ||
// the filter. To prevent this, we need to remove the previous results. | ||
currentResults = null; | ||
search(undefined, true); | ||
}; | ||
} | ||
|
||
// Push and pop states are used to add search results to the browser | ||
// history. | ||
if (searchState.browserSupportsHistoryApi()) { | ||
|
@@ -1616,6 +1612,15 @@ window.initSearch = function(rawSearchIndex) { | |
}; | ||
} | ||
|
||
function updateCrate(ev) { | ||
updateLocalStorage("rustdoc-saved-filter-crate", ev.target.value); | ||
// In case you "cut" the entry from the search input, then change the crate filter | ||
// before paste back the previous search, you get the old search results without | ||
// the filter. To prevent this, we need to remove the previous results. | ||
currentResults = null; | ||
search(undefined, true); | ||
} | ||
|
||
searchWords = buildIndex(rawSearchIndex); | ||
registerSearchEvents(); | ||
// If there's a search term in the URL, execute the search now. | ||
|
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 wanted to make this change in bigger PR but I guess it's fine... Don't forget to update the comment just above please.
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.
I actually think a giant PR adding ES6 features wherever possible, and updating the linter at the same time would be a bad idea. The way we should do it is like I'm doing here:
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.
Like I said, it's fine. 😉