Workspace
Extends
Constructors
new Workspace()
new Workspace():
Workspace
Returns
Inherited from
Properties
_
_:
Record
<string
,EventsEntry
[]>
Inherited from
activeEditor
activeEditor:
null
|MarkdownFileInfo
A component managing the current editor. This can be null if the active view has no editor.
activeLeaf
activeLeaf:
null
|WorkspaceLeaf
Indicates the currently focused leaf, if one exists.
Please avoid using activeLeaf
directly, especially without checking whether
activeLeaf
is null.
activeTabGroup
activeTabGroup:
WorkspaceTabs
Currently active tab group
app
app:
App
Reference to App
containerEl
containerEl:
HTMLElement
editorExtensions
editorExtensions:
Extension
[]
Registered CodeMirror editor extensions, to be applied to all CM instances
lastActiveFile
lastActiveFile:
TFile
Last opened file in the vault
layoutReady
layoutReady:
boolean
If the layout of the app has been successfully initialized. To react to the layout becoming ready, use Workspace.onLayoutReady
leftRibbon
leftRibbon:
WorkspaceRibbon
leftSplit
leftSplit:
WorkspaceSidedock
|WorkspaceMobileDrawer
protocolHandlers
protocolHandlers:
Map
<string
,ObsidianProtocolHandler
>
Protocol handlers registered on the workspace
recentFileTracker
recentFileTracker:
RecentFileTracker
Tracks last opened files in the vault
requestSaveLayout
Save the state of the current workspace layout.
rightRibbon
rightRibbon:
WorkspaceRibbon
rightSplit
rightSplit:
WorkspaceSidedock
|WorkspaceMobileDrawer
rootSplit
rootSplit:
WorkspaceRoot
undoHistory
undoHistory:
StateHistory
[]
List of states that were closed and may be reopened
Methods
changeLayout()
changeLayout(
workspace
):Promise
<void
>
Parameters
• workspace: any
Returns
Promise
<void
>
createLeafBySplit()
createLeafBySplit(
leaf
,direction
?,before
?):WorkspaceLeaf
Parameters
• leaf: WorkspaceLeaf
• direction?: SplitDirection
• before?: boolean
Returns
createLeafInParent()
createLeafInParent(
parent
,index
):WorkspaceLeaf
Parameters
• parent: WorkspaceSplit
• index: number
Returns
detachLeavesOfType()
detachLeavesOfType(
viewType
):void
Remove all leaves of the given type.
Parameters
• viewType: string
Returns
void
duplicateLeaf()
duplicateLeaf(leaf, direction)
duplicateLeaf(
leaf
,direction
?):Promise
<WorkspaceLeaf
>
Parameters
• leaf: WorkspaceLeaf
• direction?: SplitDirection
Returns
duplicateLeaf(leaf, leafType, direction)
duplicateLeaf(
leaf
,leafType
,direction
?):Promise
<WorkspaceLeaf
>
Parameters
• leaf: WorkspaceLeaf
• leafType: boolean
| PaneType
• direction?: SplitDirection
Returns
ensureSideLeaf()
ensureSideLeaf(
type
,side
,options
?):Promise
<WorkspaceLeaf
>
Get side leaf or create one if one does not exist.
Parameters
• type: string
• side: Side
• options?
• options.active?: boolean
• options.reveal?: boolean
• options.split?: boolean
• options.state?: any
Returns
getActiveFile()
getActiveFile():
null
|TFile
Returns the file for the current view if it’s a FileView
.
Otherwise, it will return the most recently active file.
Returns
null
| TFile
getActiveFileView()
getActiveFileView():
null
|FileView
Get active file view if exists
Returns
null
| FileView
getActiveLeafOfViewType()
getActiveLeafOfViewType<
T
>(type
):null
|T
Type Parameters
• T extends View
Parameters
• type: Constructor
<T
>
Returns
null
| T
getActiveViewOfType()
getActiveViewOfType<
T
>(type
):null
|T
Get the currently active view of a given type.
Type Parameters
• T extends View
Parameters
• type: Constructor
<T
>
Returns
null
| T
getAdjacentLeafInDirection()
getAdjacentLeafInDirection(
leaf
,direction
):null
|WorkspaceLeaf
Get adjacent leaf in specified direction
Parameters
• leaf: WorkspaceLeaf
• direction: "left"
| "right"
| "bottom"
| "top"
Returns
null
| WorkspaceLeaf
getFocusedContainer()
getFocusedContainer():
WorkspaceSplit
Get the workspace split for the currently focused container
Returns
getGroupLeaves()
getGroupLeaves(
group
):WorkspaceLeaf
[]
Get all leaves that belong to a group
Parameters
• group: string
id
Returns
getLastOpenFiles()
getLastOpenFiles():
string
[]
Get the filenames of the 10 most recently opened files.
Returns
string
[]
getLayout()
getLayout():
Record
<string
,unknown
>
Returns
Record
<string
, unknown
>
getLeaf()
getLeaf(newLeaf, direction)
getLeaf(
newLeaf
?,direction
?):WorkspaceLeaf
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.
Parameters
• newLeaf?: "split"
• direction?: SplitDirection
Returns
getLeaf(newLeaf)
getLeaf(
newLeaf
?):WorkspaceLeaf
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.
Parameters
• newLeaf?: boolean
| PaneType
Returns
getLeafById()
getLeafById(
id
):null
|WorkspaceLeaf
Retrieve a leaf by its id.
Parameters
• id: string
id of the leaf to retrieve.
Returns
null
| WorkspaceLeaf
getLeavesOfType()
getLeavesOfType(viewType)
getLeavesOfType(
viewType
):WorkspaceLeaf
[]
Get all leaves of a given type.
Parameters
• viewType: string
Returns
getLeavesOfType(viewType)
getLeavesOfType(
viewType
):FileExplorerLeaf
[]
Parameters
• viewType: "file-explorer"
Returns
getLeftLeaf()
getLeftLeaf(
split
):null
|WorkspaceLeaf
Create a new leaf inside the left sidebar.
Parameters
• split: boolean
Should the existing split be split up?
Returns
null
| WorkspaceLeaf
getMostRecentLeaf()
getMostRecentLeaf(
root
?):null
|WorkspaceLeaf
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.
Parameters
• root?: WorkspaceParent
Root for the leaves you want to search. If a root is not provided, the rootSplit
and leaves within pop-outs will be searched.
Returns
null
| WorkspaceLeaf
getRecentFiles()
getRecentFiles(
arg
?):string
[]
Get n last opened files of type (defaults to 10)
Parameters
• arg?
• arg.maxCount?: number
• arg.showCanvas?: boolean
• arg.showImages?: boolean
• arg.showMarkdown?: boolean
• arg.showNonImageAttachments?: boolean
Returns
string
[]
getRightLeaf()
getRightLeaf(
split
):null
|WorkspaceLeaf
Create a new leaf inside the right sidebar.
Parameters
• split: boolean
Should the existing split be split up?
Returns
null
| WorkspaceLeaf
getSideLeaf()
getSideLeaf(
sideRibbon
,split
):WorkspaceLeaf
Get leaf in the side ribbon/dock and split if necessary
Parameters
• sideRibbon: WorkspaceSidedock
| WorkspaceMobileDrawer
Side ribbon to get leaf from
• split: boolean
Whether to split the leaf if it does not exist
Returns
getUnpinnedLeaf()
getUnpinnedLeaf():
WorkspaceLeaf
Returns
iterateAllLeaves()
iterateAllLeaves(
callback
):void
Iterate through all leaves, including main area leaves, floating leaves, and sidebar leaves.
Parameters
• callback
Returns
void
iterateLeaves()
iterateLeaves(
split
,callback
):void
Iterate the leaves of a split
Parameters
• split: WorkspaceSplit
• callback
Returns
void
iterateRootLeaves()
iterateRootLeaves(
callback
):void
Iterate through all leaves in the main area of the workspace.
Parameters
• callback
Returns
void
iterateTabs()
iterateTabs(
tabs
,cb
):boolean
Iterate the tabs of a split till meeting a condition
Parameters
• tabs: WorkspaceSplit
| WorkspaceSplit
[]
• cb
Returns
boolean
moveLeafToPopout()
moveLeafToPopout(
leaf
,data
?):WorkspaceWindow
Migrates this leaf to a new popout window. Only works on the desktop app.
Parameters
• leaf: WorkspaceLeaf
• data?: WorkspaceWindowInitData
Returns
Throws
Error if the app does not support popout windows (i.e. on mobile or if Electron version is too old)
off()
off(
name
,callback
):void
Parameters
• name: string
• callback
Returns
void
Inherited from
offref()
offref(
ref
):void
Parameters
• ref: EventRef
Returns
void
Inherited from
on()
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the active Markdown file is modified. React to file changes before they are saved to disk.
Parameters
• name: "quick-preview"
• callback
• ctx?: any
Returns
Inherited from
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when a WorkspaceItem
is resized or the workspace layout has changed.
Parameters
• name: "resize"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the active leaf changes.
Parameters
• name: "active-leaf-change"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the active file changes. The file could be in a new leaf, an existing leaf, or an embed.
Parameters
• name: "file-open"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Parameters
• name: "layout-change"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when a new popout window is created.
Parameters
• name: "window-open"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when a popout window is closed.
Parameters
• name: "window-close"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the CSS of the app has changed.
Parameters
• name: "css-change"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the user opens the context menu on a file.
Parameters
• name: "file-menu"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the user opens the context menu with multiple files selected in the File Explorer.
Parameters
• name: "files-menu"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the user opens the context menu on an external URL.
Parameters
• name: "url-menu"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the user opens the context menu on an editor.
Parameters
• name: "editor-menu"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when changes to an editor has been applied, either programmatically or from a user event.
Parameters
• name: "editor-change"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
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.
Parameters
• name: "editor-paste"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
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.
Parameters
• name: "editor-drop"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggered when the app is about to quit. Not guaranteed to actually run. Perform some best effort cleanup here.
Parameters
• name: "quit"
• callback
• ctx?: any
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the browser history is updated.
Parameters
• name: "browser:update-history"
‘browser:update-history’
• callback
Callback function
• ctx?: unknown
Context
Returns
Event reference
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the user opens a context menu on a connection in the canvas
Parameters
• name: "canvas:edge-menu"
• callback
• ctx?: unknown
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the user drops edge connection to empty space in the canvas
Parameters
• name: "canvas:node-connection-drop-menu"
• callback
• ctx?: unknown
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the user opens a context menu on a single node in the canvas
Parameters
• name: "canvas:node-menu"
• callback
• ctx?: unknown
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the user opens a context menu on a selection of multiple nodes in the canvas
Parameters
• name: "canvas:selection-menu"
• callback
• ctx?: unknown
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the editor selection changes.
Parameters
• name: "editor-selection-change"
‘editor-selection-change’
• callback
Callback function
• ctx?: unknown
Context
Returns
Event reference
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when workspace layout is loaded
Parameters
• name: "layout-ready"
• callback
• ctx?: unknown
Returns
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the leaf menu is opened.
Parameters
• name: "leaf-menu"
‘leaf-menu’
• callback
Callback function
• ctx?: unknown
Context
Returns
Event reference
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the markdown scroll event is fired.
Parameters
• name: "markdown-scroll"
‘markdown-scroll’
• callback
Callback function
• ctx?: unknown
Context
Returns
Event reference
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when the markdown viewport menu is opened.
Parameters
• name: "markdown-viewport-menu"
‘markdown-viewport-menu’
• callback
Callback function
• ctx?: unknown
Context
Returns
Event reference
Inherited from
Events.on
on(name, callback, ctx)
on(
name
,callback
,ctx
?):EventRef
Triggers when user clicks on ‘N results’ button in search view
Parameters
• name: "search:results-menu"
• callback
• ctx?: unknown
Returns
Inherited from
Events.on
onLayoutReady()
onLayoutReady(
callback
):void
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.
Parameters
• callback
Returns
void
openLinkText()
openLinkText(
linktext
,sourcePath
,newLeaf
?,openViewState
?):Promise
<void
>
Parameters
• linktext: string
• sourcePath: string
• newLeaf?: boolean
| PaneType
• openViewState?: OpenViewState
Returns
Promise
<void
>
openPopout()
openPopout(
data
?):WorkspaceWindow
Open a leaf in a popup window
Parameters
• data?: WorkspaceWindowInitData
Returns
openPopoutLeaf()
openPopoutLeaf(
data
?):WorkspaceLeaf
Open a new popout window with a single new leaf and return that leaf. Only works on the desktop app.
Parameters
• data?: WorkspaceWindowInitData
Returns
revealLeaf()
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.
Parameters
• leaf: WorkspaceLeaf
Returns
Promise
<void
>
saveLayout()
saveLayout():
Promise
<void
>
Save workspace layout to disk
Returns
Promise
<void
>
setActiveLeaf()
setActiveLeaf(leaf, params)
setActiveLeaf(
leaf
,params
?):void
Sets the active leaf
Parameters
• leaf: WorkspaceLeaf
The new active leaf
• params?
Parameter object of whether to set the focus.
• params.focus?: boolean
Returns
void
setActiveLeaf(leaf, pushHistory, focus)
setActiveLeaf(
leaf
,pushHistory
,focus
):void
Parameters
• leaf: WorkspaceLeaf
• pushHistory: boolean
• focus: boolean
Returns
void
splitActiveLeaf()
splitActiveLeaf(
direction
?):WorkspaceLeaf
Parameters
• direction?: SplitDirection
Returns
splitLeafOrActive()
splitLeafOrActive(
leaf
?,direction
?):WorkspaceLeaf
Split provided leaf, or active leaf if none provided
Parameters
• leaf?: WorkspaceLeaf
• direction?: SplitDirection
Returns
trigger()
trigger(
name
, …data
):void
Parameters
• name: string
• …data: unknown
[]
Returns
void
Inherited from
tryTrigger()
tryTrigger(
evt
,args
):void
Parameters
• evt: EventRef
• args: unknown
[]
Returns
void
Inherited from
updateOptions()
updateOptions():
void
Calling this function will update/reconfigure the options of all Markdown views. It is fairly expensive, so it should not be called frequently.
Returns
void
updateTitle()
updateTitle():
void
Update the internal title of the application
Returns
void