Replace deselect with more general content access method

This commit is contained in:
John Factotum
2023-05-16 19:12:26 +08:00
parent edea003b2f
commit 57ab79d598
3 changed files with 13 additions and 13 deletions
+5 -3
View File
@@ -279,9 +279,11 @@ export class FixedLayout extends HTMLElement {
if (s) this.#reportLocation() if (s) this.#reportLocation()
else return this.goToSpread(this.#index - 1, this.rtl ? 'left' : 'right') else return this.goToSpread(this.#index - 1, this.rtl ? 'left' : 'right')
} }
deselect() { getContents() {
for (const frame of this.#root.querySelectorAll('iframe')) return Array.from(this.#root.querySelectorAll('iframe'), frame => ({
frame.contentWindow.getSelection().removeAllRanges() doc: frame.contentDocument,
// TODO: index, overlayer
}))
} }
destroy() { destroy() {
this.#observer.unobserve(this) this.#observer.unobserve(this)
+4 -7
View File
@@ -792,12 +792,13 @@ export class Paginator extends HTMLElement {
const index = this.sections.findLastIndex(section => section.linear !== 'no') const index = this.sections.findLastIndex(section => section.linear !== 'no')
return this.goTo({ index }) return this.goTo({ index })
} }
getOverlayer() { getContents() {
if (this.#view) return { if (this.#view) return [{
index: this.#index, index: this.#index,
overlayer: this.#view.overlayer, overlayer: this.#view.overlayer,
doc: this.#view.document, doc: this.#view.document,
} }]
return []
} }
setStyle(styles) { setStyle(styles) {
const $$styles = this.#styleMap.get(this.#view?.document) const $$styles = this.#styleMap.get(this.#view?.document)
@@ -809,10 +810,6 @@ export class Paginator extends HTMLElement {
$style.textContent = style $style.textContent = style
} else $style.textContent = styles } else $style.textContent = styles
} }
deselect() {
const sel = this.#view.document.defaultView.getSelection()
sel.removeAllRanges()
}
destroy() { destroy() {
this.#observer.unobserve(this) this.#observer.unobserve(this)
} }
+4 -3
View File
@@ -148,8 +148,8 @@ export class View extends HTMLElement {
return this.addAnnotation(annotation, true) return this.addAnnotation(annotation, true)
} }
#getOverlayer(index) { #getOverlayer(index) {
const obj = this.renderer.getOverlayer() return this.renderer.getContents()
if (obj.index === index) return obj .find(x => x.index === index && x.overlayer)
} }
#createOverlayer({ doc, index }) { #createOverlayer({ doc, index }) {
const overlayer = new Overlayer() const overlayer = new Overlayer()
@@ -218,7 +218,8 @@ export class View extends HTMLElement {
} }
} }
deselect() { deselect() {
return this.renderer.deselect?.() for (const { doc } of this.renderer.getContents())
doc.defaultView.getSelection().removeAllRanges()
} }
async getTOCItemOf(target) { async getTOCItemOf(target) {
try { try {