Skip to content

Commit 8b05da5

Browse files
committed
Fix issue with default field value in field's 'when' clause #872
1 parent 0062117 commit 8b05da5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
### 🐞 Fixes
1414

15+
- [#872](https://github.com/estruyf/vscode-front-matter/issues/872): Check the default field value as well for the field's `when` clause
1516
- [#874](https://github.com/estruyf/vscode-front-matter/issues/874): Fix media snippet markup insertion to article content's
1617
- [#875](https://github.com/estruyf/vscode-front-matter/issues/875): Clean up the exclamation marks from the file name when creating new content
1718

src/utils/fieldWhenClause.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export const fieldWhenClause = (field: Field, parent: IMetadata, allFields?: Fie
2222
}
2323
}
2424

25-
const whenValue = parent[when.fieldRef];
25+
let whenValue = parent[when.fieldRef];
26+
if (whenValue === undefined) {
27+
whenValue = field.default as string | IMetadata | string[] | null;
28+
}
2629
if (when.caseSensitive || typeof when.caseSensitive === 'undefined') {
2730
return caseSensitive(when, field, whenValue);
2831
} else {
@@ -61,7 +64,7 @@ const caseInsensitive = (
6164
*/
6265
const caseSensitive = (
6366
when: WhenClause,
64-
field: Field,
67+
_: Field,
6568
whenValue: string | IMetadata | string[] | null
6669
) => {
6770
switch (when.operator) {

0 commit comments

Comments
 (0)