Skip to content

Commit b13e562

Browse files
committed
Settings: display text format, include notice
1 parent fe856cd commit b13e562

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

main.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Set
33
// Remember to rename these classes and interfaces!
44

55
interface HeaderDisplayTextSettings {
6-
mySetting: string;
6+
displayTextFormat: string;
7+
includeNotice: boolean;
78
}
89

910
const DEFAULT_SETTINGS: HeaderDisplayTextSettings = {
10-
mySetting: 'default'
11+
displayTextFormat: 'headerOnly',
12+
includeNotice: false
1113
}
1214

1315
export default class HeaderDisplayText extends Plugin {
@@ -33,10 +35,15 @@ export default class HeaderDisplayText extends Plugin {
3335
if (match) {
3436
const noteName = match[1];
3537
const heading = match[2];
36-
console.log(noteName, heading);
3738
const startIndex = (match.index ?? 0) + match[0].length - 2;
38-
editor.replaceRange(`|${heading}`, {line: cursor.line, ch: startIndex}, undefined, 'headerAliases')
39-
new Notice ('Link changed!')
39+
if (this.settings.displayTextFormat === 'headerOnly') {
40+
editor.replaceRange(`|${heading}`, {line: cursor.line, ch: startIndex}, undefined, 'headerAliases')
41+
} else if (this.settings.displayTextFormat === 'withNoteName'){
42+
editor.replaceRange(`|${noteName} ${heading}`, {line: cursor.line, ch: startIndex}, undefined, 'headerAliases')
43+
}
44+
if (this.settings.includeNotice) {
45+
new Notice ('Link changed!')
46+
}
4047
}
4148
})
4249
);
@@ -66,18 +73,25 @@ class HeaderDisplayTextSettingTab extends PluginSettingTab {
6673

6774
display(): void {
6875
const {containerEl} = this;
69-
7076
containerEl.empty();
71-
7277
new Setting(containerEl)
7378
.setName('Display Text Format')
74-
.setDesc('Change the format of the display text.')
75-
.addText(text => text
76-
.setPlaceholder('Enter your secret')
77-
.setValue(this.plugin.settings.mySetting)
78-
.onChange(async (value) => {
79-
this.plugin.settings.mySetting = value;
80-
await this.plugin.saveSettings();
81-
}));
79+
.setDesc('Change the format of the auto populated display text.')
80+
.addDropdown(dropdown => {
81+
dropdown.addOption('headerOnly', 'Header Only');
82+
dropdown.addOption('withNoteName', 'Note Name and Header');
83+
dropdown.setValue('headerOnly');
84+
dropdown.onChange(value => {
85+
this.plugin.settings.displayTextFormat = value;
86+
this.plugin.saveSettings();
87+
});
88+
})
89+
.addToggle(toggle => {
90+
toggle.setValue(this.plugin.settings.includeNotice);
91+
toggle.onChange(value => {
92+
this.plugin.settings.includeNotice = value;
93+
this.plugin.saveSettings();
94+
});
95+
})
8296
}
8397
}

0 commit comments

Comments
 (0)