From 0dc91d79edd59c72c4994c95f392b21f94e2872c Mon Sep 17 00:00:00 2001 From: malkja Date: Tue, 15 Oct 2024 15:10:46 +0200 Subject: [PATCH] refactor: check the existence of witnesses Html in removeWitness() --- src/stores/annotations.ts | 3 +-- src/utils/annotations.js | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/stores/annotations.ts b/src/stores/annotations.ts index 6b95e3c4..7d6d2d9c 100644 --- a/src/stores/annotations.ts +++ b/src/stores/annotations.ts @@ -212,14 +212,13 @@ export const useAnnotationsStore = defineStore('annotations', () => { } const resetAnnotations = () => { - const textPanelHtml = document.querySelector('#text-content') if (annotations.value !== null) { annotations.value.forEach((annotation) => { const selector = AnnotationUtils.generateTargetSelector(annotation); if (selector) { AnnotationUtils.highlightTargets(selector, {level: -1}); AnnotationUtils.removeIcon(annotation); - if (AnnotationUtils.isVariant(annotation) && textPanelHtml.querySelector('.witnesses')) { + if (AnnotationUtils.isVariant(annotation)) { AnnotationUtils.removeWitness(selector, annotation.body.value.witness) } } diff --git a/src/utils/annotations.js b/src/utils/annotations.js index 3b4f3f8b..adeb4396 100644 --- a/src/utils/annotations.js +++ b/src/utils/annotations.js @@ -292,6 +292,9 @@ export function removeChipsFromOtherViews() { export function removeWitness(selector, witness) { // find the witnesses span which contains each 'witness' span child element // find this witness inside the 'witnesses' html span and remove it + const textPanelHtml = document.querySelector('#text-content') + if(!textPanelHtml.querySelector('.witnesses')) return; + const witnessesHtmlEl = getWitnessesHtmlEl(selector) const witHtml = Array.from(witnessesHtmlEl.children).filter(item => item.innerHTML === witness) if (witHtml.length > 0) witHtml[0].remove()