Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-remove-textinputsuggest #78

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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