UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

28 lines (26 loc) • 959 B
import { Mapping } from '@atlaskit/editor-prosemirror/transform'; // ProseMirror's assoc value chooses which side of an insertion a mapped boundary stays on. var FROM_ASSOC = -1; var TO_ASSOC = 1; /** Maps a step's range into final-document coordinates when the rollout path supplies step maps. */ export var mapStepRangeToFinal = function mapStepRangeToFinal(from, to, stepIndex, stepMaps) { if (!stepMaps) { return { fromB: from, toB: to }; } // The range is already in the document immediately after this step, so skip its own map and // apply only the maps from subsequent steps. var firstSubsequentStepIndex = stepIndex + 1; var finalRange = new Mapping(stepMaps.slice(firstSubsequentStepIndex)); var fromB = finalRange.mapResult(from, FROM_ASSOC); var toB = finalRange.mapResult(to, TO_ASSOC); if (fromB.deleted && toB.deleted) { return undefined; } return { fromB: fromB.pos, toB: toB.pos }; };