Skip to content

workspace

This module provides additional utilities for working with the Obsidian Workspace.

Function Description
ensureLayoutReady Waits until the workspace layout is ready. Resolves immediately when the layout is already ready; otherwise resolves once Obsidian fires the layout-ready event.
getAllContainers Returns all containers in the workspace.
getAllDomWindows Returns all DOM windows in the workspace.
getMainWindow Returns the app’s main window — the one the vault opened in, as opposed to any popout window. Read from the root split, which is the one workspace container that always lives in the main window (every popout is a WorkspaceWindow under floatingSplit). Prefer this over the global window, which only happens to be the main window because plugin code runs in its context.
switchToMainWindow Makes the app’s main window the active one until the returned DisposableEx is disposed. See switchToWindow for why this is needed and what it changes, and getMainWindow for what counts as the main window.
switchToWindow Makes the given window the active one until the returned DisposableEx is disposed. Obsidian tracks the focused window in the activeWindow / activeDocument globals and updates them whenever a window takes focus — including when a popout such as the settings window opens. UI it creates for “the current window” reads those globals at creation time and offers no way to name a window: new Notice(...), for instance, is built inside whatever window activeWindow points at, and cannot be moved afterwards. Pointing the globals at the wanted window for exactly that creation, then putting them back, is what this does. Restore is what makes it safe, so always bind it with using (or dispose it in a finally): leaving the globals pointed at the wrong window would misplace every later window-sensitive Obsidian call.