diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b272288..61920621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### 🐞 Fixes - [#876](https://github.com/estruyf/vscode-front-matter/issues/876): Fix snippet type on the snippet card +- [#879](https://github.com/estruyf/vscode-front-matter/issues/879): Fix for auto updating last modified date on save ## [10.5.1] - 2024-10-23 diff --git a/src/commands/Article.ts b/src/commands/Article.ts index b0e35076..044ef7da 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -52,7 +52,7 @@ export class Article { * * @param subscriptions - The array of subscriptions to register the commands with. */ - public static async registerCommands(subscriptions: unknown[]) { + public static registerCommands(subscriptions: unknown[]) { subscriptions.push( commands.registerCommand(COMMAND_NAME.setLastModifiedDate, Article.setLastModifiedDate) ); @@ -66,6 +66,15 @@ export class Article { subscriptions.push(commands.registerCommand(COMMAND_NAME.insertSnippet, Article.insertSnippet)); } + /** + * Registers event listeners for the Article class. + * + * @param subscriptions - An array to which the event listener will be added. + */ + public static registerListeners(subscriptions: unknown[]) { + subscriptions.push(workspace.onWillSaveTextDocument(Article.autoUpdate)); + } + /** * Sets the article date */ @@ -369,15 +378,15 @@ export class Article { * Article auto updater * @param event */ - public static async autoUpdate(event: TextDocumentWillSaveEvent) { + public static autoUpdate(event: TextDocumentWillSaveEvent) { const document = event.document; if (document && ArticleHelper.isSupportedFile(document)) { const autoUpdate = Settings.get(SETTING_AUTO_UPDATE_DATE); // Is article located in one of the content folders - const folders = await Folders.getCachedOrFresh(); + const folders = Folders.getCached(); const documentPath = parseWinPath(document.fileName); - const folder = folders.find((f) => documentPath.startsWith(f.path)); + const folder = folders?.find((f) => documentPath.startsWith(f.path)); if (!folder) { return; } diff --git a/src/extension.ts b/src/extension.ts index 49c560bf..8c523e4e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,7 +14,7 @@ import ContentProvider from './providers/ContentProvider'; import { PagesListener } from './listeners/dashboard'; import { ModeSwitch } from './services/ModeSwitch'; import { PagesParser } from './services/PagesParser'; -import { ContentType, Telemetry, Extension } from './helpers'; +import { ContentType, Extension } from './helpers'; import * as l10n from '@vscode/l10n'; import { Backers, @@ -121,8 +121,9 @@ export async function activate(context: vscode.ExtensionContext) { // Register the taxonomy commands Taxonomy.registerCommands(subscriptions); - // Register all the article commands + // Register all the article commands and listeners Article.registerCommands(subscriptions); + Article.registerListeners(subscriptions); // Template creation Template.registerCommands(); @@ -181,9 +182,6 @@ export async function activate(context: vscode.ExtensionContext) { // Automatically run the command triggerPageUpdate(`main`); - // Listener for file edit changes - subscriptions.push(vscode.workspace.onWillSaveTextDocument(handleAutoDateUpdate)); - // Listener for file saves subscriptions.push(PagesListener.saveFileWatcher()); @@ -241,16 +239,13 @@ export async function activate(context: vscode.ExtensionContext) { // Subscribe all commands subscriptions.push(PanelView, collapseAll, fmStatusBarItem); + // eslint-disable-next-line no-console console.log(`π–₯π—‹π—ˆπ—‡π— 𝖬𝖺𝗍𝗍𝖾𝗋 𝖒𝖬𝖲 𝖺𝖼𝗍𝗂𝗏𝖺𝗍𝖾𝖽! 𝖱𝖾𝖺𝖽𝗒 π—π—ˆ π—Œπ—π–Ίπ—‹π— 𝗐𝗋𝗂𝗍𝗂𝗇𝗀... πŸ‘©β€πŸ’»πŸ§‘β€πŸ’»πŸ‘¨β€πŸ’»`); } // eslint-disable-next-line @typescript-eslint/no-empty-function export function deactivate() {} -const handleAutoDateUpdate = (e: vscode.TextDocumentWillSaveEvent) => { - Article.autoUpdate(e); -}; - const triggerPageUpdate = (location: string) => { Logger.verbose(`Trigger page update: ${location}`); pageUpdateDebouncer(() => {