From f6ca8e5c98c950a5bcb464285bd78872163f6601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Thu, 19 Sep 2024 13:37:55 +0200 Subject: [PATCH] Fix adding muliple previews in one place --- src/web/inputElements/inlineImage.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/web/inputElements/inlineImage.ts b/src/web/inputElements/inlineImage.ts index 8cc4828c..717c4c6e 100644 --- a/src/web/inputElements/inlineImage.ts +++ b/src/web/inputElements/inlineImage.ts @@ -21,7 +21,7 @@ type DebouncePreviewItem = { const timeoutMap = new Map(); function getImagePreviewElement(targetElement: HTMLMarkdownElement) { - return Array.from(targetElement?.childNodes || []).find((el) => (el as HTMLElement)?.contentEditable === 'false'); + return Array.from(targetElement?.childNodes || []).find((el) => (el as HTMLElement)?.contentEditable === 'false') as HTMLMarkdownElement | undefined; } function createImageElement(targetNode: TreeNode, url: string, callback: (img: HTMLElement, err?: string | Event) => void) { @@ -111,7 +111,10 @@ function addInlineImagePreview(currentInput: MarkdownTextInputElement, targetNod // Update the target element if input structure was updated while the image was loading and its content haven't changed if (!targetElement.isConnected) { const currentElement = currentInput.querySelector(`[data-type="block"][data-id="${targetNode.orderIndex}"]`) as HTMLMarkdownElement; - if (getImagePreviewElement(currentElement)?.textContent === getImagePreviewElement(targetNode.element)?.textContent) { + + const currentElementSpinner = getImagePreviewElement(currentElement); + const targetElementSpinner = getImagePreviewElement(targetNode.element); + if (currentElementSpinner && targetElementSpinner && currentElementSpinner.getAttribute('data-url') && targetElementSpinner.getAttribute('data-url')) { targetElement = currentElement; } else { return; // Cancel expired image preview if the content has changed befo