UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

34 lines (31 loc) • 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapStepRangeToFinal = void 0; var _transform = require("@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. */ var mapStepRangeToFinal = exports.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 _transform.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 }; };