Commit d00ff041 authored by Robert Knight's avatar Robert Knight

Refactor `scrollToAnnotation` handler to reduce nesting

parent a0367a19
......@@ -293,12 +293,13 @@ export default class Guest {
});
this.crossframe.on('scrollToAnnotation', tag => {
for (let anchor of this.anchors) {
if (anchor.highlights) {
if (anchor.annotation.$tag === tag) {
const anchor = this.anchors.find(a => a.annotation.$tag === tag);
if (!anchor?.highlights) {
return;
}
const range = resolveAnchor(anchor);
if (!range) {
continue;
return;
}
const event = new CustomEvent('scrolltorange', {
......@@ -307,12 +308,10 @@ export default class Guest {
detail: range,
});
const defaultNotPrevented = this.element.dispatchEvent(event);
if (defaultNotPrevented) {
scrollIntoView(anchor.highlights[0]);
}
}
}
}
});
// Handler for when sidebar requests metadata for the current document
......
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