From 5457bd6041259697ecf5774f4561719081b7fe7e Mon Sep 17 00:00:00 2001 From: Gabriel Fouasnon Date: Wed, 22 Nov 2023 16:29:30 -0600 Subject: [PATCH 1/2] Fix control + k keyboard shortcut --- .../assets/scripts/pydata-sphinx-theme.js | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js index 57c329c57..ce13ea19d 100644 --- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js +++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js @@ -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 @@ -261,19 +261,14 @@ var addEventListenerForSearchKeyboard = () => { /** * Find out if we're on a Mac + * + * 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 @@ -281,7 +276,7 @@ var isMac = (navigator) => { 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 = "⌘") ); From d95ff1a99b0eb98361b8b054d95c82b8a28c618d Mon Sep 17 00:00:00 2001 From: gabalafou Date: Wed, 22 Nov 2023 16:44:39 -0600 Subject: [PATCH 2/2] Update src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js --- src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js index ce13ea19d..30765c995 100644 --- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js +++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js @@ -260,7 +260,7 @@ var addEventListenerForSearchKeyboard = () => { }; /** - * Find out if we're on a Mac + * If the user is on a Mac, use command (⌘) instead of control (ctrl) key * * Note: `navigator.platform` is deprecated; however MDN still recommends using * it for the one specific use case of detecting whether a keyboard shortcut