From b48557d22c662b78c886161fc5b6be9a9508fd69 Mon Sep 17 00:00:00 2001 From: Ping Zou Date: Mon, 21 Apr 2025 22:30:55 +0100 Subject: [PATCH 1/2] support adding prefix phrase to the autosuggest --- README.md | 1 + src/settings.ts | 17 +++++++++++++++++ src/suggest/date-suggest.ts | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 541fc69..fdb5aaa 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Typing `@today` Enter will automatically be expanded to the current d | Setting | Description | Default | | --------------- | ------------------------------------------------------- | ------- | | Enable/Disable | A global toggle to enable or disable the autosuggest | Enabled | +| Prefix phrase | Characters(s) added to the beginning of a date suggestion | `time:` or `#` | | Trigger phrase | Character(s) required to open the autosuggest | `@` | | Insert as link? | Dates will be inserted as wikilinks (i.e. `[[]]`) | Yes | diff --git a/src/settings.ts b/src/settings.ts index a7696aa..80cabd8 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -15,6 +15,7 @@ export type DayOfWeek = export interface NLDSettings { autosuggestToggleLink: boolean; autocompleteTriggerPhrase: string; + autocompletePrefixPhrase: string; isAutosuggestEnabled: boolean; format: string; @@ -30,6 +31,7 @@ export interface NLDSettings { export const DEFAULT_SETTINGS: NLDSettings = { autosuggestToggleLink: true, autocompleteTriggerPhrase: "@", + autocompletePrefixPhrase: "", isAutosuggestEnabled: true, format: "YYYY-MM-DD", @@ -165,6 +167,21 @@ export class NLDSettingsTab extends PluginSettingTab { }) ); + new Setting(containerEl) + .setName("Prefix") + .setDesc( + "Characters(s) that will be added before the date, which can be used for formatting" + ) + .addMomentFormat((text) => + text + .setPlaceholder(DEFAULT_SETTINGS.autocompletePrefixPhrase) + .setValue(this.plugin.settings.autocompletePrefixPhrase || "") + .onChange(async (value) => { + this.plugin.settings.autocompletePrefixPhrase = value.trim(); + await this.plugin.saveSettings(); + }) + ); + new Setting(containerEl) .setName("Trigger phrase") .setDesc("Character(s) that will cause the date autosuggest to open") diff --git a/src/suggest/date-suggest.ts b/src/suggest/date-suggest.ts index 615108c..a05f080 100644 --- a/src/suggest/date-suggest.ts +++ b/src/suggest/date-suggest.ts @@ -100,6 +100,7 @@ export default class DateSuggest extends EditorSuggest { const includeAlias = event.shiftKey; let dateStr = ""; let makeIntoLink = this.plugin.settings.autosuggestToggleLink; + let datePrefix = this.plugin.settings.autocompletePrefixPhrase; if (suggestion.label.startsWith("time:")) { const timePart = suggestion.label.substring(5); @@ -109,6 +110,10 @@ export default class DateSuggest extends EditorSuggest { dateStr = this.plugin.parseDate(suggestion.label).formattedString; } + if (datePrefix) { + dateStr = datePrefix + " " + dateStr; + } + if (makeIntoLink) { dateStr = generateMarkdownLink( this.app, From 50dbca6acf1e899b121ebda950cd8afe8fa3d973 Mon Sep 17 00:00:00 2001 From: Ping Zou Date: Mon, 21 Apr 2025 23:25:10 +0100 Subject: [PATCH 2/2] update manifest info to distinguish from the original plugin --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index ef47c07..401198b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "nldates-obsidian", - "name": "Natural Language Dates", + "name": "Natural Language Dates [PZ]", "description": "Create date-links based on natural language", - "version": "0.6.2", + "version": "0.6.3.beta", "author": "Argentina Ortega Sainz", "authorUrl": "https://argentinaos.com/", "isDesktopOnly": false,