/
base-keymap.ts
42 lines (36 loc) 路 1.28 KB
/
base-keymap.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { BaseExtensionOptions, Extension, KeyboardBindings } from '@remirror/core';
import { baseKeymap, chainCommands, selectParentNode } from 'prosemirror-commands';
import { undoInputRule } from 'prosemirror-inputrules';
export interface BaseKeymapExtensionOptions extends BaseExtensionOptions {
/**
* Determines whether a backspace after an input rule has been applied undoes the input rule.
*
* @defaultValue true
*/
undoInputRuleOnBackspace?: boolean;
/**
* Determines whether the escape key selects the current node.
*
* @defaultValue false
*/
selectParentNodeOnEscape?: boolean;
}
export class BaseKeymapExtension extends Extension<BaseKeymapExtensionOptions> {
get name() {
return 'baseKeymap' as const;
}
get defaultOptions() {
return {
undoInputRuleOnBackspace: true,
selectParentNodeOnEscape: false,
};
}
public keys() {
const { selectParentNodeOnEscape, undoInputRuleOnBackspace } = this.options;
const backspaceRule: KeyboardBindings = undoInputRuleOnBackspace
? { Backspace: chainCommands(undoInputRule, baseKeymap.Backspace) }
: {};
const escapeRule: KeyboardBindings = selectParentNodeOnEscape ? { Escape: selectParentNode } : {};
return { ...baseKeymap, ...backspaceRule, ...escapeRule };
}
}