Skip to content

iterateReferencesAffectedByRename

Visits the references app.metadataCache.iterateAllRefs would visit, minus every reference whose resolution cannot change when file is renamed to newPath.

Obsidian’s FileManager.runAsyncLinkUpdate resolves EVERY reference in the vault before each rename, to diff the resolutions afterwards in updateAllLinks; that is the whole cost of a rename in a large vault. A reference can resolve to file only if its linkpath’s last segment matches file’s name before the rename or its name after it (see the file header), and a reference that resolves to neither keeps resolving to whatever it did. So the references that can change are those of the index’s candidates for both names, plus the references held by file itself, whose relative links resolve from its new folder afterwards. linkUpdaters references are walked in full, as in getIndexedBacklinksForFile.

Import:

import { iterateReferencesAffectedByRename } from '@mnaoumov/obsidian-lib/backlink-index';

Signature:

function iterateReferencesAffectedByRename(app: App, file: TFile, newPath: string, callback: (path: string, reference: Reference) => boolean | void): void

Parameters:

Parameter Type Description
app App The Obsidian app instance.
file TFile The file being renamed, still at its old path.
newPath string The path it is being renamed to.
callback (path: string, reference: Reference) => boolean | void Called with each reference and the path of the note holding it. Returning true stops the walk over that note’s references, as in Obsidian’s own walk.

Returns: void