Skip to content

Commit

Permalink
Fix the afforementioned embed problem as well as avoiding redundant r…
Browse files Browse the repository at this point in the history
…enderMath() calls by remembering the last loaded preamble (what a dumb mistake I made...)
  • Loading branch information
RyotaUshio committed Nov 25, 2023
1 parent 0ead81a commit c26354b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default class MathJaxPreamblePlugin extends Plugin {
}

async rerender() {
this.manager.forgetHistory();

for (const leaf of this.app.workspace.getLeavesOfType('markdown')) {
const view = leaf.view as MarkdownView;
const state = view.getState();
Expand Down
20 changes: 11 additions & 9 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export class PreambleManager extends Component {
preambles: Map<string, Preamble>;
/** Maps folder path to preamble path. */
folderPreambles: Map<string, string>;
/** Maps sourcePath to preamble path. */
// sourcePreambleMap: Map<string, string>;
/** Stores the path of the last loaded preamble. */
lastPreamblePath: string | null;

constructor(public plugin: MathJaxPreamblePlugin, private serialized: SerializedPreambles) {
super();
this.app = plugin.app;
this.preambles = new Map();
this.folderPreambles = new Map<string, string>();
// this.sourcePreambleMap = new Map<string, string>();
this.lastPreamblePath = null;
}

onload() {
Expand Down Expand Up @@ -195,12 +195,14 @@ export class PreambleManager extends Component {
loadPreamble(sourcePath: string, frontmatter?: { preamble?: string }) {
const preamble = this.resolvedPreamble(sourcePath, frontmatter);
if (preamble?.content) {
// const lastPreamblePath = this.sourcePreambleMap.get(sourcePath);
// console.log({sourcePath, lastPreamblePath, preamblePath: preamble.path});
// if (lastPreamblePath !== preamble.path) {
// this.sourcePreambleMap.set(sourcePath, preamble.path);
renderMath(preamble.content, false);
// }
if (this.lastPreamblePath !== preamble.path) {
renderMath(preamble.content, false);
this.lastPreamblePath = preamble.path;
}
}
}

forgetHistory() {
this.lastPreamblePath = null;
}
}

0 comments on commit c26354b

Please sign in to comment.