Skip to content

Commit a3be04e

Browse files
committed
[Fix] update code based on comments from @lishid
See obsidianmd/obsidian-releases#330
1 parent 69eedc3 commit a3be04e

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "obsidian-advanced-new-file",
33
"name": "Advanced new file",
4-
"version": "1.0.0",
5-
"minAppVersion": "0.9.12",
4+
"version": "1.0.1",
5+
"minAppVersion": "0.9.7",
66
"description": "This is a plugin for choosing folder on note creation.",
77
"author": "vanadium23",
88
"authorUrl": "https://vanadium23.me/",

src/main.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ export default class AdvancedNewFilePlugin extends Plugin {
99
this.addCommand({
1010
id: 'advanced-new-file',
1111
name: 'Create note',
12-
checkCallback: (checking: boolean) => {
13-
let leaf = this.app.workspace.activeLeaf;
14-
if (leaf) {
15-
if (!checking) {
16-
new ChooseFolderModal(this.app).open();
17-
}
18-
return true;
19-
}
20-
return false;
12+
callback: () => {
13+
new ChooseFolderModal(this.app).open();
2114
}
2215
});
2316
}

src/modal.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, FuzzySuggestModal, TFolder, Notice } from 'obsidian';
1+
import { App, FuzzySuggestModal, TFolder, Notice, Vault } from 'obsidian';
22

33
const EMPTY_TEXT = 'No files found to append content. Enter to create a new one.'
44
const PLACEHOLDER_TEXT = 'Type file to append to or create';
@@ -20,11 +20,12 @@ export class ChooseFolderModal extends FuzzySuggestModal<TFolder>{
2020
}
2121

2222
init() {
23-
const files = this.app.vault.getFiles();
2423
const folders = new Set() as Set<TFolder>;
25-
for (const file of files) {
26-
folders.add(file.parent)
27-
}
24+
Vault.recurseChildren(this.app.vault.getRoot(), (file) => {
25+
if (file instanceof TFolder) {
26+
folders.add(file);
27+
}
28+
});
2829
this.folders = Array.from(folders);
2930
this.emptyStateText = EMPTY_TEXT;
3031
this.setPlaceholder(PLACEHOLDER_TEXT);
@@ -84,7 +85,7 @@ export class ChooseFolderModal extends FuzzySuggestModal<TFolder>{
8485
const file = await this.app.vault.create(fileName, "");
8586
this.app.workspace.activeLeaf.openFile(file);
8687
} catch (error) {
87-
new Notice(error);
88+
new Notice(error.toString());
8889
}
8990
}
9091

versions.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"1.0.1": "0.9.7",
23
"1.0.0": "0.9.7"
34
}

0 commit comments

Comments
 (0)