Skip to content

isReferenceInOffsetRange

Checks if a reference is fully contained within an offset range.

Only a reference that carries a position within the file’s content can be in a range. A FrontmatterLinkCache — a frontmatter link, a multi-link frontmatter value entry, or any canvas reference — carries no such position and is therefore never in range. Its startOffset / endOffset, where present, locate the link within its own property value rather than within the file, so they are deliberately not compared against the range.

Containment is full and both bounds are inclusive: a reference that only partially overlaps the range is not in it, because rewriting part of a link corrupts it.

Import:

import { isReferenceInOffsetRange } from 'obsidian-dev-utils/obsidian/reference';

Signature:

function isReferenceInOffsetRange(reference: Reference, offsetRange: OffsetRange): boolean

Parameters:

ParameterTypeDescription
referenceReferenceThe reference to check.
offsetRangeOffsetRangeThe offset range to check against.

Returns: boolean — Whether the reference is fully contained within the offset range.