Workspace.on('file-open') method
Workspace › on(‘file-open’)
Official
Triggered when the active file changes. The file could be in a new leaf, an existing leaf, or an embed.Signature:
on(name: "file-open", callback: (file: TFile | null) => unknown, ctx?: unknown): EventRefParameters:
| Parameter | Type | Description |
|---|---|---|
| name | "file-open" | Should be 'file-open'. |
| callback | (file: TFile | null) => unknown | The callback function. |
| ctx? | unknown | The context passed as this to the callback function. |
Returns: EventRef — The event reference.
Example:
app.workspace.on('file-open', (file) => { console.log(file);});