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

dispatch in a sinlge transaction

parent 46d00294
No related branches found
No related tags found
1 merge request!143Track changes
import { Mapping, RemoveMarkStep } from 'prosemirror-transform';
import { minBy, maxBy } from 'lodash';
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import Tools from '../../lib/Tools'; import Tools from '../../lib/Tools';
...@@ -10,9 +13,12 @@ class AcceptTrackChange extends Tools { ...@@ -10,9 +13,12 @@ class AcceptTrackChange extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
const { const {
tr,
selection: { from, to }, selection: { from, to },
} = state; } = state;
const map = new Mapping();
state.doc.nodesBetween(from, to, (node, pos) => { state.doc.nodesBetween(from, to, (node, pos) => {
if ( if (
node.marks && node.marks &&
...@@ -21,15 +27,16 @@ class AcceptTrackChange extends Tools { ...@@ -21,15 +27,16 @@ class AcceptTrackChange extends Tools {
const insertionMark = node.marks.find( const insertionMark = node.marks.find(
mark => mark.type.name === 'insertion', mark => mark.type.name === 'insertion',
); );
dispatch( tr.step(
state.tr.removeMark( new RemoveMarkStep(
insertionMark.pos, map.map(maxBy(pos, from)),
insertionMark.pos + node.nodeSize, map.map(minBy(pos + node.nodeSize, to)),
state.schema.marks.insertion, 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