Skip to content

LayoutReadyWorkspace

Unofficial

A obsidian#Workspace whose layout is loaded, so the members that are null before that are set.

Get one with the isLayoutReady type guard or the onLayoutReadyEx helper from obsidian-typings/implementations.

Import:

import type { LayoutReadyWorkspace } from '@obsidian-typings/obsidian-public-latest';

Example:

import { onLayoutReadyEx } from 'obsidian-typings/implementations';
onLayoutReadyEx(this.app.workspace, (workspace) => {
console.log(workspace.floatingSplit.children.length);
});

Signature:

export interface LayoutReadyWorkspace extends Workspace

Extends: Workspace

Constructor

new LayoutReadyWorkspace(app: App, containerEl: HTMLElement)

Constructor.

To get the constructor instance, use getWorkspaceConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
_Record<string, EventsEntry[]>Internal storage of registered event handlers by event name.
(Inherited from Workspace)
_activeEditorMarkdownFileInfo | nullInternal reference to the active editor.
(Inherited from Workspace)
activeEditorMarkdownFileInfo | nullA component managing the current editor. This can be null if the active view has no editor.
(Inherited from Workspace)
activeLeafnull | WorkspaceLeafIndicates the currently focused leaf, if one exists.

Please avoid using activeLeaf directly, especially without checking whether activeLeaf is null.
(Inherited from Workspace)
activeTabGroupWorkspaceTabsCurrently active tab group.
appAppReference to the obsidian#App.
(Inherited from Workspace)
backlinkInDocument?unknownBacklink in document plugin instance, if enabled.
(Inherited from Workspace)
containerElHTMLElementThe container element of the workspace.
(Inherited from Workspace)
editorExtensionsExtension[]Registered CodeMirror editor extensions, to be applied to all CM instances.
(Inherited from Workspace)
editorSuggestEditorSuggestExThe global editor suggest manager for live autocomplete.
(Inherited from Workspace)
floatingSplitWorkspaceFloatingThe workspace container that holds the popout (floating) windows.
hoverLinkSourcesWorkspaceHoverLinkSourcesRecordRegistered sources for hover link previews.
(Inherited from Workspace)
initializedbooleanWhether the workspace has finished its initial layout load.
(Inherited from Workspace)
lastActiveFilenull | TFileLast opened file in the vault, or null when no file has been opened yet.
(Inherited from Workspace)
lastTabGroupStackedbooleanWhether the last active tab group had stacked tabs enabled.
(Inherited from Workspace)
layoutItemQueueunknown[]Queue of layout items pending initialization.
(Inherited from Workspace)
layoutReadytrueWhether the layout of the app has been successfully initialized.
layoutReadyCallbacksDonenull | Promise<void>Settles once every callback queued by Workspace.onLayoutReady before the layout was ready has run, awaiting those that return a promise. null until the layout is ready.
(Inherited from Workspace)
leftRibbonWorkspaceRibbonThe left ribbon of the workspace.
(Inherited from Workspace)
leftSidebarToggleButtonElHTMLElementButton element for toggling the left sidebar.
(Inherited from Workspace)
leftSplitWorkspaceMobileDrawer | WorkspaceSidedockThe left split of the workspace.
(Inherited from Workspace)
mobileFileInfosunknown[]Array of renderCallbacks
(Inherited from Workspace)
onLayoutReadyCallbacks?unknownCallbacks queued to run when the layout is ready.
(Inherited from Workspace)
operatorFuncConfigsRecord<string, unknown>Registered operator function configurations.
(Inherited from Workspace)
protocolHandlerWorkspaceProtocolHandlerProtocol handlers registered on the workspace.
(Inherited from Workspace)
recentFileTrackerRecentFileTrackerTracks last opened files in the vault.
(Inherited from Workspace)
requestSaveLayoutDebouncer<[], Promise<void>>Save the state of the current workspace layout.
(Inherited from Workspace)
rightRibbonWorkspaceRibbonThe right ribbon of the workspace.
(Inherited from Workspace)
rightSidebarToggleButtonElHTMLElementButton element for toggling the right sidebar.
(Inherited from Workspace)
rightSplitWorkspaceMobileDrawer | WorkspaceSidedockThe right split of the workspace.
(Inherited from Workspace)
rootSplitWorkspaceRootThe root split of the workspace.
(Inherited from Workspace)
scopeWorkspaceScopeThe workspace's key scope, a child of the app scope that delegates to the active leaf's view scope.
(Inherited from Workspace)
undoHistoryStateHistory[]List of states that were closed and may be reopened.
(Inherited from Workspace)

Methods

MethodReturnsDescription
activeLeafEvents()voidChange active leaf and trigger leaf change event
(Inherited from Workspace)
addMobileFileInfo(file)voidAdd file to mobile file info
(Inherited from Workspace)
addRecentFile(file)voidAdd a file to the recent files list.
(Inherited from Workspace)
changeLayout(workspace)Promise<void>Change the layout of the workspace.
(Inherited from Workspace)
clearLayout()Promise<void>Clear layout of workspace and destruct all leaves
(Inherited from Workspace)
createLeafBySplit(leaf, direction?, before?)WorkspaceLeafCreate a leaf by a split.
(Inherited from Workspace)
createLeafInParent(parent, index)WorkspaceLeafCreate a leaf in a parent.
(Inherited from Workspace)
createLeafInTabGroup(tabs?)WorkspaceLeafCreate a leaf in the selected tab group or last used tab group.
(Inherited from Workspace)
deserializeLayout(leaf, ribbon?)Promise<WorkspaceLeaf>Deserialize workspace entries into actual Leaf objects.
(Inherited from Workspace)
detachLeavesOfType(viewType)voidRemove all leaves of the given type.
(Inherited from Workspace)
duplicateLeaf(leaf, direction?)Promise<WorkspaceLeaf>Duplicate a leaf.
(Inherited from Workspace)
duplicateLeaf(leaf, leafType, direction?)Promise<WorkspaceLeaf>Duplicate a leaf.
(Inherited from Workspace)
ensureSideLeaf(type, side, options?)Promise<WorkspaceLeaf>Get side leaf or create one if one does not exist.
(Inherited from Workspace)
focusLeaf(leaf)voidFocus on a specific leaf.
(Inherited from Workspace)
getActiveFile()TFile | nullReturns the file for the current view if it's a FileView. Otherwise, it will return the most recently active file.
(Inherited from Workspace)
getActiveFileView()FileView | nullGet active file view if exists.
(Inherited from Workspace)
getActiveLeafOfViewType(type)null | TGet the active leaf of the given view type.
(Inherited from Workspace)
getActiveViewOfType(type)T | nullGet the currently active view of a given type.
(Inherited from Workspace)
getAdjacentLeafInDirection(leaf, direction)null | WorkspaceLeafGet adjacent leaf in specified direction.
(Inherited from Workspace)
getDropDirection(e, rect, directions, leaf)'bottom' | 'center' | 'left' | 'right' | 'top'Get the direction where the leaf should be dropped on dragevent
(Inherited from Workspace)
getDropLocation(e)null | WorkspaceLeafGet the leaf where the leaf should be dropped on dragevent.
(Inherited from Workspace)
getFocusedContainer()WorkspaceSplitGet the workspace split for the currently focused container.
(Inherited from Workspace)
getGroupLeaves(group)WorkspaceLeaf[]Get all leaves that belong to a group.
(Inherited from Workspace)
getLastOpenFiles()string[]Get the filenames of the 10 most recently opened files.
(Inherited from Workspace)
getLayout()Record<string, unknown>Get the layout of the workspace.
(Inherited from Workspace)
getLeaf(newLeaf?, direction?)WorkspaceLeafCreates a new leaf in a leaf adjacent to the currently active leaf. If direction is 'vertical', the leaf will appear to the right. If direction is 'horizontal', the leaf will appear below the current leaf.
(Inherited from Workspace)
getLeaf(newLeaf?)WorkspaceLeafIf newLeaf is false (or not set) then an existing leaf which can be navigated is returned, or a new leaf will be created if there was no leaf available.

If newLeaf is 'tab' or true then a new leaf will be created in the preferred location within the root split and returned.

If newLeaf is 'split' then a new leaf will be created adjacent to the currently active leaf.

If newLeaf is 'window' then a popout window will be created with a new leaf inside.
(Inherited from Workspace)
getLeafById(id)WorkspaceLeaf | nullRetrieve a leaf by its id.
(Inherited from Workspace)
getLeavesOfType(viewType)WorkspaceLeaf[]Get all leaves of a given type.
(Inherited from Workspace)
getLeavesOfType(viewType)TypedWorkspaceLeaf<ViewTypeViewMapping[TViewType]>[]Get leaves of a specific view type.

Declared before the string overload, which would otherwise match every literal first.
(Inherited from Workspace)
getLeftLeaf(split)WorkspaceLeaf | nullCreate a new leaf inside the left sidebar.
(Inherited from Workspace)
getMostRecentLeaf(root?)WorkspaceLeaf | nullGet the most recently active leaf in a given workspace root. Useful for interacting with the leaf in the root split while a sidebar leaf might be active.
(Inherited from Workspace)
getRecentFiles(options?)string[]Get n last opened files of type (defaults to 10).
(Inherited from Workspace)
getRightLeaf(split)WorkspaceLeaf | nullCreate a new leaf inside the right sidebar.
(Inherited from Workspace)
getSideLeaf(sideRibbon, split)WorkspaceLeafGet leaf in the side ribbon/dock and split if necessary.
(Inherited from Workspace)
getUnpinnedLeaf()WorkspaceLeafGet the unpinned leaf.
(Inherited from Workspace)
handleExternalLinkContextMenu(menu, linkText)voidHandle the context menu for an external URL link.
(Inherited from Workspace)
handleLinkContextMenu(menu, linktext, sourcePath, leaf?)booleanAdd a context menu to internal file links.
(Inherited from Workspace)
handleLinkContextMenu(menu, linkText, sourcePath, leaf?)voidHandle the context menu for an internal link.
(Inherited from Workspace)
hasUndoHistory()booleanCheck if there is any undo history available.
(Inherited from Workspace)
isAttached(leaf?)booleanCheck if leaf has been attached to the workspace
(Inherited from Workspace)
isInSidebar(leaf)booleanCheck if a leaf is in the sidebar.
(Inherited from Workspace)
isWorkspaceFocused()booleanChecks whether the workspace (the main window or a focused popout window) currently has focus.
(Inherited from Workspace)
iterateAllLeaves(callback)voidIterate through all leaves, including main area leaves, floating leaves, and sidebar leaves.
(Inherited from Workspace)
iterateCodeMirrors(_unused)voidIterate through all CodeMirror instances in the workspace.
(Inherited from Workspace)
iterateLeaves(split, callback)voidIterate the leaves of a split.
(Inherited from Workspace)
iterateRootLeaves(callback)voidIterate through all leaves in the main area of the workspace.
(Inherited from Workspace)
iterateTabs(tabs, cb)booleanIterate the tabs of a split till meeting a condition.
(Inherited from Workspace)
loadLayout()Promise<void>Load workspace from disk and initialize
(Inherited from Workspace)
moveLeafToPopout(leaf, data?)WorkspaceWindowMigrates this leaf to a new popout window. Only works on the desktop app.
(Inherited from Workspace)
off(name, callback)voidRemove an event listener.
(Inherited from Workspace)
offref(ref)voidRemove an event listener by reference.
(Inherited from Workspace)
on('quick-preview', callback, ctx?)EventRefTriggered when the active Markdown file is modified. React to file changes before they are saved to disk.
(Inherited from Workspace)
on('resize', callback, ctx?)EventRefTriggered when a WorkspaceItem is resized or the workspace layout has changed.
(Inherited from Workspace)
on('active-leaf-change', callback, ctx?)EventRefTriggered when the active leaf changes.
(Inherited from Workspace)
on('file-open', callback, ctx?)EventRefTriggered when the active file changes. The file could be in a new leaf, an existing leaf, or an embed.

Despite its name, this is a "focused file changed" event, not a "file was opened" one. It fires whenever Workspace.getActiveFile returns a different file than it did last time, so moving the focus to another leaf that already shows another file fires it too, while opening the file that is already active does not. The file is null when the newly active leaf shows no file.
(Inherited from Workspace)
on('layout-change', callback, ctx?)EventRefTriggered when the layout of the workspace changes.
(Inherited from Workspace)
on('window-open', callback, ctx?)EventRefTriggered when a new popout window is created.
(Inherited from Workspace)
on('window-close', callback, ctx?)EventRefTriggered when a popout window is closed.
(Inherited from Workspace)
on('css-change', callback, ctx?)EventRefTriggered when the CSS of the app has changed.
(Inherited from Workspace)
on('file-menu', callback, ctx?)EventRefTriggered when the user opens the context menu on a file.
(Inherited from Workspace)
on('files-menu', callback, ctx?)EventRefTriggered when the user opens the context menu with multiple files selected in the File Explorer.
(Inherited from Workspace)
on('url-menu', callback, ctx?)EventRefTriggered when the user opens the context menu on an external URL.
(Inherited from Workspace)
on('editor-menu', callback, ctx?)EventRefTriggered when the user opens the context menu on an editor.
(Inherited from Workspace)
on('editor-change', callback, ctx?)EventRefTriggered when changes to an editor has been applied, either programmatically or from a user event.
(Inherited from Workspace)
on('editor-paste', callback, ctx?)EventRefTriggered when the editor receives a paste event. Check for evt.defaultPrevented before attempting to handle this event, and return if it has been already handled. Use evt.preventDefault() to indicate that you've handled the event.
(Inherited from Workspace)
on('editor-drop', callback, ctx?)EventRefTriggered when the editor receives a drop event. Check for evt.defaultPrevented before attempting to handle this event, and return if it has been already handled. Use evt.preventDefault() to indicate that you've handled the event.
(Inherited from Workspace)
on('quit', callback, ctx?)EventRefTriggered when the app is about to quit. Not guaranteed to actually run. Perform some best effort cleanup here.
(Inherited from Workspace)
on('bookmarks:bookmarks-menu', callback, ctx?)EventRefTriggers when the context menu of a bookmark is opened in the Bookmarks view.
(Inherited from Workspace)
on('browser:update-history', callback, ctx?)EventRefTriggers when the browser history is updated.
(Inherited from Workspace)
on('canvas:edge-menu', callback, ctx?)EventRefTriggers when the user opens a context menu on a connection in the canvas.
(Inherited from Workspace)
on('canvas:node-connection-drop-menu', callback, ctx?)EventRefTriggers when the user drops edge connection to empty space in the canvas.
(Inherited from Workspace)
on('canvas:node-menu', callback, ctx?)EventRefTriggers when the user opens a context menu on a single node in the canvas.
(Inherited from Workspace)
on('canvas:selection-menu', callback, ctx?)EventRefTriggers when the user opens a context menu on a selection of multiple nodes in the canvas.
(Inherited from Workspace)
on('editor-selection-change', callback, ctx?)EventRefTriggers when the editor selection changes.
(Inherited from Workspace)
on('hover-link', callback, ctx?)EventRefTriggers when user hovers over any note link element (file explorer, editor, ...).
(Inherited from Workspace)
on('layout-ready', callback, ctx?)EventRefTriggers when workspace layout is loaded.
(Inherited from Workspace)
on('leaf-menu', callback, ctx?)EventRefTriggers when the leaf menu is opened.
(Inherited from Workspace)
on('markdown-properties-menu', callback, ctx?)EventRefTriggers when the properties menu of a note's metadata editor is opened.
(Inherited from Workspace)
on('markdown-scroll', callback, ctx?)EventRefTriggers when the markdown scroll event is fired.
(Inherited from Workspace)
on('markdown-viewport-menu', callback, ctx?)EventRefTriggers when the markdown viewport menu is opened.
(Inherited from Workspace)
on('receive-files-menu', callback, ctx?)EventRefTriggered when user shares files on mobile.
(Inherited from Workspace)
on('receive-text-menu', callback, ctx?)EventRefTriggered when user shares text on mobile.
(Inherited from Workspace)
on('search:results-menu', callback, ctx?)EventRefTriggers when user clicks on 'N results' button in search view.
(Inherited from Workspace)
on('swipe', callback, ctx?)EventRefTriggers when user swipes open left/right sidebar
(Inherited from Workspace)
on('tab-group-menu', callback, ctx?)EventRefCalled whenever user opens tab group menu (contains e.g. stacked tabs button)
(Inherited from Workspace)
on(name, callback, ctx?)EventRefAdd an event listener.
(Inherited from Workspace)
onDragLeaf(e, leaf)voidHandles drag event on leaf
(Inherited from Workspace)
onLayoutChange(leaf?)voidHandles layout change and saves layout to disk
(Inherited from Workspace)
onLayoutReady(callback)voidRuns the callback function right away if layout is already ready, or push it to a queue to be called later when layout is ready.
(Inherited from Workspace)
onQuickPreview(file, data)voidTrigger the quick preview event with the given arguments.
(Inherited from Workspace)
onResize()voidHandle a resize event on the workspace.
(Inherited from Workspace)
onStartLink(leaf)voidHandle the start of a link drag operation from a leaf.
(Inherited from Workspace)
openLinkText(linktext, sourcePath, newLeaf?, openViewState?)Promise<void>Open a link text.
(Inherited from Workspace)
openPopout(data?)WorkspaceWindowOpen a leaf in a popup window.
(Inherited from Workspace)
openPopoutLeaf(data?)WorkspaceLeafOpen a new popout window with a single new leaf and return that leaf. Only works on the desktop app.
(Inherited from Workspace)
pushUndoHistory(leaf, parentID, rootID)voidPush leaf change to history
(Inherited from Workspace)
readWorkspaceFile()Promise<SerializedWorkspace>Read workspace layout data from disk.
(Inherited from Workspace)
recursiveGetTarget(e, leaf)null | WorkspaceTabsGet drag event target location
(Inherited from Workspace)
registerEditorExtension(extension)voidRegister a CodeMirror editor extension.
(Inherited from Workspace)
registerHoverLinkSource(key, source)voidRegisters hover link source
(Inherited from Workspace)
registerObsidianProtocolHandler(protocol, handler)voidRegisters Obsidian protocol handler
(Inherited from Workspace)
registerOpenFileHandler()voidInstalls the desktop external-file open handler and processes a pending open request.
(Inherited from Workspace)
registerOperatorFuncConfigs(id, configs)voidRegister operator function configurations.
(Inherited from Workspace)
registerUriHook()voidConstructs hook for receiving URI actions
(Inherited from Workspace)
requestActiveLeafEvents()voidRequest execution of activeLeaf change events
(Inherited from Workspace)
requestLayoutChangeEvents()voidRequest execution of layout change events.
(Inherited from Workspace)
requestResize()voidRequest execution of resize event
(Inherited from Workspace)
requestUpdateLayout()voidRequest execution of layout update event
(Inherited from Workspace)
revealLeaf(leaf)Promise<void>Bring a given leaf to the foreground. If the leaf is in a sidebar, the sidebar will be uncollapsed. await this function to ensure your view has been fully loaded and is not deferred.
(Inherited from Workspace)
saveLayout()Promise<void>Save workspace layout to disk.
(Inherited from Workspace)
setActiveLeaf(leaf, params?)voidSets the active leaf.
(Inherited from Workspace)
setActiveLeaf(leaf, pushHistory, focus)voidSets the active leaf.
(Inherited from Workspace)
setLayout(data)Promise<void>Use deserialized layout data to reconstruct the workspace
(Inherited from Workspace)
splitActiveLeaf(direction?)WorkspaceLeafSplit the active leaf.
(Inherited from Workspace)
splitLeaf(leaf, newLeaf, direction?, before?)voidSplit leaves in specified direction
(Inherited from Workspace)
splitLeafOrActive(leaf?, direction?)WorkspaceLeafSplit provided leaf, or active leaf if none provided.
(Inherited from Workspace)
trigger(name, data?)voidTrigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Workspace)
tryTrigger(evt, args)voidTry to trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Workspace)
unregisterEditorExtension(extension)voidUnregister a CodeMirror editor extension
(Inherited from Workspace)
unregisterHoverLinkSource(key)voidUnregister hover link source
(Inherited from Workspace)
unregisterObsidianProtocolHandler(protocol, handler)voidUnregister Obsidian protocol handler
(Inherited from Workspace)
unregisterOperatorFuncConfigs(id)voidUnregister operator function configurations.
(Inherited from Workspace)
unsetActiveEditor(editor)voidUnset the active editor.
(Inherited from Workspace)
updateFrameless()voidUpdate the frameless window chrome (title bar) display.
(Inherited from Workspace)
updateLayout()voidInvoke workspace layout update, redraw and save
(Inherited from Workspace)
updateMobileVisibleTabGroup()voidUpdate visibility of tab group
(Inherited from Workspace)
updateOptions()voidCalling this function will update/reconfigure the options of all Markdown views. It is fairly expensive, so it should not be called frequently.
(Inherited from Workspace)
updateTitle()voidUpdate the internal title of the application.
(Inherited from Workspace)

Links to this page: