@@ -241,7 +241,7 @@ var addEventListenerForSearchKeyboard = () => {
241
241
! event . shiftKey &&
242
242
! event . altKey &&
243
243
// On Mac use ⌘, all other OS use Ctrl
244
- ( isMac
244
+ ( useCommandKey
245
245
? event . metaKey && ! event . ctrlKey
246
246
: ! event . metaKey && event . ctrlKey ) &&
247
247
// Case-insensitive so the shortcut still works with caps lock
@@ -260,28 +260,23 @@ var addEventListenerForSearchKeyboard = () => {
260
260
} ;
261
261
262
262
/**
263
- * Find out if we're on a Mac
263
+ * If the user is on a Mac, use command (⌘) instead of control (ctrl) key
264
+ *
265
+ * Note: `navigator.platform` is deprecated; however MDN still recommends using
266
+ * it for the one specific use case of detecting whether a keyboard shortcut
267
+ * should use control or command:
268
+ * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#examples
264
269
*/
265
- var isMac = ( navigator ) => {
266
- var platform = "" ;
267
- if (
268
- typeof navigator . userAgentData !== "undefined" &&
269
- navigator . userAgentData != null
270
- ) {
271
- platform = navigator . userAgentData . platform ;
272
- } else if ( typeof navigator . platform !== "undefined" ) {
273
- platform = navigator . platform ;
274
- }
275
- return / m a c .? o s / . test ( platform . toLowerCase ( ) ) ;
276
- } ;
270
+ var useCommandKey =
271
+ navigator . platform . indexOf ( "Mac" ) === 0 || navigator . platform === "iPhone" ;
277
272
278
273
/**
279
274
* Change the search hint to `meta key` if we are a Mac
280
275
*/
281
276
282
277
var changeSearchShortcutKey = ( ) => {
283
278
let shortcuts = document . querySelectorAll ( ".search-button__kbd-shortcut" ) ;
284
- if ( isMac ( window . navigator ) ) {
279
+ if ( useCommandKey ) {
285
280
shortcuts . forEach (
286
281
( f ) => ( f . querySelector ( "kbd.kbd-shortcut__modifier" ) . innerText = "⌘" )
287
282
) ;
0 commit comments