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

Keyboard zoom #293

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Keyboard zoom #293

wants to merge 4 commits into from

Conversation

eridilla
Copy link

Issue #189

@@ -22,6 +22,9 @@
<img class="icon-dismiss invisible" src="/common/img/close.svg" width="24" height="24" tabindex="0" data-i18n data-i18n-aria-label="__MSG_dismissIconDescription__"></span>
</div>
</div>
<div>
<p id="zoomTooltip">Alt +/- to zoom</p>
Copy link
Owner

Choose a reason for hiding this comment

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

That would need to be localized, otherwise, it's static in all languages.

But let's first see whether that is a the appropriate approach.

For more information, please see the MDN guide on how to localize WebExtensions and our internationalization (i18n) guide.

function zoomQrCode(e) {
var evtobj = window.event ? event : e;
if (evtobj.keyCode == 61 && evtobj.altKey && qrLastSize < 440) {
setNewQrCodeSize(qrLastSize + 30, true);
Copy link
Owner

Choose a reason for hiding this comment

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

Note setNewQrCodeSize may – depending on

if (qrCodeSizeOption.sizeType === "remember") {
save the size to add-on storage's, too. THough thinking about it, that makes sense, because it is then just persisted.

So yeah, I dunno whether my idea of remembering it additionally, was a good idea, but it seems okay'ish.

}

// zoom listener
document.onkeydown = zoomQrCode;
Copy link
Owner

Choose a reason for hiding this comment

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

IMHO better use addEventListener it's the modern and better syntax.


localStorage.setItem("lastSize", qrLastSize);
}
if (evtobj.keyCode == 173 && evtobj.altKey && qrLastSize > 50) {
Copy link
Owner

Choose a reason for hiding this comment

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

keyCode is kinda deprecated, see the warning at https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode, so let's better switch to alternatives, if possible.

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

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

Hi @eridilla,
thanks for your first contribution to this project! 🎉 👍 🏅
I hope you'll like this project and enjoy hacking on it… 😃

I am a little critical with having such a non-standard tooltip like Alt+ (+/-) for zoomimng, given that as I said in #189 (comment) mouse wheel and zoom also already works.

It's a good idea to give a hint, but maybe that is a little too obtrusive (at best it should work intuitively, but I see why that was not possible, as you've explained in #189 (comment)).

So the approach I would recommend, as that is not the most important feature here, would be to add a tip via the (already integrated) RandomTips library.

Also I need to test this out, of course.


A general note, please: Next time avoid reformatting many unrelated files, that are not related to the change. The format looks okay, so I will keep that (dunno how that happened? EsLint?), but it makes reviewing harder. Or, at least, do it in a separate commit.

Also, BTW: Next time, try to avoid doing a pull request from the master branch, because you can run into problems when you have a "non-clean" master that does not follow this repo here (i.e. "upstream"). See this article for details. Anyway, this is only a tip for the next time. 😃

@eridilla
Copy link
Author

eridilla commented Dec 20, 2022

Hey @rugk,
thank you for the review and the tips!

I looked at your comments and fixed accordingly. I rewrote the key press listener to the addEventListener function and replaced the deprecated keyCodes. I removed the div with the tooltip and added the tip to Tips.js and the english messages.json.

When I was trying out the random tip I got it to show up incorrectly a few times, then changed my code to look like the other tips and then I couldn't get any tip to show at all so I hope the additions I made are correct.

Also sorry about the reformatting, Prettier did that on it's own, next time I'll check harder to make sure that doesn't happen again. 😅

Thank you once again for your comments and I hope these changes are better. 😀

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

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

Thanks a lot, yeah that looks good now. Only one minor nitpick.

Do you want to add yourself to the Contributors file?

function zoomQrCode(e) {
var evtobj = window.event ? event : e;
if (evtobj.keyCode == 61 && evtobj.altKey && qrLastSize < 440) {
document.addEventListener('keydown', function(event) {
Copy link
Owner

Choose a reason for hiding this comment

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

naaaw, I would still keep the function zoomQrCode or so you had… You can just reference that here AFAIK.

@rugk rugk added this to the next milestone Dec 30, 2022
localStorage.setItem("lastSize", qrLastSize);
}
if (event.key == '-' && event.altKey && qrLastSize > 50) {
setNewQrCodeSize(qrLastSize - 30, true);
Copy link
Owner

Choose a reason for hiding this comment

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

Ah and could you extract the 30 into a const KEYBOARD_ZOOM_SIZE = 30 constant or so? Magic numbers are not a good practise in source code that should be readable… 🙃

Copy link
Owner

Choose a reason for hiding this comment

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

Same for 50 which I assume is something as MINIMAL_ZOOM_SIZE or so?

Just place the constants at the top, there should be some, already. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants