( choices: IChoice[], templateFilePaths: string[], )
| 70 | * Multis), then raw template files not already covered by a choice. |
| 71 | */ |
| 72 | export function buildTemplatePickerItems( |
| 73 | choices: IChoice[], |
| 74 | templateFilePaths: string[], |
| 75 | ): TemplatePickerItem[] { |
| 76 | const templateChoices = flattenChoices(choices).filter( |
| 77 | (choice): choice is ITemplateChoice => |
| 78 | choice.type === "Template" && |
| 79 | Boolean((choice as ITemplateChoice).templatePath) && |
| 80 | isMarkdownTemplatePath((choice as ITemplateChoice).templatePath), |
| 81 | ); |
| 82 | |
| 83 | const coveredPaths = new Set( |
| 84 | templateChoices.map((choice) => |
| 85 | normalizeTemplatePathForComparison(choice.templatePath), |
| 86 | ), |
| 87 | ); |
| 88 | |
| 89 | const items: TemplatePickerItem[] = templateChoices.map((choice) => ({ |
| 90 | kind: "choice", |
| 91 | choice, |
| 92 | })); |
| 93 | |
| 94 | for (const path of templateFilePaths) { |
| 95 | if (!isMarkdownTemplatePath(path)) continue; |
| 96 | if (coveredPaths.has(normalizeTemplatePathForComparison(path))) continue; |
| 97 | items.push({ kind: "file", path }); |
| 98 | } |
| 99 | |
| 100 | return items; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Applies a template to an existing note (issue #526). |
no test coverage detected