Fix going to annotation

This commit is contained in:
John Factotum
2023-05-27 17:09:18 +08:00
parent abcd87ed9a
commit 22956c1ae7
+5 -1
View File
@@ -220,11 +220,14 @@ export class View extends HTMLElement {
}
async showAnnotation(annotation) {
const { value } = annotation
const { index, anchor } = await this.goTo(value)
const resolved = await this.goTo(value)
if (resolved) {
const { index, anchor } = resolved
const { doc } = this.#getOverlayer(index)
const range = anchor(doc)
this.#emit('show-annotation', { value, range })
}
}
getCFI(index, range) {
const baseCFI = this.book.sections[index].cfi ?? CFI.fake.fromIndex(index)
if (!range) return baseCFI
@@ -259,6 +262,7 @@ export class View extends HTMLElement {
try {
await this.renderer.goTo(resolved)
this.history.pushState(target)
return resolved
} catch(e) {
console.error(e)
console.error(`Could not go to ${target}`)