From 57ab79d598b4ea21e6de9e543b8d8f55203b6021 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Tue, 16 May 2023 19:12:26 +0800 Subject: [PATCH] Replace deselect with more general content access method --- fixed-layout.js | 8 +++++--- paginator.js | 11 ++++------- view.js | 7 ++++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fixed-layout.js b/fixed-layout.js index 41269ef..b359bc9 100644 --- a/fixed-layout.js +++ b/fixed-layout.js @@ -279,9 +279,11 @@ export class FixedLayout extends HTMLElement { if (s) this.#reportLocation() else return this.goToSpread(this.#index - 1, this.rtl ? 'left' : 'right') } - deselect() { - for (const frame of this.#root.querySelectorAll('iframe')) - frame.contentWindow.getSelection().removeAllRanges() + getContents() { + return Array.from(this.#root.querySelectorAll('iframe'), frame => ({ + doc: frame.contentDocument, + // TODO: index, overlayer + })) } destroy() { this.#observer.unobserve(this) diff --git a/paginator.js b/paginator.js index bdba2a6..18fa0d6 100644 --- a/paginator.js +++ b/paginator.js @@ -792,12 +792,13 @@ export class Paginator extends HTMLElement { const index = this.sections.findLastIndex(section => section.linear !== 'no') return this.goTo({ index }) } - getOverlayer() { - if (this.#view) return { + getContents() { + if (this.#view) return [{ index: this.#index, overlayer: this.#view.overlayer, doc: this.#view.document, - } + }] + return [] } setStyle(styles) { const $$styles = this.#styleMap.get(this.#view?.document) @@ -809,10 +810,6 @@ export class Paginator extends HTMLElement { $style.textContent = style } else $style.textContent = styles } - deselect() { - const sel = this.#view.document.defaultView.getSelection() - sel.removeAllRanges() - } destroy() { this.#observer.unobserve(this) } diff --git a/view.js b/view.js index 448f98b..dbb8389 100644 --- a/view.js +++ b/view.js @@ -148,8 +148,8 @@ export class View extends HTMLElement { return this.addAnnotation(annotation, true) } #getOverlayer(index) { - const obj = this.renderer.getOverlayer() - if (obj.index === index) return obj + return this.renderer.getContents() + .find(x => x.index === index && x.overlayer) } #createOverlayer({ doc, index }) { const overlayer = new Overlayer() @@ -218,7 +218,8 @@ export class View extends HTMLElement { } } deselect() { - return this.renderer.deselect?.() + for (const { doc } of this.renderer.getContents()) + doc.defaultView.getSelection().removeAllRanges() } async getTOCItemOf(target) { try {