Scroll to anchor when body size changes

Also: remove unused private method
This commit is contained in:
John Factotum
2023-05-13 13:22:48 +08:00
parent 1396bd2b89
commit 20254e30aa
+8 -6
View File
@@ -145,8 +145,9 @@ class View {
#column = true #column = true
#size #size
#layout = {} #layout = {}
constructor({ container }) { constructor({ container, onExpand }) {
this.container = container this.container = container
this.onExpand = onExpand
this.#iframe.classList.add('foliate-filter') this.#iframe.classList.add('foliate-filter')
this.#element.append(this.#iframe) this.#element.append(this.#iframe)
Object.assign(this.#element.style, { Object.assign(this.#element.style, {
@@ -315,6 +316,7 @@ class View {
this.#overlayer.redraw() this.#overlayer.redraw()
} }
} }
this.onExpand()
} }
set overlayer(overlayer) { set overlayer(overlayer) {
this.#overlayer = overlayer this.#overlayer = overlayer
@@ -405,7 +407,10 @@ export class Paginator {
} }
#createView() { #createView() {
if (this.#view) this.#container.removeChild(this.#view.element) if (this.#view) this.#container.removeChild(this.#view.element)
this.#view = new View({ container: this.#element }) this.#view = new View({
container: this.#element,
onExpand: this.#scrollToAnchor.bind(this),
})
this.#container.append(this.#view.element) this.#container.append(this.#view.element)
return this.#view return this.#view
} }
@@ -596,6 +601,7 @@ export class Paginator {
// previous column, there is an extra zero width rect in that column // previous column, there is an extra zero width rect in that column
const rect = Array.from(rects) const rect = Array.from(rects)
.find(r => r.width > 0 && r.height > 0) || rects[0] .find(r => r.width > 0 && r.height > 0) || rects[0]
if (!rect) return
await this.#scrollToRect(rect, 'anchor') await this.#scrollToRect(rect, 'anchor')
if (select) this.#selectAnchor() if (select) this.#selectAnchor()
return return
@@ -771,10 +777,6 @@ export class Paginator {
const sel = this.#view.document.defaultView.getSelection() const sel = this.#view.document.defaultView.getSelection()
sel.removeAllRanges() sel.removeAllRanges()
} }
async #setAnchor(anchor, select) {
this.#anchor = anchor
await this.#scrollToAnchor(select)
}
destroy() { destroy() {
this.#observer.unobserve(this.#element) this.#observer.unobserve(this.#element)
this.#element.remove() this.#element.remove()