Skip to content

Commit 044c1bd

Browse files
authored
Merge pull request lukeleppan#121 from NullCub3/fix-null-setting-values
Prevent Null Setting Values
2 parents c93e045 + 1acd2e1 commit 044c1bd

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/settings/SettingsTab.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,37 @@ export default class BetterWordCountSettingsTab extends PluginSettingTab {
5353
.setDesc("Set how many words count as one \"page\"")
5454
.addText((text: TextComponent) => {
5555
text.inputEl.type = "number";
56-
text.setPlaceholder("300");
57-
text.setValue(this.plugin.settings.pageWords.toString());
58-
text.onChange(async (value: string) => {
59-
this.plugin.settings.pageWords = parseInt(value);
60-
await this.plugin.saveSettings();
56+
text
57+
.setPlaceholder("300")
58+
.setValue(String(this.plugin.settings.pageWords))
59+
.onChange(async (value: string) => {
60+
if (value) {
61+
this.plugin.settings.pageWords = parseInt(value);
62+
} else {
63+
this.plugin.settings.pageWords = 300;
64+
}
65+
await this.plugin.saveSettings();
66+
});
6167
});
62-
});
6368

6469
// Advanced Settings
6570
containerEl.createEl("h4", { text: "Advanced Settings" });
6671
new Setting(containerEl)
6772
.setName("Vault Stats File Path")
6873
.setDesc("Reload required for change to take effect. The location of the vault statistics file, relative to the vault root.")
6974
.addText((text: TextComponent) => {
70-
text.setPlaceholder(".obsidian/vault-stats.json");
71-
text.setValue(this.plugin.settings.statsPath.toString());
72-
text.onChange(async (value: string) => {
73-
this.plugin.settings.statsPath = value;
74-
await this.plugin.saveSettings();
75+
text
76+
.setPlaceholder(".obsidian/vault-stats.json")
77+
.setValue(this.plugin.settings.statsPath)
78+
.onChange(async (value: string) => {
79+
if (value) {
80+
this.plugin.settings.statsPath = value;
81+
} else {
82+
this.plugin.settings.statsPath = ".obsidian/vault-stats.json";
83+
}
84+
await this.plugin.saveSettings();
85+
});
7586
});
76-
});
77-
7887

7988
// Status Bar Settings
8089
addStatusBarSettings(this.plugin, containerEl);

0 commit comments

Comments
 (0)