-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Fix for #26016] In the docs js: support keyboard events for non-english keyboard layouts #26675
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Doesn't jQuery have some accessor which does all this for us? |
... and wasn't jquery removed recently? |
// Helper function for Keyboard events, | ||
// Get's the char from the keypress event | ||
// | ||
// This method is used because e.wich === x is not |
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.
which
I'm personally cool with not using jquery as much as possible. (jquery was removed from the book, not rustdoc) |
if (e.shiftKey && $('#help').hasClass('hidden')) { | ||
e.preventDefault(); | ||
$('#help').removeClass('hidden'); | ||
} | ||
} else if (e.which === 27) { // esc | ||
} else if (getChar(e) === 's' || getChar(e) === 'S') { |
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.
A deep part of my soul wants these to be cached in a variable, but then I remember this is javascript and it doesn't matter at all.
From rustbook, not rustdoc.
I'm worried about the JS becoming a pile of impenetrable lists of platform-specific details for all browsers and weird combinations. I'd much rather have something else take care of all this so we don't have to keep updating little bits like this. |
Same, very much so. |
If jQuery has a method I haven't found it, and I didn't add jQuery, it was already there :) I am totally pro using jQuery, because they do a lot better job at implementing browser support and abstractions. If there is a jQuery way for this I'm all in, but I didn't find any unfortunately. I could drop the helper function and replace it with just String.fromCharCode( e.which ) But I have no idea how it behaves in IE and I can't test it. |
@gankro removing jQuery is in my opinion not really a win. Because it offers so much convenience methods to shorten and simplify the code. It's a lot easier to maintain than vanilla js. On top of that you get good browser compatibility removing / reducing the need to hack your way through it ;) Also jQuery is used on a lot of websites loaded from the official CDN, if we used that CDN jQuery would most likely already be cached in the users browsers and thus practically bring it's load time to zero. |
jquery is well-known to generally have significant overhead over "plain" DOM manipulations. Rustdoc being snappy is important to me. Especially as we make its render more dynamic in the future. |
That said, there's a reason I don't push hard for removing it ;) |
I am not totally convinced about the pure js vs jQuery performance. Sure jQuery has a bit of overhead because it has support for most browsers etc. But it is designed by a bunch of people who are a lot more skilled than myself and probably most contributors here, they probably know how to get that last bit of performance out of it. Well written vanilla js can be faster than jQuery but it has to be well written ;) One thing that comes to mind though is that it's a lot easier to use other css selectors instead of id's with jQuery because of the convenience methods, and this can drastically slow down the dom manipulations. I could be wrong, but I think we still have a pretty big marge before we begin to have performance issues in the rustdoc :) |
Hm ok, if there's nothing in jquery to already do this then it's probably fine. Can you squash the commits together as well? |
Done :) |
Like explained in #26016, typing `?` had no effect with non-english keyboard layouts in the docs. This patch seems to resolve this issue, **tested with AZERTY keyboard in Google Chrome and Firefox**. I haven't tested it with more exotic keyboard layouts or with other browsers though. This code is based on the information found on: http://javascript.info/tutorial/keyboard-events **More specifically:** > The only event which reliably provides the character is keypress. **And** >``` // event.type must be keypress function getChar(event) { if (event.which == null) { return String.fromCharCode(event.keyCode) // IE } else if (event.which!=0 && event.charCode!=0) { return String.fromCharCode(event.which) // the rest } else { return null // special key } } ``` `?` and `S` work, `escape` however does not (on an Azerty keyboard). It would be good if some people could test it with other browsers and keyboard layouts: http://www.mathieudavid.org/test/rustdoc/std/index.html **Edit:** - swedish layout works on Firefox and Chromium - french (azerty) mac layout works on Safari
We should endeavour to back-port client-side rustdoc fixes as much as possible. |
Not accepted. |
Like explained in #26016, typing
?
had no effect with non-english keyboard layouts in the docs.This patch seems to resolve this issue, tested with AZERTY keyboard in Google Chrome and Firefox. I haven't tested it with more exotic keyboard layouts or with other browsers though.
This code is based on the information found on: http://javascript.info/tutorial/keyboard-events
More specifically:
And
?
andS
work,escape
however does not (on an Azerty keyboard).It would be good if some people could test it with other browsers and keyboard layouts: http://www.mathieudavid.org/test/rustdoc/std/index.html
Edit: