Skip to content
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 settings menu on clippy lints page #13187

Merged
merged 4 commits into from
Aug 11, 2024

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jul 30, 2024

It looks like this (when the menu is expanded):

Screenshot from 2024-08-06 21-36-41

Follow-up of #13178.

Someone pointed out that they should be able to disable the shortcuts on this page like it's the case for rustdoc and docs.rs. So here we go.

The first commit moves the style into its own file: it's much better for a web browser because it can then cache it.

The second one actually adds the new settings menu you can see above.

r? @Alexendoo

changelog: Add settings menu on clippy lints page

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 30, 2024
@Alexendoo
Copy link
Member

What is the use case for this?

@GuillaumeGomez
Copy link
Member Author

Maybe I didn't explain correctly, sorry about that. If you want the full context, you can see the mastodon discussion.

@Alexendoo
Copy link
Member

Okay it doesn't break Tridactyl but it does break / which is a Firefox native shortcut. I think we should just drop / in that case

@GuillaumeGomez
Copy link
Member Author

I think any plugin using s will also be impacted (I have some vim plugin in mind). So I think we'll need this setting in both cases.

@Alexendoo
Copy link
Member

I tried S in Tridactyl and it worked fine

@GuillaumeGomez
Copy link
Member Author

In rustdoc, we needed to implement this setting before we even had the / binding because of a vim plugin, hence why I mentioned it.

@xFrednet
Copy link
Member

Do we maybe want to move the theme menu also into the new settings menu?

@GuillaumeGomez
Copy link
Member Author

I can do that and have a display similar to what we have in rustdoc.

@Alexendoo
Copy link
Member

I don't like that / breaks native browser functionality (search in firefox) but if we decide to keep that I would be fine with an option

If we drop that part I would want to see an example of something S breaks. I tried a few things but couldn't find an example (Tridactyl, Vimium, NVDA)

@pacak
Copy link
Contributor

pacak commented Jul 31, 2024

/ breaks search in Firefox - not sure which part is responsible for it, s opens bookmark search in Tridactyl. Annoying, but that's something I can live without.

/ for search seem to be a common pattern for some websites, including GitHub so keeping it as is with an option to disable like a good choice. Alternatively it might make sense to keep the behavior consistent with all rust related websites. docs.rs uses S for search. But then crates.io uses / again...

@pacak
Copy link
Contributor

pacak commented Jul 31, 2024

I'm on Linux, last Firefox and Tridactyl 1.24.1

@Alexendoo
Copy link
Member

s opens bookmark search in Tridactyl. Annoying, but that's something I can live without.

To clarify if you press s on https://rust-lang.github.io/rust-clippy/master/index.html it focuses the search bar instead of opening bookmarks? I don't see that behaviour on my end

But yeah since pretty much every Rust related site, GitHub and Zulip all have shortcuts on / I think it's fair to say people who use it are used to it being overridden. So let's go with keeping / and doing #13187 (comment)

@pacak
Copy link
Contributor

pacak commented Aug 4, 2024

To clarify if you press s on https://rust-lang.github.io/rust-clippy/master/index.html it focuses the search bar instead of opening bookmarks?

Yes, it opens a search bookmarks and history prompt.

But yeah since pretty much every Rust related site, GitHub and Zulip all have shortcuts on / I think it's fair to say people who use it are used to it being overridden.

Hmm... No? On GitHub and docs.rs I can disable the shortcuts. I'm not using Zulip as much, but there's a ticket about adding an option to disable shortcuts - zulip/zulip#16863

@Alexendoo
Copy link
Member

That isn't to say that we shouldn't add an option, just that you've experienced it breaking

Interestingly crates.io behaves differently here, / gives precedence to the Firefox shortcut

@GuillaumeGomez
Copy link
Member Author

I still think that we should add this setting for users comfort and coherency with other rust platforms.

@Alexendoo
Copy link
Member

As I said, I'm fine with keeping / and adding the setting + #13187 (comment). The crates.io thing is tangential

@xFrednet xFrednet added the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Aug 6, 2024
@blyxyas
Copy link
Member

blyxyas commented Aug 6, 2024

An idea, disabling the button for mobile devices, (e.g. width <= 768) as they usually have no keyboard.

@GuillaumeGomez
Copy link
Member Author

I will simply hide it in this case (as long as we only have this setting). Although, you can have keyboards on mobile devices. 😉

@GuillaumeGomez
Copy link
Member Author

It was discussed on zulip and the conclusion was:

  • The team agrees with adding this setting
  • The team would prefer for the theme picking and this setting to be part of the same menu

I'll push an update making this change.

@flip1995 flip1995 removed the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Aug 6, 2024
@GuillaumeGomez
Copy link
Member Author

Both menus have been unified. I updated the screenshot in the first message.

@blyxyas
Copy link
Member

blyxyas commented Aug 6, 2024

Just checked, the new feature is responsive for mobile devices.

Comment on lines +546 to +512
try {
localStorage.setItem(`clippy-lint-list-${settingName}`, value);
} catch (e) { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop the try/catch, not sure why it was there before but we aren't storing enough to hit any quota errors

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not because of quota but because localStorage might not be supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Letting it throw would still be fine, we'd want to see the error in the console

Do we support any browsers where that's the case? I know way back when safari in private browsing behaved like that but that was fixed a long time ago also

It could happen on file: URLs but the site already doesn't work there due to the JSON file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it should definitely not fail. Not saving a setting is ok, crashing the script is not.

You can see the list of (not) supported platforms here. Basically, small web browsers used on some specific embed/mobile devices.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing in an event handler doesn't stop the script, it doesn't even unregister the handler

The grey is unknown not unsupported, the MDN sourced data isn't that thorough. A related entry from caniuse shows all the small ones support it with the exception of Opera Mini, but that's not relevant because it doesn't run JS

util/gh-pages/script.js Outdated Show resolved Hide resolved
Comment on lines 71 to 88
.directive('settingsDropdown', function ($document) {
return {
restrict: 'A',
link: function ($scope, $element, $attr) {
$element.bind('click', function () {
$element.toggleClass('open');
$element.addClass('open-recent');
});

$document.bind('click', function () {
if (!$element.hasClass('open-recent')) {
$element.removeClass('open');
}
$element.removeClass('open-recent');
})
}
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and themeDropdown are unused now, but I think the dropdown should use this directive over the blur based one so it behaves the same as the other dropdowns on the page

Currently clicking on the Disable keyboard shortcuts label or inside the box but not on a control closes the popup

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and themeDropdown are unused now, but I think the dropdown should use this directive over the blur based one so it behaves the same as the other dropdowns on the page

I'm planning to make them follow the same logic (not using vue/angular) because they make the JS very difficult to debug to understand what's going on. It also allows to have less code and less JS events.

Currently clicking on the Disable keyboard shortcuts label or inside the box but not on a control closes the popup

Ah indeed, forgot a tabindex="-1" on the menu. Now it's behaving as expected, thanks!

@GuillaumeGomez
Copy link
Member Author

Updated!

@Alexendoo
Copy link
Member

@bors r+

The remaining things are pretty minor so let's not let it hold this up, I've been thinking about removing our usage of angular anyway since not many people are familiar with it (me included). We've slowly been gaining a bigger split between angular and not angular parts

@bors
Copy link
Collaborator

bors commented Aug 11, 2024

📌 Commit 2ae6a49 has been approved by Alexendoo

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Aug 11, 2024

⌛ Testing commit 2ae6a49 with merge c7c8724...

@bors
Copy link
Collaborator

bors commented Aug 11, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Alexendoo
Pushing c7c8724 to master...

@bors bors merged commit c7c8724 into rust-lang:master Aug 11, 2024
5 checks passed
@GuillaumeGomez GuillaumeGomez deleted the settings-menu branch August 12, 2024 10:00
@GuillaumeGomez
Copy link
Member Author

@bors r+

The remaining things are pretty minor so let's not let it hold this up, I've been thinking about removing our usage of angular anyway since not many people are familiar with it (me included). We've slowly been gaining a bigger split between angular and not angular parts

I strongly agree and I'm working slowly towards this goal too. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants