From 8d68db4de347e772a5272fd0519fa30c03a30db4 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 29 Apr 2024 23:00:52 -0400
Subject: updating showDocument to not have to know about groups -- all group
 logic is in collectionfreeformview.

---
 .../collectionFreeForm/CollectionFreeFormView.tsx  | 30 +++++++++++++---------
 1 file changed, 18 insertions(+), 12 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 8a859a3fd..986c1e357 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -310,7 +310,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     }
 
     focusOnPoint = (options: FocusViewOptions) => {
-        const {pointFocus, zoomTime, didMove} = options;
+        const { pointFocus, zoomTime, didMove } = options;
         if (!this.Document.isGroup && pointFocus && !didMove) {
             const dfltScale = this.isAnnotationOverlay ? 1 : 0.5;
             if (this.layoutDoc[this.scaleFieldKey] !== dfltScale) {
@@ -322,6 +322,14 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
         return undefined;
     };
 
+    /**
+     * Focusing on a member of a group -
+     *   Since groups can't pan and zoom like regular collections, this method focuses on a Doc in a group by
+     * focusing on the group with an additional transformation to force the final focus to be on the center of the group item.
+     * @param anchor
+     * @param options
+     * @returns
+     */
     groupFocus = (anchor: Doc, options: FocusViewOptions) => {
         if (options.pointFocus) return this.focusOnPoint(options);
         options.docTransform = new Transform(NumCast(anchor.x) + NumCast(anchor._width)/2 - NumCast(this.layoutDoc[this.panXFieldKey]),
@@ -331,19 +339,17 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
         return res;
     };
 
-    focus = (anchor: Doc, options: FocusViewOptions) => {
+    focus = (anchor: Doc, options: FocusViewOptions): any => {
+        if (anchor.isGroup && !options.docTransform && options.contextPath?.length) {
+            // don't focus on group if there's a context path because we're about to focus on a group item
+            // which will override any group focus. (If we allowed the group to focus, it would mark didMove even if there were no net movement)
+            return undefined;
+        }
         if (this._lightboxDoc) return undefined;
         if (options.pointFocus) return this.focusOnPoint(options);
-        if (anchor === this.Document) {
-            // if (options.willZoomCentered && options.zoomScale) {
-            //     this.fitContentOnce();
-            //     options.didMove = true;
-            // }
-        }
-        // prettier-ignore
-        if (anchor.type !== DocumentType.CONFIG && 
-            !DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]).includes(anchor) && //
-            !this.childLayoutPairs.map(pair => pair.layout).includes(anchor)) { 
+        const anchorInCollection = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]).includes(anchor);
+        const anchorInChildViews = this.childLayoutPairs.map(pair => pair.layout).includes(anchor);
+        if (anchor.type !== DocumentType.CONFIG && !anchorInCollection && !anchorInChildViews) {
             return undefined;
         }
         const xfToCollection = options?.docTransform ?? Transform.Identity();
-- 
cgit v1.2.3-70-g09d2

