/** * The caret, expressed as something a remote edit cannot move out from under. * * A ProseMirror selection is a pair of absolute integers. A remote insert of * five characters before the caret makes both of them wrong, and the spike * proved that recovering afterwards does not work: `loro-prosemirror` built its * Loro `Cursor` from the absolute position **after** importing the remote * update, so it anchored to whichever character had slid into that offset. * Measured there: caret at 11, peer inserts `BBBBB` at 0, caret still reads 11 * and the next keystroke lands in the middle of the user's own word. * * So the anchor is minted **before** any import can happen — refreshed on every * local transaction — and resolved after, in the same ProseMirror transaction * that applies the remote change. A Loro `Cursor` is a stable reference to a * character, so resolving it later answers "where did that character go?", * which is the question the caret actually asks. */ import type { Node as PmNode } from 'prosemirror-model'; import type { ContainerID, Cursor, LoroDoc } from 'loro-crdt'; import { LoroPmMapping } from './types.js'; /** * Where the caret sits, in terms Loro can rebase. * * `cursor` is the real answer. `block`/`offset` is the fallback for the one * case a text cursor cannot express — an empty textblock, which has no * character to anchor to — and for a cursor whose character has been deleted. */ export interface CaretAnchor { cursor?: Cursor; block?: ContainerID; offset: number; } /** * Mint an anchor for one ProseMirror position. * * Called on every local transaction, which is what makes it *pre-import*: the * editor is single-threaded, so an anchor taken while handling a transaction is * necessarily older than the next remote event. */ export declare function caretAnchorAt(loro_doc: LoroDoc, pm_doc: PmNode, position: number, mapping: LoroPmMapping): CaretAnchor | null; /** * Resolve an anchor against the freshly projected document. * * Returns `null` when the block it named is gone — in which case the caller * should leave ProseMirror's own step mapping to it, which is right for a * deletion and only slightly wrong for anything else. */ export declare function resolveCaretAnchor(loro_doc: LoroDoc, pm_doc: PmNode, anchor: CaretAnchor, mapping: LoroPmMapping): { position: number; cursor?: Cursor; } | null; //# sourceMappingURL=cursor.d.ts.map