mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(text-snippets): better reaction to removing templates
This commit is contained in:
		
							parent
							
								
									3e40a35c19
								
							
						
					
					
						commit
						4f9bd970af
					
				@ -46,12 +46,11 @@ async function handleContentUpdate(affectedNoteIds: string[]) {
 | 
			
		||||
    const templateNoteIds = new Set(templateCache.keys());
 | 
			
		||||
    const affectedTemplateNoteIds = templateNoteIds.intersection(updatedNoteIds);
 | 
			
		||||
 | 
			
		||||
    console.log("Got ", affectedTemplateNoteIds);
 | 
			
		||||
 | 
			
		||||
    await froca.getNotes(affectedNoteIds);
 | 
			
		||||
 | 
			
		||||
    let fullReloadNeeded = false;
 | 
			
		||||
    for (const affectedTemplateNoteId of affectedTemplateNoteIds) {
 | 
			
		||||
        try {
 | 
			
		||||
            const template = await froca.getNote(affectedTemplateNoteId);
 | 
			
		||||
            if (!template) {
 | 
			
		||||
                console.warn("Unable to obtain template with ID ", affectedTemplateNoteId);
 | 
			
		||||
@ -68,6 +67,10 @@ async function handleContentUpdate(affectedNoteIds: string[]) {
 | 
			
		||||
                title: template.title,
 | 
			
		||||
                content: await template.getContent()
 | 
			
		||||
            });
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            // If a note was not found while updating the cache, it means we need to do a full reload.
 | 
			
		||||
            fullReloadNeeded = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (fullReloadNeeded) {
 | 
			
		||||
@ -77,14 +80,15 @@ async function handleContentUpdate(affectedNoteIds: string[]) {
 | 
			
		||||
 | 
			
		||||
export function updateTemplateCache(loadResults: LoadResults): boolean {
 | 
			
		||||
    const affectedNoteIds = loadResults.getNoteIds();
 | 
			
		||||
    if (affectedNoteIds.length > 0) {
 | 
			
		||||
        debouncedHandleContentUpdate(affectedNoteIds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // React to creation or deletion of text snippets.
 | 
			
		||||
    if (loadResults.getAttributeRows().find((attr) =>
 | 
			
		||||
            attr.type === "label" &&
 | 
			
		||||
            attr.name === "textSnippet")) {
 | 
			
		||||
        handleFullReload();
 | 
			
		||||
    } else if (affectedNoteIds.length > 0) {
 | 
			
		||||
        // Update content and titles if one of the template notes were updated.
 | 
			
		||||
        debouncedHandleContentUpdate(affectedNoteIds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user