-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathundoInputRule.js
More file actions
32 lines (25 loc) · 855 Bytes
/
undoInputRule.js
File metadata and controls
32 lines (25 loc) · 855 Bytes
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
export const undoInputRule = () => ({ state, dispatch }) => {
const plugins = state.plugins;
for (let i = 0; i < plugins.length; i += 1) {
const plugin = plugins[i];
let undoable;
// eslint-disable-next-line
if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
if (dispatch) {
const tr = state.tr;
const toUndo = undoable.transform;
for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
}
if (undoable.text) {
const marks = tr.doc.resolve(undoable.from).marks();
tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
} else {
tr.delete(undoable.from, undoable.to);
}
}
return true;
}
}
return false;
}