Add null protection.

I was getting "extension could not load error" on starting up obsidian.
This was because of leaf not being its expected value.
This commit is contained in:
bakuzan 2023-01-21 09:02:05 +00:00 committed by GitHub
parent 9e6550f407
commit 29766d2fe6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,7 +72,7 @@ export default class BetterWordCount extends Plugin {
giveEditorPlugin(leaf: WorkspaceLeaf): void { giveEditorPlugin(leaf: WorkspaceLeaf): void {
//@ts-expect-error, not typed //@ts-expect-error, not typed
const editor = leaf.view.editor; const editor = leaf?.view?.editor;
if (editor) { if (editor) {
const editorView = editor.cm as EditorView; const editorView = editor.cm as EditorView;
const editorPlug = editorView.plugin(editorPlugin); const editorPlug = editorView.plugin(editorPlugin);