diff --git a/packages/block-editor/src/components/inserter-list-item/index.js b/packages/block-editor/src/components/inserter-list-item/index.js index f791dfb5fdc2ae..d24df56df241fe 100644 --- a/packages/block-editor/src/components/inserter-list-item/index.js +++ b/packages/block-editor/src/components/inserter-list-item/index.js @@ -12,7 +12,7 @@ import { createBlocksFromInnerBlocksTemplate, } from '@wordpress/blocks'; import { __experimentalTruncate as Truncate } from '@wordpress/components'; -import { ENTER } from '@wordpress/keycodes'; +import { ENTER, isAppleOS } from '@wordpress/keycodes'; /** * Internal dependencies @@ -21,22 +21,6 @@ import BlockIcon from '../block-icon'; import { InserterListboxItem } from '../inserter-listbox'; import InserterDraggableBlocks from '../inserter-draggable-blocks'; -/** - * Return true if platform is MacOS. - * - * @param {Object} _window window object by default; used for DI testing. - * - * @return {boolean} True if MacOS; false otherwise. - */ -function isAppleOS( _window = window ) { - const { platform } = _window.navigator; - - return ( - platform.indexOf( 'Mac' ) !== -1 || - [ 'iPad', 'iPhone' ].includes( platform ) - ); -} - function InserterListItem( { className, isFirst, diff --git a/packages/compose/src/hooks/use-keyboard-shortcut/index.js b/packages/compose/src/hooks/use-keyboard-shortcut/index.js index 4e1612bc11330e..992f8e4fcc245b 100644 --- a/packages/compose/src/hooks/use-keyboard-shortcut/index.js +++ b/packages/compose/src/hooks/use-keyboard-shortcut/index.js @@ -3,12 +3,13 @@ */ import Mousetrap from 'mousetrap'; import 'mousetrap/plugins/global-bind/mousetrap-global-bind'; -import { includes, castArray } from 'lodash'; +import { castArray } from 'lodash'; /** * WordPress dependencies */ import { useEffect, useRef } from '@wordpress/element'; +import { isAppleOS } from '@wordpress/keycodes'; /** * A block selection object. @@ -21,22 +22,6 @@ import { useEffect, useRef } from '@wordpress/element'; * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event. */ -/** - * Return true if platform is MacOS. - * - * @param {Window} [_window] window object by default; used for DI testing. - * - * @return {boolean} True if MacOS; false otherwise. - */ -function isAppleOS( _window = window ) { - const { platform } = _window.navigator; - - return ( - platform.indexOf( 'Mac' ) !== -1 || - includes( [ 'iPad', 'iPhone' ], platform ) - ); -} - /* eslint-disable jsdoc/valid-types */ /** * Attach a keyboard shortcut handler. diff --git a/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js b/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js index 10c64efe4575b5..8e8f4c42ca6dd6 100644 --- a/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js +++ b/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js @@ -6,6 +6,7 @@ import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { BlockEditorKeyboardShortcuts } from '@wordpress/block-editor'; import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; +import { isAppleOS } from '@wordpress/keycodes'; function EditorKeyboardShortcutsRegister() { // Registering the shortcuts. @@ -39,6 +40,18 @@ function EditorKeyboardShortcutsRegister() { modifier: 'primaryShift', character: 'z', }, + // Disable on Apple OS because it conflicts with the browser's + // history shortcut. It's a fine alias for both Windows and Linux. + // Since there's no conflict for Ctrl+Shift+Z on both Windows and + // Linux, we keep it as the default for consistency. + aliases: isAppleOS() + ? [] + : [ + { + modifier: 'primary', + character: 'y', + }, + ], } ); }, [ registerShortcut ] ); diff --git a/packages/keycodes/README.md b/packages/keycodes/README.md index 8aeb4000d57780..99557a44b26310 100644 --- a/packages/keycodes/README.md +++ b/packages/keycodes/README.md @@ -114,6 +114,18 @@ Keycode for F10 key. Keycode for HOME key. +### isAppleOS + +Return true if platform is MacOS. + +_Parameters_ + +- _\_window_ `Window?`: window object by default; used for DI testing. + +_Returns_ + +- `boolean`: True if MacOS; false otherwise. + ### isKeyboardEvent An object that contains functions to check if a keyboard event matches a diff --git a/packages/keycodes/src/index.js b/packages/keycodes/src/index.js index 8f115804e1e3ba..e2306d9d75d056 100644 --- a/packages/keycodes/src/index.js +++ b/packages/keycodes/src/index.js @@ -144,6 +144,8 @@ export const SHIFT = 'shift'; */ export const ZERO = 48; +export { isAppleOS }; + /** * Object that contains functions that return the available modifier * depending on platform.