-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeymap.mjs
More file actions
42 lines (41 loc) · 1.36 KB
/
keymap.mjs
File metadata and controls
42 lines (41 loc) · 1.36 KB
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 { gateSchema } from "./schema.mjs";
import { chainCommands } from "prosemirror-commands";
import { splitListItem } from "prosemirror-schema-list";
import { TextSelection } from "prosemirror-state";
import { findWrapping } from "prosemirror-transform";
export default {
Enter: chainCommands(
function (state, dispatch) {
if (!state.selection.empty) return false;
const { $from } = state.selection;
const node = $from.parent;
if (node.type == gateSchema.nodes.button) {
if (dispatch) {
let tr = state.tr.insert(
$from.after(1),
gateSchema.nodes.accordion.createAndFill(),
);
tr = tr.setSelection(TextSelection.create(tr.doc, $from.after(-1) + 2));
dispatch(tr);
}
return true;
} else if (node.type == gateSchema.nodes.paragraph && $from.depth == 2) {
return splitBlock(state, dispatch)
}
return false;
},
splitListItem(gateSchema.nodes.listItem)
),
Backspace(state, dispatch) {
if (!state.selection.empty) return false;
const { $from } = state.selection;
const node = $from.node(1);
if (node.type != gateSchema.nodes.accordion) return false;
if (node.textContent) return false;
if (dispatch) {
let tr = state.tr.delete($from.before(1), $from.after(1));
dispatch(tr);
}
return true;
},
};