downforacross / downforacross.com

Web frontend for downforacross.com -- continuation of stevenhao/crosswordsio
https://downforacrosscom.downforacross1.now.sh
MIT License
220 stars 92 forks source link

Keyboard shortcuts to check/reveal don't work on Mac? #307

Open mjbaldwin opened 5 months ago

mjbaldwin commented 5 months ago

Hi, I'm trying to use the advertised keyboard shortcuts:

Alt + S, W, or P Check Square, Word, or Puzzle Alt + Shift + S, W, or P Reveal Square, Word, or Puzzle

But I can't get them to work on my Mac -- not on Chrome and not on Safari.

Obviously Macs don't have an Alt key, they have an Option key, but they're generally the same. But I tried each of Cmd, Opt, and Ctrl with S, W, P, and none of them do a check or reveal.

Am I missing something on how to get this working? Or is it a bug?

Thanks!

kumar-ish commented 5 months ago

I believe this is because Macs transform combinations of keys and Option to not-those-characters (I can't exactly tell what this feature is called, but it's the same thing as being described in this StackOverflow post) -- e.g. if I press down on (in this textarea, on Github) Option + S on my Mac, I get ß.

So when the downforacross.com frontend is reading the key property of that key press event, it's detecting the key as ß. These lines are the ones that have to be changed (in the hackiest way possible in that SO post I linked) are here.

kumar-ish commented 5 months ago

AFAICT, there's no way for Macs to not do that (i.e. it's not like we can disable that on the browser level, and handle it the same way that we're doing now). Note that there's also a different set of transformations that happen for Option+Shift+key's.

I would recommend that we just add those transformations (i.e. for S, W and P respectively -- ß, ∑, π when pressing Option, and Í, „, and ∏ when pressing Option+Shift -- this is the case in most of the English keyboards available (i.e. everything but Irish and Indian)) in the lines in those permalinks. Seeing as those are not valid characters in crosswords anyways, there should be no conflict with other parts of the codebase.

The other alternative would be to simply change the shortcuts. However, some people would be used to the existing behaviour, and would need to learn the changed ones. So this previous option is non-invasive to existing users.

I've added / tested those changes in this branch, if the former behaviour is desirable.

mjbaldwin commented 5 months ago

Yup. In case it helps, since I'm assuming you're not on Macs -- I used this link to generate a series of keyboard events for Opt+S on my Mac in Chrome:

image

And for Opt+Shift+S:

image

I think your approach will work fine.

The alternative approach would be to use the "code" instead of the "key", will still returns the unmodified "S" in this case, possibly around line 279:

https://github.com/downforacross/downforacross.com/blob/56c56864194c6cb18423408aa79d4e3f8f3a9d43/src/components/Player/GridControls.js#L279

I'm not sure if that would break other things that depend on existing behavior though.