Using the Obsidian API, is the "MarkdownView" type available in dataviewjs?

If you look at the documentation fro app.workspace.activeLeaf it suggests that you should use app.workspace.getActiveViewOfType(). However, this function requires a Constructor<T> like the constructor reference ( or whatever this is called) to MarkdownView.

My problem is this: How do I get that reference when calling these functions from within a dataviewjs script, or other javascript code?

I know that QuickAdd exposes these classes/constructors in their user scripts through the params.obsidian.* structures. But I don’t know how to get this params from within dataviewjs. Is it the same as doing the following, and is this an acceptable approach:

```dataviewjs
const obsidian = require('obsidian')
const activeView = app.workspace.getActiveViewOfType(obsidian.MarkdownView)
...
```

In other words, are there better ways of getting the activeView other than using app.workspace.activeLeaf, or the method above, and what would that be?

When the active view is MarkdownView, you can get the reference to it by app.workspace.activeEditor.

FYI, this page of the documentation seems to say activeEditor is an Editor object, but it’s not true.

(I’m not sure if it’s better than activeLeaf?.view, but there is also the undocumented app.workspace.getActiveFileView() method)

1 Like