Skip to content

Commit 4c30b46

Browse files
committed
feat: safe folder access
Creates the folder if it does not exist, probably deleted after the setting has been set.
1 parent 06e4613 commit 4c30b46

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/generator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export async function generate(app: App,
1818
try {
1919
console.debug("Started generation");
2020
let div: HTMLElement;
21-
// if (app.vault.getAbstractFileByPath(".thumbnail")) {
22-
// await app.vault.createFolder(".thumbnail");
23-
// };
21+
if (!app.vault.getAbstractFileByPath(`${plugin.settings.folder}`)) {
22+
await app.vault.createFolder(`${plugin.settings.folder}`);
23+
}
24+
2425
const width = 1080;
2526
const height = Math.round(width * (rHeight / rWidth));
2627

@@ -109,13 +110,16 @@ async function renderCM(
109110
width: number,
110111
) {
111112
try {
113+
const prevLeaf = app.workspace.getMostRecentLeaf();
112114
console.debug("Rendering via CodeMirror");
113-
const leaf: WorkspaceLeaf = app.workspace.getLeaf(true);
115+
const leaf: WorkspaceLeaf = app.workspace.getLeaf("tab");
114116
await leaf.openFile(file, { active: false });
115117
const view: MarkdownView = leaf.view as MarkdownView;
116118
const state = view.getState() as { mode: string };
117119
const container = document.body.createDiv();
118120

121+
app.workspace.setActiveLeaf(prevLeaf, { focus: true});
122+
119123
if (state.mode != "preview") {
120124
await view.setState({ mode: "preview" }, { history: false });
121125
}

0 commit comments

Comments
 (0)