Skip to content

Commit

Permalink
refactor: Update folder suggester to use new Obsidian API
Browse files Browse the repository at this point in the history
  • Loading branch information
observerw committed Jul 6, 2024
1 parent 44d7478 commit 0b45fb6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 245 deletions.
2 changes: 1 addition & 1 deletion src/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export abstract class Component {
protected _plugin: CodeLinkPlugin,
protected _sourcePath: string
) {
this._containerEl = document.createEl("div");
this._containerEl = createEl("div");
}

markdown(el: HTMLElement, markdownText: string): void {
Expand Down
2 changes: 1 addition & 1 deletion src/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Notice, PluginSettingTab, Setting } from "obsidian";
import CodeLinkPlugin from "src/main";
import { FolderSuggest } from "./suggester/folder";
import { FolderSuggest } from "./suggester";
import { SupportedLangsArray } from "src/lang/data";

export interface CodeLinkPluginSettings {
Expand Down
33 changes: 0 additions & 33 deletions src/settings/suggester/folder.ts

This file was deleted.

27 changes: 27 additions & 0 deletions src/settings/suggester/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { AbstractInputSuggest, TAbstractFile, TFolder } from "obsidian";

export class FolderSuggest extends AbstractInputSuggest<TFolder> {
protected getSuggestions(query: string): TFolder[] | Promise<TFolder[]> {
const abstractFiles = this.app.vault.getAllLoadedFiles();
const folders: TFolder[] = [];
const lowerCaseInputStr = query.toLowerCase();

abstractFiles.forEach((folder: TAbstractFile) => {
if (
folder instanceof TFolder &&
folder.path.toLowerCase().contains(lowerCaseInputStr)
) {
folders.push(folder);
}
});

return folders;
}
renderSuggestion(value: TFolder, el: HTMLElement): void {
el.setText(value.path);
}
selectSuggestion(value: TFolder, evt: MouseEvent | KeyboardEvent): void {
this.setValue(value.path);
this.close();
}
}
210 changes: 0 additions & 210 deletions src/settings/suggester/suggest.ts

This file was deleted.

0 comments on commit 0b45fb6

Please sign in to comment.