Workspace

Workspace class

Signature:

export class Workspace extends Events 

Extends: Events

Properties

PropertyModifiersTypeDescription
activeEditorMarkdownFileInfo | nullA component managing the current editor. This can be null if the active view has no editor.
activeLeafWorkspaceLeaf | null

Indicates the currently focused leaf, if one exists.

Please avoid using activeLeaf directly, especially without checking whether activeLeaf is null.

containerElHTMLElement
layoutReadybooleanIf the layout of the app has been successfully initialized. To react to the layout becoming ready, use Workspace.onLayoutReady()
leftRibbonWorkspaceRibbon
leftSplitWorkspaceSidedock | WorkspaceMobileDrawer
requestSaveLayoutDebouncer<[], Promise<void>>Save the state of the current workspace layout.
rightRibbonWorkspaceRibbon
rightSplitWorkspaceSidedock | WorkspaceMobileDrawer
rootSplitWorkspaceRoot

Methods

MethodModifiersDescription
changeLayout(workspace)
createLeafBySplit(leaf, direction, before)
createLeafInParent(parent, index)
detachLeavesOfType(viewType)Remove all leaves of the given type.
duplicateLeaf(leaf, direction)
duplicateLeaf(leaf, leafType, direction)
ensureSideLeaf(type, side, options)Get side leaf or create one if one does not exist.
getActiveFile()Returns the file for the current view if it’s a FileView. Otherwise, it will return the most recently active file.
getActiveViewOfType(type)Get the currently active view of a given type.
getGroupLeaves(group)Get all leaves that belong to a group
getLastOpenFiles()Get the filenames of the 10 most recently opened files.
getLayout()
getLeaf(newLeaf, direction)Creates 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.
getLeaf(newLeaf)

If 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.

getLeafById(id)Retrieve a leaf by its id.
getLeavesOfType(viewType)Get all leaves of a given type.
getLeftLeaf(split)Create a new leaf inside the left sidebar.
getMostRecentLeaf(root)Get 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.
getRightLeaf(split)Create a new leaf inside the right sidebar.
getUnpinnedLeaf()
iterateAllLeaves(callback)Iterate through all leaves, including main area leaves, floating leaves, and sidebar leaves.
iterateRootLeaves(callback)Iterate through all leaves in the main area of the workspace.
moveLeafToPopout(leaf, data)Migrates this leaf to a new popout window. Only works on the desktop app.
off(name, callback)

(Inherited from Events)

offref(ref)

(Inherited from Events)

on(name: 'quick-preview', callback, ctx)Triggered when the active Markdown file is modified. React to file changes before they are saved to disk.
on(name: 'files-menu', callback, ctx)Triggered when the user opens the context menu with multiple files selected in the File Explorer.
on(name: 'url-menu', callback, ctx)Triggered when the user opens the context menu on an external URL.
on(name: 'editor-menu', callback, ctx)Triggered when the user opens the context menu on an editor.
on(name: 'editor-change', callback, ctx)Triggered when changes to an editor has been applied, either programmatically or from a user event.
on(name: 'editor-paste', callback, ctx)Triggered 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.
on(name: 'editor-drop', callback, ctx)Triggered 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.
on(name: 'quit', callback, ctx)Triggered when the app is about to quit. Not guaranteed to actually run. Perform some best effort cleanup here.
on(name: 'resize', callback, ctx)Triggered when a WorkspaceItem is resized or the workspace layout has changed.
on(name: 'active-leaf-change', callback, ctx)Triggered when the active leaf changes.
on(name: 'file-open', callback, ctx)Triggered when the active file changes. The file could be in a new leaf, an existing leaf, or an embed.
on(name: 'layout-change', callback, ctx)
on(name: 'window-open', callback, ctx)Triggered when a new popout window is created.
on(name: 'window-close', callback, ctx)Triggered when a popout window is closed.
on(name: 'css-change', callback, ctx)Triggered when the CSS of the app has changed.
on(name: 'file-menu', callback, ctx)Triggered when the user opens the context menu on a file.
onLayoutReady(callback)Runs the callback function right away if layout is already ready, or push it to a queue to be called later when layout is ready.
openLinkText(linktext, sourcePath, newLeaf, openViewState)
openPopoutLeaf(data)Open a new popout window with a single new leaf and return that leaf. Only works on the desktop app.
revealLeaf(leaf)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.
setActiveLeaf(leaf, params)Sets the active leaf
setActiveLeaf(leaf, pushHistory, focus)
splitActiveLeaf(direction)
trigger(name, data)

(Inherited from Events)

tryTrigger(evt, args)

(Inherited from Events)

updateOptions()Calling this function will update/reconfigure the options of all Markdown views. It is fairly expensive, so it should not be called frequently.