Hi, first time plugin dev here. I’m working on a plugin that allows the user to select/mark arbitrary text parts of external markdown files. In order to accomplish this, i tried extending the existing MarkdownView
from obsidian.
Unfortunately, i can’t get it to work. When i call this.app.workspace.getLeavesOfType(EstFileView.viewType);
i get a null result. There seems to be something special going on with the MarkdownView
type. If i extend ItemView
instead of MarkdownView
, it works without problems, e.g. the result of this.app.workspace.getLeavesOfType(EstFileView.viewType);
is the view.
Some excerpts:
I registered the view:
this.registerView(
EstFileView.viewType,
(leaf: WorkspaceLeaf) => new EstFileView(leaf, this.settings)
);
I create the view and right afterwards try to get it, but the result is null:
await this.app.workspace.getRightLeaf(true).setViewState({
type: EstFileView.viewType,
// active: true,
});
const views = this.app.workspace.getLeavesOfType(EstFileView.viewType);
console.log("views of type", views);
Beginning of my view class:
import { ItemView, MarkdownView, WorkspaceLeaf } from "obsidian";
import type { PluginSettings} from "../main"
import type TrackedFile from "../model/TrackedFile";
export default class EstFileView extends MarkdownView {
If i change extends MarkdownView
to extends ItemView
here, everything works fine.
Does anybody have an idea how to get a view extending MarkdownView to work or is there maybe a better approach to this? Basically i just need a view that can display Markdown text, and that gives me the ability to mark and highlight certain areas of the text.
What would also help would be to take a look at the MarkdownView sourcecode. But it looks like that part is closed source by the obsidian developers. Is that correct?