From d3635165c6f8a3790a9595385c55d7330459227f Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 1 Mar 2023 18:19:57 +0200 Subject: [PATCH] deletion fix --- .../src/ImageService/AltComponent.js | 2 +- .../src/ImageService/plugins/captionPlugin.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/wax-prosemirror-services/src/ImageService/AltComponent.js b/wax-prosemirror-services/src/ImageService/AltComponent.js index 35ab8914b..5662125c4 100644 --- a/wax-prosemirror-services/src/ImageService/AltComponent.js +++ b/wax-prosemirror-services/src/ImageService/AltComponent.js @@ -45,7 +45,7 @@ export default ({ setPosition, position }) => { const imageId = selection.node.attrs.id; const image = document.querySelector(`[data-id='${imageId}']`); const figCaption = document.getElementsByTagName('figcaption')[0]; - if (!image) return; + if (!image || !figCaption) return; const imagePosition = image.getBoundingClientRect(); const figCaptionPosition = figCaption.getBoundingClientRect().height - 5; const left = imagePosition.left - WaxSurface.left; diff --git a/wax-prosemirror-services/src/ImageService/plugins/captionPlugin.js b/wax-prosemirror-services/src/ImageService/plugins/captionPlugin.js index 5263fa679..5df7f5cfc 100644 --- a/wax-prosemirror-services/src/ImageService/plugins/captionPlugin.js +++ b/wax-prosemirror-services/src/ImageService/plugins/captionPlugin.js @@ -112,16 +112,14 @@ const captionPlugin = key => } // delete caption if figure is deleted if (e.key === 'Delete' || e.code === 'Backspace') { - const figcap = document.getElementsByTagName('figcaption'); - const figcapLength = figcap.length; + const figCap = view.state.selection.$head.path; + if (figCap[6] && figCap[6].type.name === 'figcaption') { + const figCapEl = document.getElementById(figCap[6].attrs.id); - if (figcapLength) { - for (let i = 0; i < figcapLength; i += 1) { - if ( - figcap[i].parentElement.firstChild.tagName === 'FIGCAPTION' - ) { - figcap[i].parentElement.remove(); - } + if ( + figCapEl.parentElement.firstChild.tagName === 'figCapElTION' + ) { + figCapEl.parentElement.remove(); } } } -- GitLab