Use ⌘ (KeyboardEvent.metaKey) with Pagefind search toggle on macOS#647
Conversation
✅ Deploy Preview for scientific-python-hugo-theme ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
⌘ + K works on the deploy preview at https://deploy-preview-647--scientific-python-hugo-theme.netlify.app/ on my macOS device. |
af59c39 to
b8451c0
Compare
⌘ (KeyboardEvent.metaKey) to be used with Pagefind search on macOS⌘ (KeyboardEvent.metaKey) to be used with Pagefind search toggle on macOS
⌘ (KeyboardEvent.metaKey) to be used with Pagefind search toggle on macOS⌘ (KeyboardEvent.metaKey) with Pagefind search toggle on macOS
stefanv
left a comment
There was a problem hiding this comment.
Minor suggestion, but also OK to merge without. Thank you @agriyakhetarpal!
| evt.key === "k" && | ||
| ((isMac && evt.metaKey) || (!isMac && evt.ctrlKey)) |
There was a problem hiding this comment.
I know this feels like a silly tweak, but if you'll humor me: could we swap these two lines around to mimic the order in which the keystroke is presented to the user?
There was a problem hiding this comment.
Haha, makes sense to me! Addressed in c2de9fd, apologies for the force push.
c3783ca to
c2de9fd
Compare
|
Hi, @stefanv! I hope it is okay to ping you again here? Full context: I'm trying to use this functionality downstream in pybamm-team/pybamm.org#210, which is where I noticed the problem and brought it up here – it would be great if this PR could be re-reviewed (and merged) soon! :) We usually point the theme submodule to the latest commit, so I have no issues with waiting for a new release with this change, the PR would be enough (I'll point to a release when it is up and ready here). |
|
I see, a type label needs to be added (this might have been a new CI addition since it wasn't there last week). |
|
Thanks very much @agriyakhetarpal! |

Description
This is a very small PR that should enable searching through the Command (⌘) key on macOS, which is the standard method to invoke the search bar followed by the PST. This allows both the use of ⌘ + K on macOS and the use of Ctrl + K on Linux and Windows. I've added the
KeyboardEvent.metaKeyproperty for this based on the MDN docs: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/metaKey.I don't think it is warranted to check for the host's operating system – I did think about it but since there is no reasonable alternative for this property on Windows-based keyboards besides the button for the Windows logo, this change is short and not too invasive in that sense. :)I added some additional code to the event listener present so that we get the right tooltips based on the host's operating system. :)