Commit d00ff041 authored by Robert Knight's avatar Robert Knight

Refactor `scrollToAnnotation` handler to reduce nesting

parent a0367a19
...@@ -293,25 +293,24 @@ export default class Guest { ...@@ -293,25 +293,24 @@ export default class Guest {
}); });
this.crossframe.on('scrollToAnnotation', tag => { this.crossframe.on('scrollToAnnotation', tag => {
for (let anchor of this.anchors) { const anchor = this.anchors.find(a => a.annotation.$tag === tag);
if (anchor.highlights) { if (!anchor?.highlights) {
if (anchor.annotation.$tag === tag) { return;
const range = resolveAnchor(anchor); }
if (!range) { const range = resolveAnchor(anchor);
continue; if (!range) {
} return;
}
const event = new CustomEvent('scrolltorange', {
bubbles: true, const event = new CustomEvent('scrolltorange', {
cancelable: true, bubbles: true,
detail: range, cancelable: true,
}); detail: range,
const defaultNotPrevented = this.element.dispatchEvent(event); });
if (defaultNotPrevented) { const defaultNotPrevented = this.element.dispatchEvent(event);
scrollIntoView(anchor.highlights[0]);
} if (defaultNotPrevented) {
} scrollIntoView(anchor.highlights[0]);
}
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment