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