link-at-position
Finds the link at a position in a note’s source text (the editor cursor by default), in the note’s body and in its YAML frontmatter alike.
Every range is inclusive at BOTH ends, so a cursor right before a link ({cursor}[a](b)), inside it and right after it ([a](b){cursor}) all find it. Obsidian’s own Editor.getClickableTokenAt misses the first of those and reports nothing at all inside the frontmatter, which is why this exists.
Links are found by parseLinks, one source line at a time, so a link never spans lines here.
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| GetLinkAtEditorPositionParams | Params for getLinkAtEditorPosition. |
| GetLinkAtPositionParams | Params for getLinkAtPosition. |
| GetLinkAtPositionTargetParams | Params for getLinkAtPositionTarget. |
| LinkAtPosition | The link found at a position by getLinkAtPosition. |
Functions
Section titled “Functions”| Function | Description |
|---|---|
| getLinkAtEditorPosition | Finds the link at an editor position, the cursor by default. See getLinkAtPosition for the rules. |
| getLinkAtPosition | Finds the link at a position in a note’s source text. In the body: 1. A link is hit from the column of its first character to the column just past its last, both included. 2. When two links touch ([a](x)\{cursor\}[b](y)), the one the cursor is before wins. 3. A line inside a fenced code block, or a fence line itself, holds no link. Indentation is ignored, so a nested list item is not read as an indented code block. In the frontmatter: 1. The quotes belong to the link: key: \{cursor\}"[[note]]" and key: "[[note]]"\{cursor\} both hit. So do unquoted values, flow sequences, block sequence items and Markdown links. 2. A position on the key, the sequence dash, the indentation or the gap before the value hits only when the value holds exactly one link, as \{cursor\}key: "[[note]]" does. A key with an empty value counts the links on its nested lines. Several links give null, since nothing says which one is meant. 3. The commas and spaces between two entries (["[[a]]",\{cursor\} "[[b]]"]) hit the entry after them. 4. Nothing in a comment is a link, and the delimiter lines hold none. Positions are those of the YAML source text. The Properties view is a widget, not editor text, so it has no positions to look up. |
| getLinkAtPositionTarget | Resolves the note a link found by getLinkAtPosition points at, through metadataCache.getFirstLinkpathDest. A link into the same note ([[#Heading]]) resolves to that note. |
| Type | Description |
|---|---|
| LinkSourceEditor | The part of an Editor getLinkAtEditorPosition reads. |
| LinkSourceLines | Lines of a note’s source text, the part of an Editor getLinkAtPosition reads. |