Skip to content

Commit

Permalink
Restore intended behavior of input suggest classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cwegrzyn committed Jul 13, 2024
1 parent 663b598 commit 9c1ab93
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 50 deletions.
5 changes: 1 addition & 4 deletions src/clocks/clock-create-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ export class ClockCreateModal extends Modal {
const folderSetting = new Setting(contentEl)
.setName("Target folder")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);

folderComponent = search
.setPlaceholder("Choose a folder")
Expand Down
5 changes: 1 addition & 4 deletions src/entity/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ export class EntityModal<T extends EntitySpec> extends Modal {
const targetFolderSetting = new Setting(contentEl)
.setName("Target folder")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);

search
.setPlaceholder("Choose a folder")
Expand Down
22 changes: 5 additions & 17 deletions src/settings/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import IronVaultPlugin from "index";
import { PluginSettingTab, Setting, type App } from "obsidian";
import { IronVaultPluginSettings } from "settings";
import { FolderTextSuggest } from "utils/ui/settings/folder";
import ironswornLogoBin from "../../media/ironvault_logo_ironsworn.png";
import delveLogoBin from "../../media/ironvault_logo_delve.png";
import ironswornLogoBin from "../../media/ironvault_logo_ironsworn.png";
import starforgedLogoBin from "../../media/ironvault_logo_starforged.png";
import sunderedIslesLogoBin from "../../media/ironvault_logo_sunderedisles.png";

Expand Down Expand Up @@ -160,10 +160,7 @@ export class IronVaultSettingTab extends PluginSettingTab {
.setName("Homebrew content folder")
.setDesc("Load custom rulesets from this folder.")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);

let isValidPath = true;

Expand Down Expand Up @@ -308,10 +305,7 @@ export class IronVaultSettingTab extends PluginSettingTab {
.setName("Default progress track folder")
.setDesc("Create progress tracks in this folder by default.")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);

search
.setPlaceholder("Type the name of a folder")
Expand Down Expand Up @@ -339,10 +333,7 @@ export class IronVaultSettingTab extends PluginSettingTab {
.setName("Default clock folder")
.setDesc("Create clocks in this folder by default.")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);

search
.setPlaceholder("Type the name of a folder")
Expand All @@ -366,10 +357,7 @@ export class IronVaultSettingTab extends PluginSettingTab {
.setName("Default characters folder")
.setDesc("Create player characters in this folder by default.")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);

search
.setPlaceholder("Type the name of a folder")
Expand Down
21 changes: 8 additions & 13 deletions src/tracks/progress-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ export class ProgressTrackCreateModal extends Modal {
const folderSetting = new Setting(contentEl)
.setName("Target folder")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);
folderComponent = search
.setPlaceholder("Choose a folder")
.setValue(this.result.targetFolder)
Expand Down Expand Up @@ -115,15 +112,13 @@ export class ProgressTrackCreateModal extends Modal {
"What kind of track is this? (e.g., Vow, Connection)",
);

new GenericTextSuggest(
this.app,
search.inputEl,
["Vow", "Connection", "Combat", "Scene Challenge", "Expedition"],
(val) => {
search.setValue(val);
search.onChanged();
},
);
new GenericTextSuggest(this.app, search.inputEl, [
"Vow",
"Connection",
"Combat",
"Scene Challenge",
"Expedition",
]);

search.onChange((value) => {
this.result.trackType = value;
Expand Down
5 changes: 1 addition & 4 deletions src/truths/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ class GenerateTruthsModal extends Modal {
const folderSetting = new Setting(contentEl)
.setName("Target folder")
.addSearch((search) => {
new FolderTextSuggest(this.app, search.inputEl, (val: string) => {
search.setValue(val);
search.onChanged();
});
new FolderTextSuggest(this.app, search.inputEl);
folderComponent = search
.setPlaceholder("Choose a folder")
.setValue(this.result.targetFolder)
Expand Down
11 changes: 6 additions & 5 deletions src/utils/ui/settings/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { AbstractInputSuggest, App, TFolder } from "obsidian";
export class FolderTextSuggest extends AbstractInputSuggest<TFolder> {
constructor(
app: App,
textInputEl: HTMLInputElement | HTMLDivElement,
private onSelectCallBack: (value: string) => void = () => {},
readonly textInputEl: HTMLInputElement | HTMLDivElement,
) {
super(app, textInputEl);
}

getSuggestions(inputStr: string): TFolder[] {
const searchStr = inputStr.toLowerCase();

Expand All @@ -24,9 +24,10 @@ export class FolderTextSuggest extends AbstractInputSuggest<TFolder> {
el.setText(folder.path);
}

selectSuggestion(item: TFolder): void {
this.setValue(item.path);
this.onSelectCallBack(item.path);
selectSuggestion(value: TFolder, _evt: MouseEvent | KeyboardEvent): void {
this.setValue(value.path);
if (this.textInputEl.instanceOf(HTMLInputElement))
this.textInputEl.trigger("input");
this.close();
}
}
6 changes: 3 additions & 3 deletions src/utils/ui/settings/generic-text-suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export class GenericTextSuggest extends AbstractInputSuggest<
> {
constructor(
app: App,
inputEl: HTMLInputElement,
readonly inputEl: HTMLInputElement,
public readonly items: string[],
private onSelectCallBack: (value: string) => void = () => {},
) {
super(app, inputEl);
}
Expand Down Expand Up @@ -54,7 +53,8 @@ export class GenericTextSuggest extends AbstractInputSuggest<

selectSuggestion({ item }: FuzzyMatch<string>): void {
this.setValue(item);
this.onSelectCallBack(item);
if (this.inputEl.instanceOf(HTMLInputElement))
this.inputEl.trigger("input");
this.close();
}
}

0 comments on commit 9c1ab93

Please sign in to comment.