diff --git a/src/renderer/document/WournalDocument.ts b/src/renderer/document/WournalDocument.ts index 3313491..f3a955e 100644 --- a/src/renderer/document/WournalDocument.ts +++ b/src/renderer/document/WournalDocument.ts @@ -545,7 +545,7 @@ export class WournalDocument extends Component { this, [{ page, idx: idx }], [{ page, idx: idx+1 }] )); } - page.display.scrollIntoView(); + this.api.scrollPage(this.pages.value.indexOf(page) + 1); } private setupListenChangeOutlinePages() { diff --git a/src/renderer/wournal.ts b/src/renderer/wournal.ts index a4b9cd2..99a6424 100644 --- a/src/renderer/wournal.ts +++ b/src/renderer/wournal.ts @@ -39,6 +39,7 @@ import PackageJson from 'PackageJson'; import { getLogger, logFunction, logObject } from 'util/Logging'; import { PageProps } from 'document/WournalPage'; import environment from 'Shared/environment'; +import { SVGUtils } from 'util/SVGUtils'; const LOG = getLogger(__filename); @@ -369,7 +370,12 @@ export default class Wournal extends Component { const doc = this.doc.value; const pages = doc.pages.value; if (page < 0 || page >= pages.length) return; doc.activePage.next(pages[page]); - doc.activePage.value.display.scrollIntoView(); + const prevScrollPos = this.api.getScrollPos(); + const pagePos = pages[page].display.getBoundingClientRect(); + const viewport = this.documentRef.current.getBoundingClientRect(); + if (SVGUtils.rectIntersect(viewport, pagePos)) return; + const pagePosInViewPort = pagePos.top - viewport.top; + this.api.scrollPos(prevScrollPos.top + pagePosInViewPort, prevScrollPos.left); }, scrollPos: (top: number, left: number) => { this.documentRef.current.scrollTop = top;