@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
136 lines (135 loc) • 3.89 kB
JavaScript
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
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';
/**
* Component for registering editor keyboard shortcuts.
*
* @return {Element} The component to be rendered.
*/
import { jsx as _jsx } from "react/jsx-runtime";
function EditorKeyboardShortcutsRegister() {
// Registering the shortcuts.
const {
registerShortcut
} = useDispatch(keyboardShortcutsStore);
useEffect(() => {
registerShortcut({
name: 'core/editor/toggle-mode',
category: 'global',
description: __('Switch between visual editor and code editor.'),
keyCombination: {
modifier: 'secondary',
character: 'm'
}
});
registerShortcut({
name: 'core/editor/save',
category: 'global',
description: __('Save your changes.'),
keyCombination: {
modifier: 'primary',
character: 's'
}
});
registerShortcut({
name: 'core/editor/undo',
category: 'global',
description: __('Undo your last changes.'),
keyCombination: {
modifier: 'primary',
character: 'z'
}
});
registerShortcut({
name: 'core/editor/redo',
category: 'global',
description: __('Redo your last undo.'),
keyCombination: {
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({
name: 'core/editor/toggle-list-view',
category: 'global',
description: __('Open the List View.'),
keyCombination: {
modifier: 'access',
character: 'o'
}
});
registerShortcut({
name: 'core/editor/toggle-distraction-free',
category: 'global',
description: __('Toggle distraction free mode.'),
keyCombination: {
modifier: 'primaryShift',
character: '\\'
}
});
registerShortcut({
name: 'core/editor/toggle-sidebar',
category: 'global',
description: __('Show or hide the Settings sidebar.'),
keyCombination: {
modifier: 'primaryShift',
character: ','
}
});
registerShortcut({
name: 'core/editor/keyboard-shortcuts',
category: 'main',
description: __('Display these keyboard shortcuts.'),
keyCombination: {
modifier: 'access',
character: 'h'
}
});
registerShortcut({
name: 'core/editor/next-region',
category: 'global',
description: __('Navigate to the next part of the editor.'),
keyCombination: {
modifier: 'ctrl',
character: '`'
},
aliases: [{
modifier: 'access',
character: 'n'
}]
});
registerShortcut({
name: 'core/editor/previous-region',
category: 'global',
description: __('Navigate to the previous part of the editor.'),
keyCombination: {
modifier: 'ctrlShift',
character: '`'
},
aliases: [{
modifier: 'access',
character: 'p'
}, {
modifier: 'ctrlShift',
character: '~'
}]
});
}, [registerShortcut]);
return /*#__PURE__*/_jsx(BlockEditorKeyboardShortcuts.Register, {});
}
export default EditorKeyboardShortcutsRegister;
//# sourceMappingURL=register-shortcuts.js.map