diff options
author | bobzel <zzzman@gmail.com> | 2021-02-12 16:45:06 -0500 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-02-12 16:45:06 -0500 |
commit | 926665e2367ff6a201a48618df6f7985ddbcb4b0 (patch) | |
tree | 53d2771855ba763851ec1da5cce7f6357d42e373 /src | |
parent | ffeada4e258e1786536b579b17798932bf4b8a8a (diff) |
fixed previewing/scrollingto targets in web boxes and PDFs. fixed following link to textanchor when rtf doc is not displayed.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/DocumentManager.ts | 20 | ||||
-rw-r--r-- | src/client/views/nodes/LinkDocPreview.tsx | 4 | ||||
-rw-r--r-- | src/client/views/nodes/PDFBox.tsx | 14 | ||||
-rw-r--r-- | src/client/views/nodes/WebBox.tsx | 5 | ||||
-rw-r--r-- | src/client/views/pdf/PDFViewer.tsx | 18 |
5 files changed, 41 insertions, 20 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts index 5b4917a30..d2251583c 100644 --- a/src/client/util/DocumentManager.ts +++ b/src/client/util/DocumentManager.ts @@ -141,7 +141,7 @@ export class DocumentManager { finished?: () => void, ): Promise<void> => { const getFirstDocView = LightboxView.LightboxDoc ? DocumentManager.Instance.getLightboxDocumentView : DocumentManager.Instance.getFirstDocumentView; - const docView = getFirstDocView(targetDoc, originatingDoc); + let docView = getFirstDocView(targetDoc, originatingDoc); const highlight = () => { const finalDocView = getFirstDocView(targetDoc); finalDocView && Doc.linkFollowHighlight(finalDocView.rootDoc); @@ -159,19 +159,17 @@ export class DocumentManager { finished?.(); return false; }; - let annotatedDoc = Cast(targetDoc.annotationOn, Doc, null); + const annotatedDoc = Cast(targetDoc.annotationOn, Doc, null); + const rtfView = annotatedDoc && getFirstDocView(annotatedDoc); const contextDocs = docContext ? await DocListCastAsync(docContext.data) : undefined; const contextDoc = contextDocs?.find(doc => Doc.AreProtosEqual(doc, targetDoc) || Doc.AreProtosEqual(doc, annotatedDoc)) ? docContext : undefined; const targetDocContext = contextDoc || annotatedDoc; const targetDocContextView = targetDocContext && getFirstDocView(targetDocContext); - if (!docView && annotatedDoc && annotatedDoc !== originatingDoc?.context && targetDoc.type === DocumentType.TEXTANCHOR) { - const first = getFirstDocView(annotatedDoc); - if (first) { - annotatedDoc = first.rootDoc; - first.focus(targetDoc, false); - } - } else if (docView && (targetDocContextView || !targetDocContext)) { // we have a docView already and aren't forced to create a new one ... just focus on the document. TODO move into view if necessary otherwise just highlight? - docView.props.focus(docView.rootDoc, willZoom, undefined, (didFocus: boolean) => + if (!docView && targetDoc.type === DocumentType.TEXTANCHOR && rtfView) { + rtfView.focus(targetDoc, false); + } + else if (docView) { + docView.props.focus(targetDoc, willZoom, undefined, (didFocus: boolean) => new Promise<boolean>(res => { focusAndFinish(didFocus); res(); @@ -205,7 +203,7 @@ export class DocumentManager { // we didn't find the target, so it must have moved out of the context. Go back to just creating it. if (closeContextIfNotFound) targetDocContextView.props.removeDocument?.(targetDocContextView.rootDoc); if (targetDoc.layout) { // there will no layout for a TEXTANCHOR type document - Doc.SetInPlace(targetDoc, "annotationOn", undefined, false); + // Doc.SetInPlace(targetDoc, "annotationOn", undefined, false); createViewFunc(Doc.BrushDoc(targetDoc), finished); // create a new view of the target } } else { diff --git a/src/client/views/nodes/LinkDocPreview.tsx b/src/client/views/nodes/LinkDocPreview.tsx index 488ce493c..7bd5d14d2 100644 --- a/src/client/views/nodes/LinkDocPreview.tsx +++ b/src/client/views/nodes/LinkDocPreview.tsx @@ -3,7 +3,7 @@ import { Tooltip } from '@material-ui/core'; import { action, computed, observable } from 'mobx'; import { observer } from "mobx-react"; import wiki from "wikijs"; -import { Doc, DocListCast, HeightSym, Opt, WidthSym } from "../../../fields/Doc"; +import { Doc, DocListCast, HeightSym, Opt, WidthSym, DocCastAsync } from "../../../fields/Doc"; import { NumCast, StrCast } from "../../../fields/Types"; import { emptyFunction, emptyPath, returnEmptyDoclist, returnEmptyFilter, returnFalse, setupMoveUpEvents, Utils } from "../../../Utils"; import { DocServer } from '../../DocServer'; @@ -45,7 +45,7 @@ export class LinkDocPreview extends React.Component<LinkDocPreviewProps> { if (anchor1 && anchor2) { linkTarget = Doc.AreProtosEqual(anchor1, this._linkSrc) || Doc.AreProtosEqual(anchor1?.annotationOn as Doc, this._linkSrc) ? anchor2 : anchor1; } - this._targetDoc = linkTarget?.annotationOn as Doc ?? linkTarget; + linkTarget && DocCastAsync(linkTarget.annotationOn).then(action(anno => this._targetDoc = anno)); this._toolTipText = ""; } componentDidUpdate(props: any) { diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx index c20d958ff..b941c07f6 100644 --- a/src/client/views/nodes/PDFBox.tsx +++ b/src/client/views/nodes/PDFBox.tsx @@ -80,7 +80,11 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps, PdfDocum } } - scrollFocus = (doc: Doc, smooth: boolean) => this._pdfViewer?.scrollFocus(doc, smooth); + initialScrollTarget: Opt<Doc>; + scrollFocus = (doc: Doc, smooth: boolean) => { + this.initialScrollTarget = doc; + return this._pdfViewer?.scrollFocus(doc, smooth); + } getAnchor = () => this.rootDoc; componentWillUnmount() { this._selectReactionDisposer?.(); } componentDidMount() { @@ -128,7 +132,13 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps, PdfDocum }); whenActiveChanged = action((isActive: boolean) => this.props.whenActiveChanged(this._isChildActive = isActive)); - setPdfViewer = (pdfViewer: PDFViewer) => { this._pdfViewer = pdfViewer; }; + setPdfViewer = (pdfViewer: PDFViewer) => { + this._pdfViewer = pdfViewer; + if (this.initialScrollTarget) { + this.scrollFocus(this.initialScrollTarget, false); + this.initialScrollTarget = undefined; + } + }; searchStringChanged = (e: React.ChangeEvent<HTMLInputElement>) => this._searchString = e.currentTarget.value; settingsPanel() { diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index abda0ed3a..663a8b8e4 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -30,6 +30,7 @@ import { DocAfterFocusFunc } from "./DocumentView"; import { FieldView, FieldViewProps } from './FieldView'; import "./WebBox.scss"; import React = require("react"); +import { LinkDocPreview } from "./LinkDocPreview"; const htmlToText = require("html-to-text"); type WebDocument = makeInterface<[typeof documentSchema]>; @@ -119,7 +120,9 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum this._initialScroll !== undefined && (this._initialScroll = scrollTo); this._ignoreScroll = true; this.goTo(scrollTo, focusSpeed = smooth ? 500 : 0); - this.layoutDoc._scrollTop = scrollTo; + if (!LinkDocPreview.LinkInfo) { + this.layoutDoc._scrollTop = scrollTo; + } this._ignoreScroll = false; } } else { diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 17936847e..7687690b2 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 { LinkDocPreview } from "../nodes/LinkDocPreview"; const PDFJSViewer = require("pdfjs-dist/web/pdf_viewer"); const pdfjsLib = require("pdfjs-dist"); const _global = (window /* browser */ || global /* node */) as any; @@ -87,6 +88,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu private _lastSearch = false; private _viewerIsSetup = false; private _ignoreScroll = false; + private _initialScroll: Opt<number>; private _smoothScrolling = true; @computed get allAnnotations() { @@ -182,14 +184,16 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu scrollFocus = (doc: Doc, smooth: boolean) => { const mainCont = this._mainCont.current; let focusSpeed: Opt<number>; - if (doc !== this.rootDoc && mainCont) { + if (doc !== this.rootDoc && mainCont && this._pdfViewer) { const scrollTo = Utils.scrollIntoView(NumCast(doc.y), doc[HeightSym](), NumCast(this.layoutDoc._scrollTop), this.props.PanelHeight() / (this.props.scaling?.() || 1)); if (scrollTo !== undefined) { focusSpeed = 500; if (smooth) smoothScroll(focusSpeed, mainCont, scrollTo); - else mainCont.scrollTop = scrollTo; + else this._mainCont.current?.scrollTo({ top: Math.abs(scrollTo || 0) }); } + } else { + this._initialScroll = NumCast(doc.y); } return focusSpeed; } @@ -222,7 +226,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu this.gotoPage(this.Document._curPage || 1); } document.removeEventListener("pagesinit", this.pagesinit); - var quickScroll: string | undefined = ""; + var quickScroll: string | undefined = this._initialScroll ? this._initialScroll.toString() : ""; this._disposers.scroll = reaction( () => NumCast(this.Document._scrollTop), (pos) => { @@ -249,6 +253,10 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu { fireImmediately: true } ); quickScroll = undefined; + if (this._initialScroll !== undefined && this._mainCont.current) { + this._mainCont.current?.scrollTo({ top: Math.abs(this._initialScroll || 0) }); + this._initialScroll = undefined; + } } createPdfViewer() { @@ -313,7 +321,9 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu onScroll = (e: React.UIEvent<HTMLElement>) => { if (this._mainCont.current && !this._smoothScrolling) { this._ignoreScroll = true; - this.layoutDoc._scrollTop = this._mainCont.current.scrollTop; + if (!LinkDocPreview.LinkInfo) { + this.layoutDoc._scrollTop = this._mainCont.current.scrollTop; + } this._ignoreScroll = false; } } |