UNPKG

@wordpress/editor

Version:
145 lines (144 loc) 4.17 kB
// packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js 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"; import { jsx } from "react/jsx-runtime"; function EditorKeyboardShortcutsRegister() { 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: __("Show or hide the List View."), keyCombination: { modifier: "access", character: "o" } }); registerShortcut({ name: "core/editor/toggle-distraction-free", category: "global", description: __("Enter or exit distraction free mode."), keyCombination: { modifier: "primaryShift", character: "\\" } }); registerShortcut({ name: "core/editor/toggle-sidebar", category: "global", description: __("Show or hide the Settings panel."), 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/new-note", category: "block", description: __("Add a new note."), keyCombination: { modifier: "primaryAlt", character: "m" } }); 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, {}); } var register_shortcuts_default = EditorKeyboardShortcutsRegister; export { register_shortcuts_default as default }; //# sourceMappingURL=register-shortcuts.mjs.map