From 8b05da5a7660d8b68c921ea8f363294b64951d30 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 23 Oct 2024 12:29:12 +0200 Subject: [PATCH] Fix issue with default field value in field's 'when' clause #872 --- CHANGELOG.md | 1 + src/utils/fieldWhenClause.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdec7682..970a7081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### 🐞 Fixes +- [#872](https://github.com/estruyf/vscode-front-matter/issues/872): Check the default field value as well for the field's `when` clause - [#874](https://github.com/estruyf/vscode-front-matter/issues/874): Fix media snippet markup insertion to article content's - [#875](https://github.com/estruyf/vscode-front-matter/issues/875): Clean up the exclamation marks from the file name when creating new content diff --git a/src/utils/fieldWhenClause.ts b/src/utils/fieldWhenClause.ts index 807ab89a..096d8e85 100644 --- a/src/utils/fieldWhenClause.ts +++ b/src/utils/fieldWhenClause.ts @@ -22,7 +22,10 @@ export const fieldWhenClause = (field: Field, parent: IMetadata, allFields?: Fie } } - const whenValue = parent[when.fieldRef]; + let whenValue = parent[when.fieldRef]; + if (whenValue === undefined) { + whenValue = field.default as string | IMetadata | string[] | null; + } if (when.caseSensitive || typeof when.caseSensitive === 'undefined') { return caseSensitive(when, field, whenValue); } else { @@ -61,7 +64,7 @@ const caseInsensitive = ( */ const caseSensitive = ( when: WhenClause, - field: Field, + _: Field, whenValue: string | IMetadata | string[] | null ) => { switch (when.operator) {