From fb1a74a96d42a5f5cc7a58e2af0849bed12471c9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 17 Jun 2025 16:51:27 +0300 Subject: [PATCH] feat(text-snippets): debounce updates to avoid duplication --- apps/client/src/widgets/type_widgets/ckeditor/snippets.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts b/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts index a24aefaf8..72a769015 100644 --- a/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts +++ b/apps/client/src/widgets/type_widgets/ckeditor/snippets.ts @@ -1,9 +1,11 @@ +import debounce from "debounce"; import froca from "../../../services/froca.js"; import type LoadResults from "../../../services/load_results.js"; import search from "../../../services/search.js"; import type { TemplateDefinition } from "@triliumnext/ckeditor5"; let templateCache: Map = new Map(); +const debouncedHandleUpdate = debounce(handleUpdate, 1000); /** * Generates the list of snippets based on the user's notes to be passed down to the CKEditor configuration. @@ -48,7 +50,7 @@ async function handleUpdate(affectedNoteIds: string[]) { export function updateTemplateCache(loadResults: LoadResults): boolean { const affectedNoteIds = loadResults.getNoteIds(); if (affectedNoteIds.length > 0) { - handleUpdate(affectedNoteIds); + debouncedHandleUpdate(affectedNoteIds); }