aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/pdf/PDFViewer.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-02-10 22:32:29 -0500
committerbobzel <zzzman@gmail.com>2021-02-10 22:32:29 -0500
commitaed4a386bf57ba7b1b144bacd39f9f9ccabe0dfd (patch)
tree537ea7b01c98e5cdde362984292c4db3173e98c4 /src/client/views/pdf/PDFViewer.tsx
parentf240c85ff0adee914b43d9d169fa31260e03265d (diff)
simplified focus'ing on documents. refactored scrollFocus code. changed focus in 2D to move doc into view but not center.
Diffstat (limited to 'src/client/views/pdf/PDFViewer.tsx')
-rw-r--r--src/client/views/pdf/PDFViewer.tsx15
1 files changed, 9 insertions, 6 deletions
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<IViewerProps, PdfDocu
// scrolls to focus on a nested annotation document. if this is part a link preview then it will jump to the scroll location,
// otherwise it will scroll smoothly.
- scrollFocus = (doc: Doc, smooth: boolean) => {
+ 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