Skip to content

Commit

Permalink
Merge pull request #78 from danielo515/fix-remove-textinputsuggest
Browse files Browse the repository at this point in the history
Fix-remove-textinputsuggest
  • Loading branch information
danielo515 authored Oct 19, 2023
2 parents f94aca7 + 16cc4af commit cb94f08
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 317 deletions.
14 changes: 2 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@popperjs/core": "^2.11.8",
"fuse.js": "^6.6.2"
}
}
217 changes: 0 additions & 217 deletions src/suggesters/suggest.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/suggesters/suggestArray.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { App } from "obsidian";
import { TextInputSuggest } from "./suggest";
import { AbstractInputSuggest, App } from "obsidian";

export class ArraySuggest extends TextInputSuggest<string> {
export class ArraySuggest extends AbstractInputSuggest<string> {
content: Set<string>;

constructor(app: App, input: HTMLInputElement, content: Set<string>) {
super(app, input);
constructor(app: App, private inputEl: HTMLInputElement, content: Set<string>) {
super(app, inputEl);
this.content = content;
}

Expand Down
9 changes: 3 additions & 6 deletions src/suggesters/suggestFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes

import { App, TAbstractFile, TFile } from "obsidian";
import { TextInputSuggest } from "./suggest";
import { AbstractInputSuggest, App, TAbstractFile, TFile } from "obsidian";
import { get_tfiles_from_folder } from "../utils/files";
import { tryCatch } from "../utils/Error";

Expand All @@ -13,9 +10,9 @@ export interface FileStrategy {
selectSuggestion(file: TFile): string;
}

export class FileSuggest extends TextInputSuggest<TFile> {
export class FileSuggest extends AbstractInputSuggest<TFile> {
constructor(
protected app: App,
public app: App,
public inputEl: HTMLInputElement,
private strategy: FileStrategy,
private folder: string,
Expand Down
62 changes: 30 additions & 32 deletions src/suggesters/suggestFolder.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes
import { App, TAbstractFile, TFolder } from "obsidian";
import { TextInputSuggest } from "./suggest";
import { AbstractInputSuggest, App, TAbstractFile, TFolder } from "obsidian";

export class FolderSuggest extends TextInputSuggest<TFolder> {
export class FolderSuggest extends AbstractInputSuggest<TFolder> {

constructor(
public inputEl: HTMLInputElement,
protected app: App,
) {
super(app, inputEl);
console.log('FolderSuggest constructor');
}
getSuggestions(inputStr: string): TFolder[] {
const abstractFiles = this.app.vault.getAllLoadedFiles();
const lowerCaseInputStr = inputStr.toLowerCase();
constructor(
public inputEl: HTMLInputElement,
public app: App,
) {
super(app, inputEl);
}
getSuggestions(inputStr: string): TFolder[] {
const abstractFiles = this.app.vault.getAllLoadedFiles();
const lowerCaseInputStr = inputStr.toLowerCase();

const folders: TFolder[] = abstractFiles.reduce((acc, folder: TAbstractFile) => {
if (
folder instanceof TFolder &&
folder.path.toLowerCase().contains(lowerCaseInputStr)
) {
acc.push(folder)
}
return acc
}, [] as TFolder[]);
const folders: TFolder[] = abstractFiles.reduce((acc, folder: TAbstractFile) => {
if (
folder instanceof TFolder &&
folder.path.toLowerCase().contains(lowerCaseInputStr)
) {
acc.push(folder)
}
return acc
}, [] as TFolder[]);

return folders;
}
return folders;
}

renderSuggestion(file: TFolder, el: HTMLElement): void {
el.setText(file.path);
}
renderSuggestion(file: TFolder, el: HTMLElement): void {
el.setText(file.path);
}

selectSuggestion(file: TFolder): void {
this.inputEl.value = file.path;
this.inputEl.trigger("input");
this.close();
}
selectSuggestion(file: TFolder): void {
this.inputEl.value = file.path;
this.inputEl.trigger("input");
this.close();
}
}
Loading

0 comments on commit cb94f08

Please sign in to comment.