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) {