@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
23 lines (22 loc) • 711 B
JavaScript
import { canInsert } from '@atlaskit/editor-prosemirror/utils';
/**
* Find a safe position to insert a deletion slice at the given position.
* @param doc
* @param pos
* @param slice
* @returns
*/
export function findSafeInsertPos(doc, pos, slice) {
if (pos > doc.content.size) {
return doc.content.size;
}
var $pos = doc.resolve(pos);
while (!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;
}