Skip to content

Commit

Permalink
fix: lowercase broke the file suggester
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jun 11, 2024
1 parent 805f18a commit 1d6c1ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
26 changes: 18 additions & 8 deletions src/fileSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ export class FolderSuggester extends AbstractInputSuggest<TFolder> {
}

getSuggestions(query: string): TFolder[] {
const folders: TFolder[] = [];
this.app.vault.getAllLoadedFiles().forEach((folder) => {
if (folder instanceof TFolder && folder.path.contains(query.toLowerCase())) {
folders.push(folder);
}
//@ts-ignore
return this.app.vault.getAllFolders().filter((folder: TFolder) => {
return folder.path.toLowerCase().contains(query.toLowerCase());
});
return folders;
}

selectSuggestion(value: TFolder, _evt: MouseEvent | KeyboardEvent): void {
Expand All @@ -46,6 +43,18 @@ export class FileSuggester extends AbstractInputSuggest<TFile> {
el.setText(value.path);
}

recursiveChildren(folder: TFolder): TFile[] {
const files: TFile[] = [];
folder.children.forEach((file) => {
if (file instanceof TFile) {
files.push(file);
} else if (file instanceof TFolder) {
files.push(...this.recursiveChildren(file));
}
});
return files;
}

private errorMessages = i18next.t("template.error");

getSuggestions(query: string): TFile[] {
Expand All @@ -62,11 +71,12 @@ export class FileSuggester extends AbstractInputSuggest<TFile> {
new Notice(this.errorMessages);
return [];
}
const files: TFile[] = templaterFolder.children.filter(

const files: TFile[] = this.recursiveChildren(templaterFolder).filter(
(file) =>
file instanceof TFile &&
file.extension === "md" &&
file.path.contains(query.toLowerCase())
file.path.toLowerCase().contains(query.toLowerCase())
) as TFile[];
return files;
}
Expand Down
23 changes: 13 additions & 10 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,27 @@ export class NoteInFolderSettingsTab extends PluginSettingTab {
folder.commandName.replace(/ \(\d+\)+/, "")
);
if (duplicatedFolders.length > 0) {
defaultSettings.commandName = `${folder.commandName.replace(/ \(\d+\)+/, "")} (${
duplicatedFolders.length
})`;
defaultSettings.commandName = `${folder.commandName.replace(/ \(\d+\)+/, "")} (${duplicatedFolders.length
})`;
}
return defaultSettings;
}

addTooltip(text: string, cb: HTMLElement) {
cb.onfocus = () => {
const tooltip = cb.parentElement?.createEl("div", { text: text, cls: "tooltip" });
if (tooltip) {
const rec = cb.getBoundingClientRect();
tooltip.style.top = `${rec.top + rec.height + 5}px`;
tooltip.style.left = `${rec.left + rec.width / 2}px`;
}
const tooltip = document.body.createEl("div", { text, cls: "tooltip" });
if (!tooltip) return;
tooltip.createEl("div", { cls: "tooltip-arrow" });
const rec = cb.getBoundingClientRect();
tooltip.style.top = `${rec.top + rec.height + 5}px`;
tooltip.style.left = `${rec.left + rec.width / 2}px`;
tooltip.style.right = `${rec.right}px`;
tooltip.style.width = `max-content`;
tooltip.style.height = `max-content`;
};
cb.onblur = () => {
cb.parentElement?.querySelector(".tooltip")?.remove();
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
activeDocument.querySelector(".tooltip")?.remove();
};
}
}

0 comments on commit 1d6c1ab

Please sign in to comment.