Enable undo/redo keyboard shortcuts
[MAILPOET-6362]
This commit is contained in:
committed by
Rostislav Wolný
parent
498cfda3b1
commit
7b2d113330
@ -1,5 +1,6 @@
|
|||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { useEffect } from '@wordpress/element';
|
import { useEffect } from '@wordpress/element';
|
||||||
|
import { store as coreDataStore } from '@wordpress/core-data';
|
||||||
import {
|
import {
|
||||||
useShortcut,
|
useShortcut,
|
||||||
store as keyboardShortcutsStore,
|
store as keyboardShortcutsStore,
|
||||||
@ -12,6 +13,7 @@ import { storeName } from '../../store';
|
|||||||
// https://github.com/WordPress/gutenberg/blob/0ee78b1bbe9c6f3e6df99f3b967132fa12bef77d/packages/edit-site/src/components/keyboard-shortcuts/index.js
|
// https://github.com/WordPress/gutenberg/blob/0ee78b1bbe9c6f3e6df99f3b967132fa12bef77d/packages/edit-site/src/components/keyboard-shortcuts/index.js
|
||||||
|
|
||||||
export function KeyboardShortcuts(): null {
|
export function KeyboardShortcuts(): null {
|
||||||
|
const { undo: undoAction, redo: redoAction } = useDispatch( coreDataStore );
|
||||||
const { isSidebarOpened, hasEdits, isSaving } = useSelect( ( select ) => ( {
|
const { isSidebarOpened, hasEdits, isSaving } = useSelect( ( select ) => ( {
|
||||||
isSidebarOpened: select( storeName ).isSidebarOpened(),
|
isSidebarOpened: select( storeName ).isSidebarOpened(),
|
||||||
isSaving: select( storeName ).isSaving(),
|
isSaving: select( storeName ).isSaving(),
|
||||||
@ -53,6 +55,26 @@ export function KeyboardShortcuts(): null {
|
|||||||
character: 's',
|
character: 's',
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
void registerShortcut( {
|
||||||
|
name: 'mailpoet/email-editor/undo',
|
||||||
|
category: 'block',
|
||||||
|
description: __( 'Undo your last changes.' ),
|
||||||
|
keyCombination: {
|
||||||
|
modifier: 'primary',
|
||||||
|
character: 'z',
|
||||||
|
},
|
||||||
|
} );
|
||||||
|
|
||||||
|
void registerShortcut( {
|
||||||
|
name: 'mailpoet/email-editor/redo',
|
||||||
|
category: 'block',
|
||||||
|
description: __( 'Redo your last undo.' ),
|
||||||
|
keyCombination: {
|
||||||
|
modifier: 'primaryShift',
|
||||||
|
character: 'z',
|
||||||
|
},
|
||||||
|
} );
|
||||||
}, [ registerShortcut ] );
|
}, [ registerShortcut ] );
|
||||||
|
|
||||||
useShortcut( 'mailpoet/email-editor/toggle-fullscreen', () => {
|
useShortcut( 'mailpoet/email-editor/toggle-fullscreen', () => {
|
||||||
@ -77,5 +99,25 @@ export function KeyboardShortcuts(): null {
|
|||||||
void saveEditedEmail();
|
void saveEditedEmail();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
useShortcut(
|
||||||
|
// Shortcut name
|
||||||
|
'mailpoet/email-editor/undo',
|
||||||
|
// Shortcut callback
|
||||||
|
( event ): void => {
|
||||||
|
void undoAction();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
useShortcut(
|
||||||
|
// Shortcut name
|
||||||
|
'mailpoet/email-editor/redo',
|
||||||
|
// Shortcut callback
|
||||||
|
( event ): void => {
|
||||||
|
void redoAction();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user