UNPKG

@atlaskit/editor-plugin-synced-block

Version:

SyncedBlock plugin for @atlaskit/editor-core

16 lines 580 B
import { Mapping } from '@atlaskit/editor-prosemirror/transform'; export const rebaseTransaction = (currentTr, incomingTr, state) => { if (!incomingTr.docChanged) { return currentTr; } const currentMapping = new Mapping([...currentTr.mapping.maps].reverse().map(map => map.invert())); const rebasedTransaction = state.tr; currentTr.steps.forEach(step => { const mappedStep = step.map(currentMapping); if (mappedStep) { rebasedTransaction.step(mappedStep); currentMapping.appendMap(mappedStep.getMap()); } }); return rebasedTransaction; };