Skip to content

Commit

Permalink
Fix inline images flickering on backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Oct 10, 2024
1 parent dad2cfd commit 03811f0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/web/inputElements/inlineImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ type DebouncePreviewItem = {

const timeoutMap = new Map<string, DebouncePreviewItem>();

function createSeparatorElement() {
const separator = document.createElement('span');
separator.contentEditable = 'false';
separator.setAttribute('data-type', 'image-block-separator');
return separator;
}

function getImagePreviewElement(targetElement: HTMLMarkdownElement) {
return Array.from(targetElement?.childNodes || []).find((el) => (el as HTMLElement)?.contentEditable === 'false') as HTMLMarkdownElement | undefined;
}
Expand Down Expand Up @@ -159,6 +166,9 @@ function addInlineImagePreview(
}
}

// Add an empty span to fix issues connected with removing the image from the inner HTML when editing the input
targetNode.parentNode?.element.appendChild(createSeparatorElement());

const imageMarginTop = parseStringWithUnitToNumber(`${markdownStyle.inlineImage?.marginTop}`);
const imageMarginBottom = parseStringWithUnitToNumber(`${markdownStyle.inlineImage?.marginBottom}`);

Expand Down

0 comments on commit 03811f0

Please sign in to comment.