Skip to content

Commit

Permalink
feat: Preselect current folder on chooseFolder modal
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
vanadium23 committed Mar 4, 2023
1 parent 045627d commit 694b70d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ChooseFolderModal.ts
@@ -1,4 +1,4 @@
import { App, FuzzySuggestModal, TFolder, Vault } from 'obsidian';
import { App, FuzzySuggestModal, TFolder, Vault, MarkdownView, TFile } from 'obsidian';
import CreateNoteModal from './CreateNoteModal';
import { NewFileLocation } from './enums';

Expand Down Expand Up @@ -29,12 +29,23 @@ export default class ChooseFolderModal extends FuzzySuggestModal<TFolder> {

init() {
const folders = new Set() as Set<TFolder>;
const sortedFolders = [] as TFolder[];
let leaf = this.app.workspace.getLeaf(false);
if (leaf &&
leaf.view instanceof MarkdownView &&
leaf.view.file instanceof TFile &&
leaf.view.file.parent instanceof TFolder) {
// pre-select current folder
folders.add(leaf.view.file.parent);
sortedFolders.push(leaf.view.file.parent);
}
Vault.recurseChildren(this.app.vault.getRoot(), (file) => {
if (file instanceof TFolder) {
if (file instanceof TFolder && !folders.has(file)) {
folders.add(file);
sortedFolders.push(file);
}
});
this.folders = Array.from(folders);
this.folders = sortedFolders;
this.emptyStateText = EMPTY_TEXT;
this.setPlaceholder(PLACEHOLDER_TEXT);
this.setInstructions(instructions);
Expand Down

0 comments on commit 694b70d

Please sign in to comment.