@@ -2,6 +2,36 @@ import { Extension } from '../Extension.js';
22import { isIOS } from '../utilities/isIOS.js' ;
33import { isMacOS } from '../utilities/isMacOS.js' ;
44
5+ export const handleEnter = ( editor ) => {
6+ editor . commands . first ( ( { commands } ) => [
7+ ( ) => commands . newlineInCode ( ) ,
8+ ( ) => commands . createParagraphNear ( ) ,
9+ ( ) => commands . liftEmptyBlock ( ) ,
10+ ( ) => commands . splitBlock ( ) ,
11+ ] ) ;
12+ } ;
13+
14+ export const handleBackspace = ( editor ) => {
15+ editor . commands . first ( ( { commands, tr } ) => [
16+ ( ) => commands . undoInputRule ( ) ,
17+ ( ) => {
18+ tr . setMeta ( 'inputType' , 'deleteContentBackward' ) ;
19+ return false ;
20+ } ,
21+ ( ) => commands . deleteSelection ( ) ,
22+ ( ) => commands . joinBackward ( ) ,
23+ ( ) => commands . selectNodeBackward ( ) ,
24+ ] ) ;
25+ } ;
26+
27+ export const handleDelete = ( editor ) => {
28+ editor . commands . first ( ( { commands } ) => [
29+ ( ) => commands . deleteSelection ( ) ,
30+ ( ) => commands . joinForward ( ) ,
31+ ( ) => commands . selectNodeForward ( ) ,
32+ ] ) ;
33+ } ;
34+
535/**
636 * For reference.
737 * https://github.com/ProseMirror/prosemirror-commands/blob/master/src/commands.ts
@@ -10,41 +40,14 @@ export const Keymap = Extension.create({
1040 name : 'keymap' ,
1141
1242 addShortcuts ( ) {
13- const handleEnter = ( ) =>
14- this . editor . commands . first ( ( { commands } ) => [
15- ( ) => commands . newlineInCode ( ) ,
16- ( ) => commands . createParagraphNear ( ) ,
17- ( ) => commands . liftEmptyBlock ( ) ,
18- ( ) => commands . splitBlock ( ) ,
19- ] ) ;
20-
21- const handleBackspace = ( ) =>
22- this . editor . commands . first ( ( { commands, tr } ) => [
23- ( ) => commands . undoInputRule ( ) ,
24- ( ) => {
25- tr . setMeta ( 'inputType' , 'deleteContentBackward' ) ;
26- return false ;
27- } ,
28- ( ) => commands . deleteSelection ( ) ,
29- ( ) => commands . joinBackward ( ) ,
30- ( ) => commands . selectNodeBackward ( ) ,
31- ] ) ;
32-
33- const handleDelete = ( ) =>
34- this . editor . commands . first ( ( { commands } ) => [
35- ( ) => commands . deleteSelection ( ) ,
36- ( ) => commands . joinForward ( ) ,
37- ( ) => commands . selectNodeForward ( ) ,
38- ] ) ;
39-
4043 const baseKeymap = {
41- Enter : handleEnter ,
44+ Enter : ( ) => handleEnter ( this . editor ) ,
4245 'Mod-Enter' : ( ) => this . editor . commands . exitCode ( ) ,
43- Backspace : handleBackspace ,
44- 'Mod-Backspace' : handleBackspace ,
45- 'Shift-Backspace' : handleBackspace ,
46- Delete : handleDelete ,
47- 'Mod-Delete' : handleDelete ,
46+ Backspace : ( ) => handleBackspace ( this . editor ) ,
47+ 'Mod-Backspace' : ( ) => handleBackspace ( this . editor ) ,
48+ 'Shift-Backspace' : ( ) => handleBackspace ( this . editor ) ,
49+ Delete : ( ) => handleDelete ( this . editor ) ,
50+ 'Mod-Delete' : ( ) => handleDelete ( this . editor ) ,
4851 'Mod-a' : ( ) => this . editor . commands . selectAll ( ) ,
4952 Tab : ( ) => this . editor . commands . insertTabNode ( ) ,
5053 } ;
@@ -55,12 +58,12 @@ export const Keymap = Extension.create({
5558
5659 const macBaseKeymap = {
5760 ...baseKeymap ,
58- 'Ctrl-h' : handleBackspace ,
59- 'Alt-Backspace' : handleBackspace ,
60- 'Ctrl-d' : handleDelete ,
61- 'Ctrl-Alt-Backspace' : handleDelete ,
62- 'Alt-Delete' : handleDelete ,
63- 'Alt-d' : handleDelete ,
61+ 'Ctrl-h' : ( ) => handleBackspace ( this . editor ) ,
62+ 'Alt-Backspace' : ( ) => handleBackspace ( this . editor ) ,
63+ 'Ctrl-d' : ( ) => handleDelete ( this . editor ) ,
64+ 'Ctrl-Alt-Backspace' : ( ) => handleDelete ( this . editor ) ,
65+ 'Alt-Delete' : ( ) => handleDelete ( this . editor ) ,
66+ 'Alt-d' : ( ) => handleDelete ( this . editor ) ,
6467 'Ctrl-a' : ( ) => this . editor . commands . selectTextblockStart ( ) ,
6568 'Ctrl-e' : ( ) => this . editor . commands . selectTextblockEnd ( ) ,
6669 'Ctrl-t' : ( ) => this . editor . commands . insertTabChar ( ) ,
0 commit comments