From aed4a386bf57ba7b1b144bacd39f9f9ccabe0dfd Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 10 Feb 2021 22:32:29 -0500 Subject: simplified focus'ing on documents. refactored scrollFocus code. changed focus in 2D to move doc into view but not center. --- src/client/views/pdf/PDFViewer.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/client/views/pdf') diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 0477192d5..dd9dfa733 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -28,6 +28,7 @@ import { AnchorMenu } from "./AnchorMenu"; import "./PDFViewer.scss"; const pdfjs = require('pdfjs-dist/es5/build/pdf.js'); import React = require("react"); +import { DocAfterFocusFunc } from "../nodes/DocumentView"; const PDFJSViewer = require("pdfjs-dist/web/pdf_viewer"); const pdfjsLib = require("pdfjs-dist"); const _global = (window /* browser */ || global /* node */) as any; @@ -179,15 +180,17 @@ export class PDFViewer extends ViewBoxAnnotatableComponent { + scrollFocus = (doc: Doc, smooth: boolean, afterFocus?: DocAfterFocusFunc) => { const mainCont = this._mainCont.current; - if (mainCont) { - if (smooth) { - smoothScroll(500, mainCont, NumCast(doc.y)); - } else { - mainCont.scrollTop = NumCast(doc.y); + if (doc !== this.rootDoc && mainCont) { + const scrollTo = Utils.scrollIntoView(NumCast(doc.y), doc[HeightSym](), NumCast(this.layoutDoc._scrollTop), this.props.PanelHeight() / (this.props.scaling?.() || 1)); + if (scrollTo !== undefined) { + if (smooth) smoothScroll(500, mainCont, scrollTo); + else mainCont.scrollTop = scrollTo; + return afterFocus?.(true); } } + afterFocus?.(false); } @action -- cgit v1.2.3-70-g09d2