Fix issue with default field value in field's 'when' clause #872

This commit is contained in:
Elio Struyf
2024-10-23 12:29:12 +02:00
parent 0062117c3b
commit 8b05da5a76
2 changed files with 6 additions and 2 deletions
+1
View File
@@ -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
+5 -2
View File
@@ -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) {