Skip to content

Commit

Permalink
fix: <body> could scroll out of position
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiksta committed Aug 8, 2024
1 parent 57a054c commit aa5ce5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/renderer/document/WournalDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/wournal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit aa5ce5e

Please sign in to comment.