Skip to content

Commit

Permalink
refactor: check the existence of witnesses Html in removeWitness()
Browse files Browse the repository at this point in the history
  • Loading branch information
malkja committed Oct 15, 2024
1 parent 254d2cb commit 0dc91d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/stores/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0dc91d7

Please sign in to comment.