From dd72df4f686f56fa4b6e141a2a5e376be285d60b Mon Sep 17 00:00:00 2001 From: Tommy Bergeron Date: Mon, 15 Jun 2026 13:24:13 -0400 Subject: [PATCH] Refactor date format handling in HumanReadableDates plugin - Changed `requestAnimationFrame` to use `window.requestAnimationFrame` for clarity. - Updated variable usage in `createLivePreviewExtension` to directly reference `this.settings`. - Improved description for date format settings to clarify usage of square brackets for literal text. - Enhanced warning message for unrecognized date tokens to specify valid token types. --- main.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main.ts b/main.ts index 31ac2ac..e606bb6 100644 --- a/main.ts +++ b/main.ts @@ -341,7 +341,7 @@ export default class HumanReadableDates extends Plugin { } refreshDecorations() { - requestAnimationFrame(() => { + window.requestAnimationFrame(() => { this.app.workspace.getLeavesOfType('markdown').forEach((leaf) => { const view = leaf.view as { editor?: { cm?: EditorView } } | null if (view?.editor?.cm) { @@ -355,8 +355,7 @@ export default class HumanReadableDates extends Plugin { } createLivePreviewExtension() { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const plugin = this + const settings = this.settings const app = this.app return ViewPlugin.fromClass( @@ -379,7 +378,7 @@ export default class HumanReadableDates extends Plugin { const text = doc.toString(); const selection = view.state.selection.main; - const format = plugin.settings.dateFormat + const format = settings.dateFormat const dateRegex = createDateRegex(format); const bracketedDateRegex = createBracketedDateRegex(format); @@ -490,8 +489,7 @@ class HumanReadableDatesSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Date format') - // eslint-disable-next-line obsidianmd/ui/sentence-case - .setDesc('Moment-style format tokens supported. Examples: YYYY-MM-DD, ddd MMM DD YYYY HH:mm, M/D/YYYY. Use [literal text] for brackets in the output.') + .setDesc('Moment-style format tokens are supported. Use square brackets around literal text for brackets in the output.') .addText(text => text .setValue(this.plugin.settings.dateFormat) .onChange(async (value) => { @@ -521,8 +519,7 @@ class HumanReadableDatesSettingTab extends PluginSettingTab { } const compiled = compileDateFormat(format) if (!compiled) { - // eslint-disable-next-line obsidianmd/ui/sentence-case - this.formatWarningEl.setText('No recognized date tokens found. Use YYYY, MM, MMM, DD, ddd, HH, mm.') + this.formatWarningEl.setText('No recognized date tokens found. Use year, month, day, weekday, hour, or minute tokens.') } else { this.formatWarningEl.setText('') }