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

Fix control + k keyboard shortcut #1571

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var addEventListenerForSearchKeyboard = () => {
!event.shiftKey &&
!event.altKey &&
// On Mac use ⌘, all other OS use Ctrl
(isMac
(useCommandKey
? event.metaKey && !event.ctrlKey
: !event.metaKey && event.ctrlKey) &&
// Case-insensitive so the shortcut still works with caps lock
Expand All @@ -261,27 +261,22 @@ var addEventListenerForSearchKeyboard = () => {

/**
* Find out if we're on a Mac
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
*
* Note: `navigator.platform` is deprecated; however MDN still recommends using
* it for the one specific use case of detecting whether a keyboard shortcut
* should use control or command:
* https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#examples
*/
var isMac = (navigator) => {
var platform = "";
if (
typeof navigator.userAgentData !== "undefined" &&
navigator.userAgentData != null
) {
platform = navigator.userAgentData.platform;
} else if (typeof navigator.platform !== "undefined") {
platform = navigator.platform;
}
return /mac.?os/.test(platform.toLowerCase());
};
var useCommandKey =
navigator.platform.indexOf("Mac") === 0 || navigator.platform === "iPhone";

/**
* Change the search hint to `meta key` if we are a Mac
*/

var changeSearchShortcutKey = () => {
let shortcuts = document.querySelectorAll(".search-button__kbd-shortcut");
if (isMac(window.navigator)) {
if (useCommandKey) {
shortcuts.forEach(
(f) => (f.querySelector("kbd.kbd-shortcut__modifier").innerText = "⌘")
);
Expand Down