From 280675c94b482147bbc81fdd317de6184b33f4e3 Mon Sep 17 00:00:00 2001
From: yipstanley <stanley_yip@brown.edu>
Date: Sat, 7 Sep 2019 15:58:34 -0400
Subject: pdf stuffs

---
 src/client/views/pdf/PDFViewer.tsx | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

(limited to 'src/client/views/pdf/PDFViewer.tsx')

diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index e5917fefc..91fc755c8 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -76,7 +76,15 @@ export class PDFViewer extends React.Component<IViewerProps> {
         return Math.min(this.props.pdf.numPages - 1, this.getPageFromScroll(this.panY + (this._pageSizes[0] ? this._pageSizes[0].height : 0)) + this._pageBuffer);
     }
 
-    @computed get filteredAnnotations() {
+    @computed get allAnnotations() {
+        let annotations = DocListCast(this.props.fieldExtensionDoc.annotations);
+        return annotations.filter(anno => {
+            let run = this._script.run({ this: anno });
+            return run.success ? run.result : true;
+        })
+    }
+
+    @computed get nonDocAnnotations() {
         return this._annotations.filter(anno => {
             let run = this._script.run({ this: anno });
             return run.success ? run.result : true;
@@ -101,12 +109,15 @@ export class PDFViewer extends React.Component<IViewerProps> {
         this._filterReactionDisposer = reaction(
             () => ({ scriptField: Cast(this.props.Document.filterScript, ScriptField), annos: this._annotations.slice() }),
             action(({ scriptField, annos }: { scriptField: FieldResult<ScriptField>, annos: Doc[] }) => {
+                let oldScript = this._script.originalScript;
                 this._script = scriptField && scriptField.script.compiled ? scriptField.script : CompileScript("return true") as CompiledScript;
+                if (this._script.originalScript !== oldScript) {
+                    this.Index = -1;
+                }
                 annos.forEach(d => {
                     let run = this._script.run(d);
                     d.opacity = !run.success || run.result ? 1 : 0;
                 });
-                this.Index = -1;
             }),
             { fireImmediately: true }
         );
@@ -295,12 +306,20 @@ export class PDFViewer extends React.Component<IViewerProps> {
     prevAnnotation = (e: React.MouseEvent) => {
         e.stopPropagation();
         this.Index = Math.max(this.Index - 1, 0);
+        let scrollToAnnotation = this.allAnnotations.sort((a, b) => NumCast(a.y) - NumCast(b.y))[this.Index];
+        this.allAnnotations.forEach(d => Doc.UnBrushDoc(d));
+        Doc.BrushDoc(scrollToAnnotation);
+        this.props.scrollTo(NumCast(scrollToAnnotation.y));
     }
 
     @action
     nextAnnotation = (e: React.MouseEvent) => {
         e.stopPropagation();
-        this.Index = Math.min(this.Index + 1, this.filteredAnnotations.length - 1);
+        this.Index = Math.min(this.Index + 1, this.allAnnotations.length - 1);
+        let scrollToAnnotation = this.allAnnotations.sort((a, b) => NumCast(a.y) - NumCast(b.y))[this.Index];
+        this.allAnnotations.forEach(d => Doc.UnBrushDoc(d));
+        Doc.BrushDoc(scrollToAnnotation);
+        this.props.scrollTo(NumCast(scrollToAnnotation.y));
     }
 
     sendAnnotations = (page: number) => {
@@ -413,8 +432,8 @@ export class PDFViewer extends React.Component<IViewerProps> {
             </div>
             <div className="pdfViewer-text" ref={this._viewer} />
             <div className="pdfViewer-annotationLayer" style={{ height: NumCast(this.props.Document.nativeHeight) }} ref={this._annotationLayer}>
-                {this.filteredAnnotations.sort((a, b) => NumCast(a.y) - NumCast(b.y)).map((anno, index) =>
-                    <Annotation {...this.props} ParentIndex={this.getIndex} anno={anno} index={index} key={`${anno[Id]}-annotation`} />)}
+                {this.nonDocAnnotations.sort((a, b) => NumCast(a.y) - NumCast(b.y)).map((anno, index) =>
+                    <Annotation {...this.props} anno={anno} key={`${anno[Id]}-annotation`} />)}
             </div>
             <div className="pdfViewer-overlayCont" onPointerDown={(e) => e.stopPropagation()}
                 style={{ bottom: -this.props.panY, left: `${this._searching ? 0 : 100}%` }}>
-- 
cgit v1.2.3-70-g09d2


From 01f0c9b113b3956ae1cdaa3ee8dbc3c7145bf652 Mon Sep 17 00:00:00 2001
From: yipstanley <stanley_yip@brown.edu>
Date: Sun, 8 Sep 2019 17:32:04 -0400
Subject: i think pdfs should now not require scrolling to 'correct' the pan
 position

---
 src/client/views/pdf/PDFViewer.tsx | 1 +
 1 file changed, 1 insertion(+)

(limited to 'src/client/views/pdf/PDFViewer.tsx')

diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 91fc755c8..7bc1d3507 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -181,6 +181,7 @@ export class PDFViewer extends React.Component<IViewerProps> {
 
             let startY = NumCast(this.props.Document.startY, NumCast(this.props.Document.panY));
             this.props.setPanY && this.props.setPanY(startY);
+            this.props.scrollTo(startY);
         }
     }
 
-- 
cgit v1.2.3-70-g09d2

