diff --git a/client/src/components/ContentBlock.vue b/client/src/components/ContentBlock.vue index 2af97c27..dfd3b9b1 100644 --- a/client/src/components/ContentBlock.vue +++ b/client/src/components/ContentBlock.vue @@ -269,7 +269,7 @@ onUnmounted(() => { if (element !== null) { console.log('unmounting'); - element.removeEventListener('mouseup', getSelectionHandler); + element.removeEventListener('mouseup', getSelectionHandler(element, props.contentBlock)); } }); diff --git a/client/src/directives/highlight.ts b/client/src/directives/highlight.ts index f33f7196..c2c1b918 100644 --- a/client/src/directives/highlight.ts +++ b/client/src/directives/highlight.ts @@ -102,13 +102,13 @@ export const getSelectionHandler = (el: HTMLElement, contentBlock: ContentBlockN const paragraph = findClosestAncestorWithTag(startContainer, 'p'); const endAncestor = findClosestAncestorWithTag(endContainer, 'p'); - if (paragraph === endAncestor) { + if (paragraph && paragraph === endAncestor) { // todo: rename this variable, `parent` is not correct anymore const contentComponent = findClosestAncestorWithClass(startContainer, 'content-component'); if (contentComponent) { // our selection is wholly inside the container node, we continue with it const position = findPositionInParent(contentComponent); - const siblings = Array.from(paragraph.parentElement.children); + const siblings = Array.from(paragraph.parentElement?.children || []); const positionInTextBlock = siblings.indexOf(paragraph); const numOfParagraphs = Array.from(contentComponent.children[1].children).filter(