UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

24 lines (23 loc) • 853 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeResolve = void 0; /** * Resolves a document position, or returns `null` if it cannot be resolved. * * `Node.resolve` throws a `RangeError` for a position outside the document. Diff decorations are * built from change ranges computed against a document that may since have moved on, so a position * arriving out of range is a normal outcome rather than a defect — but an exception escaping here * takes down the whole decoration set, leaving the diff unrendered. * * Callers are expected to treat `null` as "cannot tell" and fall back to behaviour that does not * need the resolved position. */ var safeResolve = exports.safeResolve = function safeResolve(doc, pos) { try { return doc.resolve(pos); } catch (_unused) { return null; } };