Skip to content

Commit

Permalink
Improve option descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
decaplanet committed Dec 29, 2023
1 parent 3341322 commit 3be4f55
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 32 deletions.
20 changes: 11 additions & 9 deletions src/settings/settingTab.ts
Expand Up @@ -110,7 +110,7 @@ export class MainPluginSettingTab extends PluginSettingTab {
});
new Setting(containerEl)
.setName("After properties")
.setDesc("Decides the gap right after the property section.")
.setDesc("Decides the gap after the property section.")
.addText((text) =>
text
.setPlaceholder("2")
Expand Down Expand Up @@ -140,7 +140,9 @@ export class MainPluginSettingTab extends PluginSettingTab {
);
new Setting(containerEl)
.setName("Before contents after code blocks")
.setDesc("Decides gaps before contents that are after code blocks.")
.setDesc(
"Decides gaps before 'contents that are after code blocks'."
)
.addText((text) =>
text
.setPlaceholder("1")
Expand Down Expand Up @@ -173,7 +175,7 @@ export class MainPluginSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName("Before code blocks after headings")
.setDesc(
"Decides gaps before code blocks that are right after headings."
"Decides gaps before 'code blocks that are after headings'."
)
.addText((text) =>
text
Expand All @@ -193,35 +195,35 @@ export class MainPluginSettingTab extends PluginSettingTab {

// Format Settings
containerEl.createEl("h2", {
text: "Format settings",
text: "Format options",
});
new Setting(containerEl)
.setName("Newline at the end of a document")
.setDesc("Inserts a newline at the end of a document.")
.addToggle((text) =>
text
.setValue(this.plugin.settings.formatSettings.insertNewline)
.setValue(this.plugin.settings.formatOptions.insertNewline)
.onChange(async (value) => {
this.plugin.settings.formatSettings.insertNewline =
this.plugin.settings.formatOptions.insertNewline =
value;
await this.plugin.saveSettings();
})
);

// Other Settings
containerEl.createEl("h2", {
text: "Other settings",
text: "Other options",
});
new Setting(containerEl)
.setName("Notify when no change is needed")
.setDesc("Displays a different message when no change was made.")
.addToggle((text) =>
text
.setValue(
this.plugin.settings.otherSettings.notifyWhenUnchanged
this.plugin.settings.otherOptions.notifyWhenUnchanged
)
.onChange(async (value) => {
this.plugin.settings.otherSettings.notifyWhenUnchanged =
this.plugin.settings.otherOptions.notifyWhenUnchanged =
value;
await this.plugin.saveSettings();
})
Expand Down
28 changes: 14 additions & 14 deletions src/settings/settingTypes.ts
@@ -1,40 +1,40 @@
export interface HeadingGaps {
/** Decides gaps before highest level of headings. */
/** Decides gaps before top level of headings. */
beforeTopLevelHeadings: string;
/** Decides the child heading gap right before a parent heading. */
beforeFirstSubHeading: string;
/** Decides gaps before headings that are not in the highest level. */
/** Decides gaps before headings that are not in the top level. */
beforeSubHeadings: string;
}

export interface OtherGaps {
/** Decides the gap after a YAML properties. */
/** Decides the gap after the property section. */
afterProperties: string;
/** Decides gaps before contents (ex: Text section right before headings). */
/** Decides gaps before contents (ex: Text section before headings). */
beforeContents: string;
/** Decides gaps before contents that are right after code blocks. */
/** Decides gaps before 'contents that are after code blocks'. */
beforeContentsAfterCodeBlocks: string;
/** Decides gaps before code blocks. */
beforeCodeBlocks: string;
/** Decides gaps before code blocks that are right after headings. */
/** DDecides gaps before 'code blocks that are after headings'. */
beforeCodeBlocksAfterHeadings: string;
}

export interface FormatSettings {
export interface FormatOptions {
/** Inserts a newline at the end of a document. */
insertNewline: boolean;
}

export interface OtherSettings {
export interface OtherOptions {
/** Displays a different message when no change was made. */
notifyWhenUnchanged: boolean;
}

export interface FormattoPluginSettings {
headingGaps: Partial<HeadingGaps>;
otherGaps: Partial<OtherGaps>;
formatSettings: Partial<FormatSettings>;
otherSettings: Partial<OtherSettings>;
formatOptions: Partial<FormatOptions>;
otherOptions: Partial<OtherOptions>;
}

// `Partial<Type>` is a TypeScript utility that returns a type with all properties of Type set to optional.
Expand All @@ -55,17 +55,17 @@ export const DEFAULT_OTHER_GAPS: Partial<OtherGaps> = {
beforeCodeBlocksAfterHeadings: "0",
};

export const DEFAULT_FORMAT_SETTINGS: Partial<FormatSettings> = {
export const DEFAULT_FORMAT_SETTINGS: Partial<FormatOptions> = {
insertNewline: true,
};

export const DEFAULT_OTHER_SETTINGS: Partial<OtherSettings> = {
export const DEFAULT_OTHER_SETTINGS: Partial<OtherOptions> = {
notifyWhenUnchanged: true,
};

export const DEFAULT_SETTINGS: FormattoPluginSettings = {
headingGaps: DEFAULT_HEADING_GAPS,
otherGaps: DEFAULT_OTHER_GAPS,
formatSettings: DEFAULT_FORMAT_SETTINGS,
otherSettings: DEFAULT_OTHER_SETTINGS,
formatOptions: DEFAULT_FORMAT_SETTINGS,
otherOptions: DEFAULT_OTHER_SETTINGS,
};
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -30,7 +30,7 @@ export class FormattoUtil {
editor.setSelection(cursorPosition, cursorPosition);

if (
this.plugin.settings.otherSettings.notifyWhenUnchanged &&
this.plugin.settings.otherOptions.notifyWhenUnchanged &&
originalDocument === editor.getValue()
) {
new Notice("Document is already formatted!");
Expand Down
10 changes: 6 additions & 4 deletions wasm/src/setting_schema.rs
Expand Up @@ -28,13 +28,15 @@ pub struct OtherGaps {

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FormatSettings {
pub struct FormatOptions {
/// Inserts a newline at the end of a document.
pub insert_newline: Option<bool>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OtherSettings {
pub struct OtherOptions {
/// Displays a different message when no change was made.
pub notify_when_unchanged: Option<bool>,
}

Expand All @@ -43,6 +45,6 @@ pub struct OtherSettings {
pub struct MainPluginSettings {
pub heading_gaps: HeadingGaps,
pub other_gaps: OtherGaps,
pub format_settings: FormatSettings,
pub other_settings: OtherSettings,
pub format_options: FormatOptions,
pub other_options: OtherOptions,
}
6 changes: 3 additions & 3 deletions wasm/src/testing.rs
Expand Up @@ -3,7 +3,7 @@ mod formatting {
mod get_formatted_string {
use crate::{
setting_schema::{
FormatSettings, HeadingGaps, MainPluginSettings, OtherGaps, OtherSettings,
FormatOptions, HeadingGaps, MainPluginSettings, OtherGaps, OtherOptions,
},
tools::{formatting::get_formatted_string, parsing::get_sections},
};
Expand All @@ -22,10 +22,10 @@ mod formatting {
before_code_blocks: Some("1".to_string()),
before_code_blocks_after_headings: Some("0".to_string()),
},
format_settings: FormatSettings {
format_options: FormatOptions {
insert_newline: Some(false),
},
other_settings: OtherSettings {
other_options: OtherOptions {
notify_when_unchanged: Some(false),
},
}
Expand Down
2 changes: 1 addition & 1 deletion wasm/src/tools/formatting.rs
Expand Up @@ -120,7 +120,7 @@ pub fn get_formatted_string(
}
}

if settings.format_settings.insert_newline == Some(true) {
if settings.format_options.insert_newline == Some(true) {
output.push('\n');
}

Expand Down

0 comments on commit 3be4f55

Please sign in to comment.