From 2bc8cda2515c54120e2f22e80071e730d3b1f8f6 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 3 Feb 2021 12:44:34 -0500 Subject: fixed updating annotations when navigating on a pdf --- src/client/views/nodes/WebBox.tsx | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index 352abd1e7..a3afc96d4 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -36,13 +36,12 @@ const WebDocument = makeInterface(documentSchema); @observer export class WebBox extends ViewBoxAnnotatableComponent(WebDocument) { - private _annotationLayer: React.RefObject = React.createRef(); public static LayoutString(fieldKey: string) { return FieldView.LayoutString(WebBox, fieldKey); } private _mainCont: React.RefObject = React.createRef(); - private _setPreviewCursor: undefined | ((x: number, y: number, drag: boolean) => void); private _disposers: { [name: string]: IReactionDisposer } = {}; private _longPressSecondsHack?: NodeJS.Timeout; private _outerRef = React.createRef(); + private _annotationLayer: React.RefObject = React.createRef(); private _iframeIndicatorRef = React.createRef(); private _iframeDragRef = React.createRef(); @observable private _marqueeing: number[] | undefined; @@ -52,11 +51,10 @@ export class WebBox extends ViewBoxAnnotatableComponent = new Dictionary(); - get scrollHeight() { return this.webpage?.scrollHeight || 1000; } get _collapsed() { return StrCast(this.layoutDoc._chromeStatus) !== "enabled"; } set _collapsed(value) { this.layoutDoc._chromeStatus = !value ? "enabled" : "disabled"; } + get scrollHeight() { return this.webpage?.scrollHeight || 1000; } get webpage() { return this._iframe?.contentDocument?.children[0]; } - url = () => this._url; constructor(props: any) { super(props); @@ -64,6 +62,7 @@ export class WebBox extends ViewBoxAnnotatableComponent { @@ -128,7 +127,6 @@ export class WebBox extends ViewBoxAnnotatableComponent void) => this._setPreviewCursor = func; iframeWheel = (e: any) => { if (this._forceSmoothScrollUpdate && e.target?.children) { this.webpage && setTimeout(action(() => { @@ -151,7 +149,6 @@ export class WebBox extends ViewBoxAnnotatableComponent this.rootDoc; - async componentDidMount() { this.props.setContentView?.(this); // this tells the DocumentView that this AudioBox is the "content" of the document. this allows the DocumentView to indirectly call getAnchor() on the AudioBox when making a link. @@ -205,9 +202,8 @@ export class WebBox extends ViewBoxAnnotatableComponent(DocListCast(this.dataDoc[this.annotationKey])); this.dataDoc[this.fieldKey] = new WebField(new URL(this._url = future.pop()!)); - this.dataDoc[this.annotationKey] = new List(DocListCast(this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)])); + this._annotationKey = this.fieldKey + "-annotations-" + this.urlHash(this._url); return true; } return false; @@ -220,9 +216,8 @@ export class WebBox extends ViewBoxAnnotatableComponent([this._url]); else future.push(this._url); - this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)] = new List(DocListCast(this.dataDoc[this.annotationKey])); this.dataDoc[this.fieldKey] = new WebField(new URL(this._url = history.pop()!)); - this.dataDoc[this.annotationKey] = new List(DocListCast(this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)])); + this._annotationKey = this.fieldKey + "-annotations-" + this.urlHash(this._url); return true; } return false; @@ -238,7 +233,6 @@ export class WebBox extends ViewBoxAnnotatableComponent(annos); } this._url = newUrl; + this._annotationKey = this.fieldKey + "-annotations-" + this.urlHash(this._url); this.dataDoc[this.fieldKey] = new WebField(new URL(newUrl)); - this.dataDoc[this.annotationKey] = new List([]); } catch (e) { console.log("WebBox URL error:" + this._url); } @@ -270,15 +263,10 @@ export class WebBox extends ViewBoxAnnotatableComponent { this._ignore = e.timeStamp; }; - onPrePointer = (e: React.PointerEvent) => { this._ignore = e.timeStamp; }; - onPostPointer = (e: React.PointerEvent) => { - if (this._ignore !== e.timeStamp) e.stopPropagation(); - } - - onPostWheel = (e: React.WheelEvent) => { - if (this._ignore !== e.timeStamp) e.stopPropagation(); - } + onPreWheel = (e: React.WheelEvent) => this._ignore = e.timeStamp; + onPrePointer = (e: React.PointerEvent) => this._ignore = e.timeStamp; + onPostPointer = (e: React.PointerEvent) => this._ignore !== e.timeStamp && e.stopPropagation(); + onPostWheel = (e: React.WheelEvent) => this._ignore !== e.timeStamp && e.stopPropagation(); onLongPressDown = (e: React.PointerEvent) => { this._pressX = e.clientX; @@ -389,8 +377,6 @@ export class WebBox extends ViewBoxAnnotatableComponent -- cgit v1.2.3-70-g09d2