Skip to content
Snippets Groups Projects
Commit e7329b36 authored by chris's avatar chris
Browse files

accept all deletions

parent 4699409a
No related branches found
No related tags found
1 merge request!143Track changes
import { Mapping, RemoveMarkStep } from 'prosemirror-transform';
import { Mapping, RemoveMarkStep, ReplaceStep } from 'prosemirror-transform';
import { Slice } from 'prosemirror-model';
import { minBy, maxBy } from 'lodash';
import { injectable } from 'inversify';
......@@ -21,6 +23,17 @@ class AcceptTrackChange extends Tools {
state.doc.nodesBetween(from, to, (node, pos) => {
if (
node.marks &&
node.marks.find(mark => mark.type.name === 'deletion')
) {
const deletionStep = new ReplaceStep(
map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)),
Slice.empty,
);
tr.step(deletionStep);
map.appendMap(deletionStep.getMap());
} else if (
node.marks &&
node.marks.find(mark => mark.type.name === 'insertion')
) {
......@@ -29,13 +42,14 @@ class AcceptTrackChange extends Tools {
);
tr.step(
new RemoveMarkStep(
map.map(maxBy(pos, from)),
map.map(minBy(pos + node.nodeSize, to)),
map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)),
insertionMark,
),
);
}
});
dispatch(tr);
};
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment