Skip to content

components/file-explorer-root-menu-component

Opens and extends the core File Explorer’s context menu for the vault root, at the two spots that stand for it: the vault name at the top of the left sidebar, and the empty area below the file list.

Obsidian already opens a menu for the empty area: the view’s own contextmenu listener on its files container calls onFileContextMenu(evt, vault.getRoot()), which builds a Menu, triggers file-menu with the root folder and the source file-explorer-context-menu, and shows it. The vault name (.workspace-drawer-vault-switcher on desktop, .workspace-drawer-header-name on mobile, where Obsidian builds no switcher) opens a different menu: on desktop Obsidian adds Show in system explorer and Copy path to the per-event menu Menu.forEvent hands out. The handlers get that menu, so a right-click there never opens a second one. A subscriber that presents the root as a folder replaces it with the root’s folder menu instead. Read from Obsidian 1.15.0.

Every plugin bundles its own copy of this library, and several of them may want this menu. Two copies patching the same prototype and listening on the same element would open it twice, so there is ONE installation per App, kept in the shared-state bag under a versioned key and owned by one subscriber. When the owner unloads while others remain, the next subscriber installs it again from its own copy. What crosses that boundary is a wire format between copies of different versions: plain objects and plain functions only, read structurally, and a change to what a field means moves to a new key rather than reinterpreting the old one.

Class Description
FileExplorerRootMenuComponent Hands the core File Explorer’s vault-root menu to a handler, and opens that menu from the vault name too. Any number of these, in any number of plugins, share one installation per App.
Interface Description
FileExplorerRootMenuComponentConstructorParams Parameters for FileExplorerRootMenuComponent.
FileExplorerRootMenuHandlerParams Parameters for a FileExplorerRootMenuHandler. The shape is part of the wire format between copies of this library: fields are only ever added.
Type Description
FileExplorerRootMenuHandler A handler of the vault-root menu.
Enum Description
FileExplorerRootMenuSpot Which spot of the File Explorer the vault-root menu was opened from.
Variable Description
VAULT_NAME_SELECTORS The elements that stand for the vault root at the top of the left sidebar, in priority order. Obsidian builds .workspace-drawer-vault-switcher only on desktop; on mobile the vault name is the drawer header instead.