@@ -7,44 +7,10 @@ import {
7
7
store as keyboardShortcutsStore ,
8
8
} from '@wordpress/keyboard-shortcuts' ;
9
9
import { isAppleOS } from '@wordpress/keycodes' ;
10
- import { useDispatch , useSelect } from '@wordpress/data' ;
10
+ import { useDispatch } from '@wordpress/data' ;
11
11
import { __ } from '@wordpress/i18n' ;
12
- import { store as blockEditorStore } from '@wordpress/block-editor' ;
13
- import { createBlock } from '@wordpress/blocks' ;
14
12
15
13
function KeyboardShortcuts ( { undo, redo, save } ) {
16
- const { replaceBlocks } = useDispatch ( blockEditorStore ) ;
17
- const { getBlockName, getSelectedBlockClientId, getBlockAttributes } =
18
- useSelect ( blockEditorStore ) ;
19
-
20
- const handleTextLevelShortcut = ( event , level ) => {
21
- event . preventDefault ( ) ;
22
- const destinationBlockName =
23
- level === 0 ? 'core/paragraph' : 'core/heading' ;
24
- const currentClientId = getSelectedBlockClientId ( ) ;
25
- if ( currentClientId === null ) {
26
- return ;
27
- }
28
- const blockName = getBlockName ( currentClientId ) ;
29
- if ( blockName !== 'core/paragraph' && blockName !== 'core/heading' ) {
30
- return ;
31
- }
32
- const attributes = getBlockAttributes ( currentClientId ) ;
33
- const textAlign =
34
- blockName === 'core/paragraph' ? 'align' : 'textAlign' ;
35
- const destinationTextAlign =
36
- destinationBlockName === 'core/paragraph' ? 'align' : 'textAlign' ;
37
-
38
- replaceBlocks (
39
- currentClientId ,
40
- createBlock ( destinationBlockName , {
41
- level,
42
- content : attributes . content ,
43
- ...{ [ destinationTextAlign ] : attributes [ textAlign ] } ,
44
- } )
45
- ) ;
46
- } ;
47
-
48
14
useShortcut ( 'core/customize-widgets/undo' , ( event ) => {
49
15
undo ( ) ;
50
16
event . preventDefault ( ) ;
@@ -60,21 +26,6 @@ function KeyboardShortcuts( { undo, redo, save } ) {
60
26
save ( ) ;
61
27
} ) ;
62
28
63
- useShortcut (
64
- 'core/customize-widgets/transform-heading-to-paragraph' ,
65
- ( event ) => handleTextLevelShortcut ( event , 0 )
66
- ) ;
67
-
68
- [ 1 , 2 , 3 , 4 , 5 , 6 ] . forEach ( ( level ) => {
69
- //the loop is based off on a constant therefore
70
- //the hook will execute the same way every time
71
- //eslint-disable-next-line react-hooks/rules-of-hooks
72
- useShortcut (
73
- `core/customize-widgets/transform-paragraph-to-heading-${ level } ` ,
74
- ( event ) => handleTextLevelShortcut ( event , level )
75
- ) ;
76
- } ) ;
77
-
78
29
return null ;
79
30
}
80
31
@@ -126,28 +77,6 @@ function KeyboardShortcutsRegister() {
126
77
} ,
127
78
} ) ;
128
79
129
- registerShortcut ( {
130
- name : 'core/customize-widgets/transform-heading-to-paragraph' ,
131
- category : 'block-library' ,
132
- description : __ ( 'Transform heading to paragraph.' ) ,
133
- keyCombination : {
134
- modifier : 'access' ,
135
- character : `0` ,
136
- } ,
137
- } ) ;
138
-
139
- [ 1 , 2 , 3 , 4 , 5 , 6 ] . forEach ( ( level ) => {
140
- registerShortcut ( {
141
- name : `core/customize-widgets/transform-paragraph-to-heading-${ level } ` ,
142
- category : 'block-library' ,
143
- description : __ ( 'Transform paragraph to heading.' ) ,
144
- keyCombination : {
145
- modifier : 'access' ,
146
- character : `${ level } ` ,
147
- } ,
148
- } ) ;
149
- } ) ;
150
-
151
80
return ( ) => {
152
81
unregisterShortcut ( 'core/customize-widgets/undo' ) ;
153
82
unregisterShortcut ( 'core/customize-widgets/redo' ) ;
0 commit comments