mirror of
https://github.com/tbergeron/obsidian-human-readable-dates.git
synced 2026-07-22 06:56:05 +00:00
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.
This commit is contained in:
parent
f77c7f420a
commit
dd72df4f68
1 changed files with 5 additions and 8 deletions
13
main.ts
13
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('')
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue