-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add crate filter parameter in URL #92735
Conversation
Some changes occurred in HTML/CSS/JS. |
This comment has been minimized.
This comment has been minimized.
26b36ee
to
50bd5fe
Compare
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.
Can you add a description of 0bd7b06fdf5c3cfa9e69728542bbc751b690a4e0 in the PR description?
if (!history.state && !params.search) { | ||
history.pushState(query, "", newURL); | ||
history.pushState(query.raw, "", newURL); |
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.
Why the change to query.raw here? Do we actually use this field of the history state?
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.
It was invalid before for some reason...
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.
Also, we don't use as it seems. So I guess it only makes it smaller?
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'll clarify: We should just pass null
here (and in the replaceState
call below) because we never use the resulting state in our popstate
event handler.
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.
Oh I see! Let's do this then!
if (ev.target.value === "All crates") { | ||
removeLocalStorageValue("saved-filter-crate"); | ||
// If we don't remove it from the URL, it'll be picked up again by the search. | ||
var params = searchState.getQueryStringParams(); | ||
var query = searchState.input.value.trim(); |
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.
Why is the "update URL" code path only activated when selecting "All crates"? It seems like we should always update the URL after the user makes a selection from the crates dropdown.
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.
Because it'll be done in the search for the other cases (ie, when we have a filter crate). This needs to be changed the current URL before we make the search so that the filter crate won't be picked since there isn't one anymore.
339a242
to
4b216f5
Compare
This comment has been minimized.
This comment has been minimized.
eeeb9d5
to
075a97c
Compare
Updated! |
This comment has been minimized.
This comment has been minimized.
@@ -134,6 +134,18 @@ function hideThemeButtonState() { | |||
themePicker.style.borderBottomLeftRadius = "3px"; | |||
} | |||
|
|||
function buildUrl(search, filterCrates) { |
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.
Let's add some JSDoc comments to this function, indicating that filterCrates is optional - or better yet, make it non-optional, and specify that it should be "null" for "no filter". Then we can remove the !== "undefined"
check below.
Also, let's move this function to search.js
. It's search-specific functionality, after all. And we shouldn't call it in hideResults; we should keep the code currently there, which doesn't care about search URL parameters.
In general, many of the things in searchState
can and should be moved to search.js eventually. What's in there is the stuff that had relationships with other things in main.js that I didn't want to untangle in my initial refactoring to split search.js.
// This function will be replaced once the search has been loaded. | ||
getFilterCrates: function() { |
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.
Let's not do this. Instead, let's move putBackSearch
into search.js
.
Since putBackSearch
is referenced from the event listener created in setup
, we'll also have to move the registration of that event listener into search.js
.
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.
👍
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.
Actually it's not possible because we load the search.js
file thanks to this event, making its functions unavailable until they're loaded (so after this event is triggered). I'll try to find another way.
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.
Nevermind, it's totally possible. I misunderstood what putBackSearch
was doing.
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.
In main.js we have:
setup: function() {
...
search_input.addEventListener("focus", function() {
searchState.putBackSearch(this);
search_input.origPlaceholder = searchState.input.placeholder;
search_input.placeholder = "Type your search here.";
loadSearch();
});
search_input.addEventListener("blur", function() {
search_input.placeholder = searchState.input.origPlaceholder;
});
Those addEventListener
calls should be moved into search.js
, in registerSearchEvents
. I think that should work. At the time that function runs, putBackSearch
will be available, even if it's defined inside search.js
.
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 still need to keep focus
in here because it loads the script. And to make it smoother, I'll keep the placeholder update before the search scripts are loaded.
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.
By the way, I've been thinking: maybe we can do the placeholder with CSS: https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder
#search-input::placeholder {
content: "Click or press 'S' for search...";
}
#search-input:focus::placeholder {
content: "Type your search 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.
I thought you didn't want to put text in the CSS? I remember something like that. Well, if so, I'll send a small PR for that. :)
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.
Just tried it, you can't set content
for ::placeholder
unfortunately...
if (!history.state && !params.search) { | ||
history.pushState(query, "", newURL); | ||
history.pushState(query.raw, "", newURL); |
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'll clarify: We should just pass null
here (and in the replaceState
call below) because we never use the resulting state in our popstate
event handler.
I had another thought about this: We could make the crate dropdown edit the textual search. For instance, if you are on https://doc.rust-lang.org/nightly/std/index.html?search=panic and select "core" from the drop-down, the URL would change to https://doc.rust-lang.org/nightly/std/index.html?search=panic+crate:core. And we would also parse |
That would mean strongly changing the search syntax (which I have another PR for :p). Better to be done as part of the other PR. Or in a follow-up, as you prefer. But changing the search input syntax isn't a good idea before the parser is merged. |
075a97c
to
c3b9dca
Compare
This comment has been minimized.
This comment has been minimized.
c3b9dca
to
829a047
Compare
I think I applied all your comments as much as I could. I moved parts of the event subscriptions on the search input in the |
@bors r+ rollup Looks great, thanks! |
📌 Commit 829a047 has been approved by |
…askrgr Rollup of 11 pull requests Successful merges: - rust-lang#92735 (Add crate filter parameter in URL) - rust-lang#93402 (Windows: Disable LLVM crash dialog boxes.) - rust-lang#93508 (Add rustdoc info to jsondocck output) - rust-lang#93551 (Add package.json in gitignore) - rust-lang#93555 (Link `try_exists` docs to `Path::exists`) - rust-lang#93585 (Missing tests for rust-lang#92630) - rust-lang#93593 (Fix ret > 1 bound if shadowed by const) - rust-lang#93630 (clippy::perf fixes) - rust-lang#93631 (rustc_mir_dataflow: use iter::once instead of Some().into_iter) - rust-lang#93632 (rustdoc: clippy::complexity fixes) - rust-lang#93638 (rustdoc: remove unused Hash impl) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #92621.
r? @jsha