Skip to content
Snippets Groups Projects

Track changes

Merged Christos requested to merge track-changes into master
1 file
+ 30
1
Compare changes
  • Side-by-side
  • Inline
import { Mapping, RemoveMarkStep } from 'prosemirror-transform';
import { minBy, maxBy } from 'lodash';
import { injectable } from 'inversify';
import Tools from '../../lib/Tools';
@@ -8,7 +11,33 @@ class AcceptTrackChange extends Tools {
content = 'Accept';
get run() {
return (state, dispatch) => {};
return (state, dispatch) => {
const {
tr,
selection: { from, to },
} = state;
const map = new Mapping();
state.doc.nodesBetween(from, to, (node, pos) => {
if (
node.marks &&
node.marks.find(mark => mark.type.name === 'insertion')
) {
const insertionMark = node.marks.find(
mark => mark.type.name === 'insertion',
);
tr.step(
new RemoveMarkStep(
map.map(maxBy(pos, from)),
map.map(minBy(pos + node.nodeSize, to)),
insertionMark,
),
);
}
});
dispatch(tr);
};
}
get active() {