aaranxu / adidoks

AdiDoks is a mordern documentation theme, which is a port of the Hugo theme Doks for Zola.
https://adidoks.org
MIT License
227 stars 81 forks source link

Wrong keycode for focusing the search (I can prepare a PR) #58

Open mr-pascal opened 1 year ago

mr-pascal commented 1 year ago

In two places, there is a check if a certain keydown event was triggered by the 191 key code to e.g. focus on the input search bar. Even though I think this is wrong or at least might not work on every machine.

At least on my (Ubuntu) Machine, using Brave Browser typing / doesn't result in the key code 191 but in 55 which is the keyCode for 7.

So instead of checking for the keyCode in the two places mentioned further down, but also in the other places I would suggest to use the event.key property instead. So I would replace e.keyCode === 191 with e.key === '/'.

I verified with the following snippet, that it works accordingly. Also you can see that I type in / but the keyCode 55 is printed to the console. Also after changing this locally the focus on the search input worked again.

document.addEventListener('keydown', function(e){
    console.log(e.keyCode);
    console.log(e.key);
});

image

The two places: https://github.com/aaranxu/adidoks/blob/6887e4e27144ac7f9bef6fe4287d8dbb2ceca87f/static/index.js#L8 https://github.com/aaranxu/adidoks/blob/e03e8a5098660b9fcf7ea9ad136024cc98723a1f/static/js/search.js#L8

I don't mind preparing a PR/fix for the 191 case, but can also do so for the other ones.