Skip to content

Commit e458770

Browse files
authored
Merge pull request #3 from rca-umb/text
Text
2 parents 60ecbcb + 3291b06 commit e458770

File tree

5 files changed

+17
-33
lines changed

5 files changed

+17
-33
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.1.0] - 2025-1-25
8+
9+
### Removed
10+
11+
- Option to change the text content of notifications.
12+
713
## [1.0.1] - 2024-12-30
814

915
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ Show only the first heading: [[Title#Heading#Subheading#Subsubheading|Heading]]
3636
Show only the last heading: [[Title#Heading#Subheading#Subsubheading|Subsubheading]]
3737
```
3838

39-
By default, the headings in the display text will be separated by a single space, but this can be changed to whatever you prefer. Some examples may be a comma (, ), colon (: ), or arrow (-> ). Just not that whatever is typed in the separator text box in the settings will be exactly what is used in the display text, nothing is added to it or removed from it.
39+
By default, the headings in the display text will be separated by a single space, but this can be changed to whatever you prefer. Some examples may be a comma (, ), colon (: ), or arrow (-> ). Just note that whatever is typed in the separator text box in the settings will be exactly what is used in the display text, nothing is added to it or removed from it.

main.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ interface AnchorDisplayTextSettings {
44
includeNoteName : string;
55
whichHeadings: string;
66
includeNotice: boolean;
7-
noticeText: string;
87
sep : string;
98
}
109

1110
const DEFAULT_SETTINGS: AnchorDisplayTextSettings = {
1211
includeNoteName: 'headersOnly',
1312
whichHeadings: 'allHeaders',
1413
includeNotice: false,
15-
noticeText: 'Link changed!',
1614
sep: ' '
1715
}
1816

@@ -48,15 +46,16 @@ export default class AnchorDisplayText extends Plugin {
4846
}
4947
}
5048
const startIndex = (match.index ?? 0) + match[0].length - 2;
51-
if (this.settings.includeNoteName === 'headersOnly') {
52-
editor.replaceRange(`|${displayText}`, {line: cursor.line, ch: startIndex}, undefined, 'headerDisplayText');
53-
} else if (this.settings.includeNoteName === 'noteNameFirst') {
54-
editor.replaceRange(`|${headings[0]}${this.settings.sep}${displayText}`, {line: cursor.line, ch: startIndex}, undefined, 'headerDisplayText');
49+
// add note name to display text if wanted
50+
if (this.settings.includeNoteName === 'noteNameFirst') {
51+
displayText = `${headings[0]}${this.settings.sep}${displayText}`;
5552
} else if (this.settings.includeNoteName === 'noteNameLast') {
56-
editor.replaceRange(`|${displayText}${this.settings.sep}${headings[0]}`, {line: cursor.line, ch: startIndex}, undefined, 'headerDisplayText');
53+
displayText = `${displayText}${this.settings.sep}${headings[0]}`;
5754
}
55+
// change the display text of the link
56+
editor.replaceRange(`|${displayText}`, {line: cursor.line, ch: startIndex}, undefined, 'headerDisplayText');
5857
if (this.settings.includeNotice) {
59-
new Notice (this.settings.noticeText)
58+
new Notice (`Updated anchor link display text.`);
6059
}
6160
}
6261
})
@@ -79,24 +78,16 @@ export default class AnchorDisplayText extends Plugin {
7978

8079
class AnchorDisplayTextSettingTab extends PluginSettingTab {
8180
plugin: AnchorDisplayText;
82-
private notificationTextSetting?: Setting;
8381

8482
constructor(app: App, plugin: AnchorDisplayText) {
8583
super(app, plugin);
8684
this.plugin = plugin;
8785
}
8886

89-
displayNotificationTextSetting() {
90-
if (this.notificationTextSetting) {
91-
this.notificationTextSetting.settingEl.style.display = this.plugin.settings.includeNotice ? 'flex' : 'none';
92-
}
93-
}
94-
9587
display(): void {
9688
const {containerEl} = this;
9789
containerEl.empty();
9890

99-
new Setting(containerEl).setName('Display text format').setHeading();
10091
new Setting(containerEl)
10192
.setName('Include note name')
10293
.setDesc('Include the title of the note in the display text.')
@@ -134,28 +125,15 @@ class AnchorDisplayTextSettingTab extends PluginSettingTab {
134125
});
135126
});
136127

137-
new Setting(containerEl).setName('Notifications').setHeading();
138128
new Setting(containerEl)
139129
.setName('Enable notifications')
140-
.setDesc('Have a notice pop up whenever a link is automatically changed.')
130+
.setDesc('Have a notice pop up whenever an anchor link is automatically changed.')
141131
.addToggle(toggle => {
142132
toggle.setValue(this.plugin.settings.includeNotice);
143133
toggle.onChange(value => {
144134
this.plugin.settings.includeNotice = value;
145-
this.displayNotificationTextSetting();
146-
this.plugin.saveSettings();
147-
});
148-
});
149-
this.notificationTextSetting = new Setting(containerEl)
150-
.setName('Notification text')
151-
.setDesc('Set the text to appear in the notification.')
152-
.addText(text => {
153-
text.setValue(this.plugin.settings.noticeText);
154-
text.onChange(value => {
155-
this.plugin.settings.noticeText = value;
156135
this.plugin.saveSettings();
157136
});
158137
});
159-
this.displayNotificationTextSetting();
160138
}
161139
}

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "anchor-display-text",
33
"name": "Anchor Link Display Text",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"minAppVersion": "0.15.0",
66
"description": "Automatically uses the linked heading as the display text for the anchor links.",
77
"author": "Robert C Arsenault",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "anchor-display-text-plugin",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Plugin for Obsidian (https://obsidian.md) that sets the display text of anchor links to the name of the heading.",
55
"main": "main.js",
66
"scripts": {

0 commit comments

Comments
 (0)