diff --git a/wax-prosemirror-services/src/ImageService/AltComponent.js b/wax-prosemirror-services/src/ImageService/AltComponent.js index 35ab8914bb525affb89d9baa3d84f2a110d5faa2..5662125c473320b8ba94466e3b91197c370b3835 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 5263fa679958be86881e651c45cc7c5bcebc4089..5df7f5cfcdb81fd9208e7462d8591ba2eebc60d1 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(); } } }