diff --git a/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts b/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts index 9072194a5..a24aefaf8 100644 --- a/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts +++ b/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts @@ -3,7 +3,7 @@ import type LoadResults from "../../../services/load_results.js"; import search from "../../../services/search.js"; import type { TemplateDefinition } from "@triliumnext/ckeditor5"; -let templateCache: Record = {}; +let templateCache: Map = new Map(); /** * Generates the list of snippets based on the user's notes to be passed down to the CKEditor configuration. @@ -15,11 +15,11 @@ export default async function getTemplates() { const snippets = await search.searchForNotes("#textSnippet"); const definitions: TemplateDefinition[] = []; for (const snippet of snippets) { - templateCache[snippet.noteId] = await (snippet.getContent()) ?? ""; + templateCache.set(snippet.noteId, await snippet.getContent()); definitions.push({ title: snippet.title, - data: () => templateCache[snippet.noteId] + data: () => templateCache.get(snippet.noteId) ?? "" }) } return definitions; @@ -27,7 +27,7 @@ export default async function getTemplates() { async function handleUpdate(affectedNoteIds: string[]) { const updatedNoteIds = new Set(affectedNoteIds); - const templateNoteIds = new Set(Object.keys(templateCache)); + const templateNoteIds = new Set(templateCache.keys()); const affectedTemplateNoteIds = templateNoteIds.intersection(updatedNoteIds); console.log("Got ", affectedTemplateNoteIds); @@ -41,7 +41,7 @@ async function handleUpdate(affectedNoteIds: string[]) { continue; } - templateCache[affectedTemplateNoteId] = await template.getContent() ?? ""; + templateCache.set(affectedTemplateNoteId, await template.getContent()); } }