Skip to content

Commit

Permalink
Delete redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
decaplanet committed Dec 29, 2023
1 parent c7064b1 commit 173ac50
Showing 1 changed file with 27 additions and 119 deletions.
146 changes: 27 additions & 119 deletions src/settings/settingTab.ts
Expand Up @@ -5,10 +5,10 @@ import type FormattoPlugin from "../main";

export class MainPluginSettingTab extends PluginSettingTab {
private plugin: FormattoPlugin;

private invalidNumberMessage =
"Please enter a valid number.\nIt should be at least 0.";

private notRoundNumberMessage =
private notRoundNumberMessage =
"Please enter a valid number.\nIt should be a round number.";

constructor(app: App, plugin: FormattoPlugin) {
Expand All @@ -18,21 +18,20 @@ export class MainPluginSettingTab extends PluginSettingTab {

display(): void {
const { containerEl } = this;

containerEl.empty();

const debounceMsg = debounce(
(text: string, value: string) => {
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
new Notice(text);
new Notice(this.invalidNumberMessage);
return;
}
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
new Notice(text);
if (value !== "" && parseInt(value) % 1 === 0) {
new Notice(this.notRoundNumberMessage);
return;
}
},
1000,
Expand All @@ -53,19 +52,8 @@ export class MainPluginSettingTab extends PluginSettingTab {
this.plugin.settings.headingGaps.beforeTopLevelHeadings
)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.headingGaps.beforeTopLevelHeadings =
value;
await this.plugin.saveSettings();
Expand All @@ -83,19 +71,8 @@ export class MainPluginSettingTab extends PluginSettingTab {
this.plugin.settings.headingGaps.beforeFirstSubHeading
)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.headingGaps.beforeFirstSubHeading =
value;
await this.plugin.saveSettings();
Expand All @@ -113,19 +90,8 @@ export class MainPluginSettingTab extends PluginSettingTab {
this.plugin.settings.headingGaps.beforeSubHeadings
)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.headingGaps.beforeSubHeadings =
value;
await this.plugin.saveSettings();
Expand All @@ -144,21 +110,9 @@ export class MainPluginSettingTab extends PluginSettingTab {
.setPlaceholder("2")
.setValue(this.plugin.settings.otherGaps.afterProperties)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

this.plugin.settings.otherGaps.afterProperties =
value;
debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.otherGaps.afterProperties = value;
await this.plugin.saveSettings();
})
);
Expand All @@ -172,21 +126,9 @@ export class MainPluginSettingTab extends PluginSettingTab {
.setPlaceholder("0")
.setValue(this.plugin.settings.otherGaps.beforeContents)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

this.plugin.settings.otherGaps.beforeContents =
value;
debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.otherGaps.beforeContents = value;
await this.plugin.saveSettings();
})
);
Expand All @@ -201,19 +143,8 @@ export class MainPluginSettingTab extends PluginSettingTab {
.beforeContentsAfterCodeBlocks
)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.otherGaps.beforeContentsAfterCodeBlocks =
value;
await this.plugin.saveSettings();
Expand All @@ -227,21 +158,9 @@ export class MainPluginSettingTab extends PluginSettingTab {
.setPlaceholder("1")
.setValue(this.plugin.settings.otherGaps.beforeCodeBlocks)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

this.plugin.settings.otherGaps.beforeCodeBlocks =
value;
debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.otherGaps.beforeCodeBlocks = value;
await this.plugin.saveSettings();
})
);
Expand All @@ -258,19 +177,8 @@ export class MainPluginSettingTab extends PluginSettingTab {
.beforeCodeBlocksAfterHeadings
)
.onChange(async (value) => {
if (
value !== "" &&
parseInt(value) % 1 === 0
) {
debounceMsg(this.notRoundNumberMessage, value);
}
if (
value !== "" &&
(isNaN(parseInt(value)) || parseInt(value) < 0)
) {
debounceMsg(this.invalidNumberMessage, value);
}

debounceMsg(this.invalidNumberMessage, value);

this.plugin.settings.otherGaps.beforeCodeBlocksAfterHeadings =
value;
await this.plugin.saveSettings();
Expand Down

0 comments on commit 173ac50

Please sign in to comment.