Skip to content

CaseInsensitiveFileIndex

An O(1) case-insensitive index of the loaded files and folders of a single vault.

The index maps the lowercased path of each abstract file to the abstract file itself. It is kept in sync by an owning component that forwards create/delete/rename vault events.

Import:

import { CaseInsensitiveFileIndex } from 'obsidian-dev-utils/obsidian/case-insensitive-file-index';

Signature:

export class CaseInsensitiveFileIndex

Constructor

new CaseInsensitiveFileIndex(app: App)

Creates a new case-insensitive file index.

Methods

MethodReturnsDescription
add(abstractFile)voidAdds an abstract file to the index.
delete(path)voidRemoves the abstract file at the given path from the index, along with all of its descendants (for folder deletions, where Obsidian removes the whole subtree).
get(path)null | TAbstractFileResolves an abstract file by its path, case-insensitively, in O(1).
ownsApp(app)booleanChecks whether this index mirrors the given application's vault.
rename(oldPath, newAbstractFile)voidRe-keys an abstract file (and, for folders, all of its descendants) after a rename.

Obsidian fires a single rename event for the renamed abstract file and updates its descendants' paths in place without firing per-descendant events, so descendant keys are recomputed here by swapping the old path prefix for the new one. Handles case-only renames (the old and new keys coincide).

Links to this page: