Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #49 from Aidurber/fix/codeblock-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidurber authored Mar 5, 2022
2 parents 862c4be + ee06781 commit 97df68a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/renderers/code-block-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { App, MarkdownRenderChild, MarkdownRenderer, TFile } from "obsidian";
import {
App,
MarkdownRenderChild,
MarkdownRenderer,
TFile,
WorkspaceLeaf,
} from "obsidian";
import { mergeSettings } from "../utils/config";
import { extractHeadings } from "../utils/extract-headings";
import { DynamicTOCSettings, TableOptions } from "../types";
Expand All @@ -22,16 +28,29 @@ export class CodeBlockRenderer extends MarkdownRenderChild {
this.onSettingsChangeHandler
)
);
this.registerEvent(
this.app.workspace.on(
"active-leaf-change",
this.onActiveLeafChangeHandler
)
);
this.registerEvent(
this.app.metadataCache.on("changed", this.onFileChangeHandler)
);
}

onActiveLeafChangeHandler = (_: WorkspaceLeaf) => {
const activeFile = this.app.workspace.getActiveFile();
this.filePath = activeFile.path;
this.onFileChangeHandler(activeFile);
};

onSettingsChangeHandler = (settings: DynamicTOCSettings) => {
this.render(mergeSettings(this.config, settings));
};
onFileChangeHandler = (file: TFile) => {
if (file.deleted || file.path !== this.filePath) return;
this.filePath = file.path;
if (file.deleted) return;
this.render();
};

Expand Down

0 comments on commit 97df68a

Please sign in to comment.