From f0781beeadf54bfc7cd4709ace9f49b1bb7e7a0d Mon Sep 17 00:00:00 2001
From: Andy Rickert <andrew_rickert@brown.edu>
Date: Wed, 5 Aug 2020 20:03:37 -0400
Subject: ff

---
 .../views/nodes/formattedText/FormattedTextBox.tsx | 42 ++++++++++++----------
 1 file changed, 23 insertions(+), 19 deletions(-)

(limited to 'src/client/views/nodes/formattedText/FormattedTextBox.tsx')

diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index 5f0f33351..2711a08c0 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -23,7 +23,7 @@ import { PrefetchProxy } from '../../../../fields/Proxy';
 import { RichTextField } from "../../../../fields/RichTextField";
 import { RichTextUtils } from '../../../../fields/RichTextUtils';
 import { createSchema, makeInterface } from "../../../../fields/Schema";
-import { Cast, DateCast, NumCast, StrCast, ScriptCast } from "../../../../fields/Types";
+import { Cast, DateCast, NumCast, StrCast, ScriptCast, BoolCast } from "../../../../fields/Types";
 import { TraceMobx, OVERRIDE_ACL, GetEffectiveAcl } from '../../../../fields/util';
 import { addStyleSheet, addStyleSheetRule, clearStyleSheetRules, emptyFunction, numberRange, returnOne, returnZero, Utils, setupMoveUpEvents } from '../../../../Utils';
 import { GoogleApiClientUtils, Pulls, Pushes } from '../../../apis/google_docs/GoogleApiClientUtils';
@@ -296,6 +296,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
     public highlightSearchTerms = (terms: string[], alt: boolean) => {
         if (this._editorView && (this._editorView as any).docView && terms.some(t => t)) {
 
+
             const mark = this._editorView.state.schema.mark(this._editorView.state.schema.marks.search_highlight);
             const activeMark = this._editorView.state.schema.mark(this._editorView.state.schema.marks.search_highlight, { selected: true });
             const res = terms.filter(t => t).map(term => this.findInNode(this._editorView!, this._editorView!.state.doc, term));
@@ -303,30 +304,33 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
             let tr = this._editorView.state.tr;
             const flattened: TextSelection[] = [];
             res.map(r => r.map(h => flattened.push(h)));
+            if (BoolCast(Doc.GetProto(this.dataDoc).resetSearch) === true) {
+                this._searchIndex = 0;
+                Doc.GetProto(this.dataDoc).resetSearch = undefined;
+                this.dumbthing = true;
+            }
+            else {
+                this._searchIndex = ++this._searchIndex > flattened.length - 1 ? 0 : this._searchIndex;
+                if (alt === true) {
+                    if (this._searchIndex > 1) {
+                        this._searchIndex += -2;
+                    }
+                    else if (this._searchIndex === 1) {
+                        this._searchIndex = length - 1;
+                    }
+                    else if (this._searchIndex === 0 && length !== 1) {
+                        this._searchIndex = length - 2;
+                    }
+
+                }
+            }
 
 
             const lastSel = Math.min(flattened.length - 1, this._searchIndex);
             flattened.forEach((h: TextSelection, ind: number) => tr = tr.addMark(h.from, h.to, ind === lastSel ? activeMark : mark));
-            this._searchIndex = ++this._searchIndex > flattened.length - 1 ? 0 : this._searchIndex;
             this._editorView.dispatch(tr.setSelection(new TextSelection(tr.doc.resolve(flattened[lastSel].from), tr.doc.resolve(flattened[lastSel].to))).scrollIntoView());
-            if (alt === true) {
-                if (this._searchIndex > 1) {
-                    this._searchIndex += -2;
-                }
-                else if (this._searchIndex === 1) {
-                    this._searchIndex = length - 1;
-                }
-                else if (this._searchIndex === 0 && length !== 1) {
-                    this._searchIndex = length - 2;
-                }
-
-            }
-            else {
-
-            }
-            const index = this._searchIndex;
 
-            Doc.GetProto(this.dataDoc).searchIndex = index;
+            console.log(this._searchIndex);
         }
     }
 
-- 
cgit v1.2.3-70-g09d2

