UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

28 lines (27 loc) 838 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findSafeInsertPos = findSafeInsertPos; var _utils = require("@atlaskit/editor-prosemirror/utils"); /** * Find a safe position to insert a deletion slice at the given position. * @param doc * @param pos * @param slice * @returns */ function findSafeInsertPos(doc, pos, slice) { if (pos > doc.content.size) { return doc.content.size; } var $pos = doc.resolve(pos); while (!(0, _utils.canInsert)($pos, slice.content) && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type.name) !== 'paragraph') { var _slice$content$firstC; if ($pos.pos + 1 > doc.content.size) { break; } $pos = doc.resolve($pos.pos + 1); } return $pos.pos; }