Rendering no longer breaks when single annotation is broken

This commit is contained in:
Rainer Simon 2020-08-07 09:28:43 +02:00
parent e823d5a506
commit 0bf9f37549
1 changed files with 13 additions and 7 deletions

View File

@ -41,15 +41,21 @@ export default class Highlighter {
}) })
_addAnnotation = annotation => { _addAnnotation = annotation => {
const [ domStart, domEnd ] = this.charOffsetsToDOMPosition([ annotation.start, annotation.end ]); try {
const [ domStart, domEnd ] = this.charOffsetsToDOMPosition([ annotation.start, annotation.end ]);
const range = document.createRange(); const range = document.createRange();
range.setStart(domStart.node, domStart.offset); range.setStart(domStart.node, domStart.offset);
range.setEnd(domEnd.node, domEnd.offset); range.setEnd(domEnd.node, domEnd.offset);
const spans = this.wrapRange(range); const spans = this.wrapRange(range);
this.applyStyles(annotation, spans); this.applyStyles(annotation, spans);
this.bindAnnotation(annotation, spans); this.bindAnnotation(annotation, spans);
} catch (error) {
console.warn('Could not render annotation')
console.warn(error);
console.warn(annotation.underlying);
}
} }
_findAnnotationSpans = annotation => { _findAnnotationSpans = annotation => {