From 22956c1ae7f2d21904b045ff9999f9296b676d27 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Sat, 27 May 2023 17:09:18 +0800 Subject: [PATCH] Fix going to annotation --- view.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/view.js b/view.js index 8b01d29..8f135fd 100644 --- a/view.js +++ b/view.js @@ -220,10 +220,13 @@ export class View extends HTMLElement { } async showAnnotation(annotation) { const { value } = annotation - const { index, anchor } = await this.goTo(value) - const { doc } = this.#getOverlayer(index) - const range = anchor(doc) - this.#emit('show-annotation', { value, range }) + 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) @@ -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}`)