From bc14d740a23d922df96f92f99eacb51f70139643 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Tue, 31 Oct 2023 17:35:45 -0400
Subject: fixed deselecting video/audio with escape. fixed focus or open on
 iconified docs to just show them (not toggle), and fixed to showDocument on
 target unless its container isn't displayed.

---
 .../collectionFreeForm/CollectionFreeFormView.tsx  | 59 +++++++++-------------
 1 file changed, 25 insertions(+), 34 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 0d43d6ab8..10d0117ef 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -82,6 +82,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     private _lastY: number = 0;
     private _downX: number = 0;
     private _downY: number = 0;
+    private _downTime = 0;
     private _inkToTextStartX: number | undefined;
     private _inkToTextStartY: number | undefined;
     private _wordPalette: Map<string, string> = new Map<string, string>();
@@ -92,7 +93,6 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     private _layoutPoolData = observable.map<string, PoolData>();
     private _layoutSizeData = observable.map<string, { width?: number; height?: number }>();
     private _cachedPool: Map<string, PoolData> = new Map();
-    private _lastTap = 0;
     private _batch: UndoManager.Batch | undefined = undefined;
     private _brushtimer: any;
     private _brushtimer1: any;
@@ -130,10 +130,6 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     @observable GroupChildDrag: boolean = false; // child document view being dragged.  needed to update drop areas of groups when a group item is dragged.
     @observable _brushedView = { width: 0, height: 0, panX: 0, panY: 0, opacity: 0 }; // highlighted region of freeform canvas used by presentations to indicate a region
 
-    constructor(props: any) {
-        super(props);
-    }
-
     @computed get views() {
         const viewsMask = this._layoutElements.filter(ele => ele.bounds && !ele.bounds.z && ele.inkMask !== -1 && ele.inkMask !== undefined).map(ele => ele.ele);
         const renderableEles = this._layoutElements.filter(ele => ele.bounds && !ele.bounds.z && (ele.inkMask === -1 || ele.inkMask === undefined)).map(ele => ele.ele);
@@ -640,6 +636,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     onPointerDown = (e: React.PointerEvent): void => {
         this._downX = this._lastX = e.pageX;
         this._downY = this._lastY = e.pageY;
+        this._downTime = Date.now();
         if (e.button === 0 && !e.altKey && !e.ctrlKey && this.props.isContentActive(true)) {
             if (
                 !this.props.Document._isGroup && // group freeforms don't pan when dragged -- instead let the event go through to allow the group itself to drag
@@ -809,31 +806,24 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     @action
     onClick = (e: React.MouseEvent) => {
         if (this._lightboxDoc) this._lightboxDoc = undefined;
-        if (this.onBrowseClickHandler()) {
-            if (this.props.DocumentView?.()) {
-                this.onBrowseClickHandler().script.run({ documentView: this.props.DocumentView(), clientX: e.clientX, clientY: e.clientY });
-            }
-            e.stopPropagation();
-            e.preventDefault();
-        } else if (Math.abs(e.pageX - this._downX) < 3 && Math.abs(e.pageY - this._downY) < 3) {
-            if (e.shiftKey && (this.props.renderDepth === 0 || this.isContentActive())) {
-                if (Date.now() - this._lastTap < 300) {
-                    // reset zoom of freeform view to 1-to-1 on a shift + double click
-                    this.zoomSmoothlyAboutPt(this.getTransform().transformPoint(e.clientX, e.clientY), 1);
-                }
+        if (Utils.isClick(e.pageX, e.pageY, this._downX, this._downY, this._downTime)) {
+            if (this.onBrowseClickHandler()) {
+                this.onBrowseClickHandler().script.run({ documentView: this.props.DocumentView?.(), clientX: e.clientX, clientY: e.clientY });
+                e.stopPropagation();
+                e.preventDefault();
+            } else if (this.isContentActive() && e.shiftKey) {
+                // reset zoom of freeform view to 1-to-1 on a shift + double click
+                this.zoomSmoothlyAboutPt(this.getTransform().transformPoint(e.clientX, e.clientY), 1);
                 e.stopPropagation();
                 e.preventDefault();
             }
-            this._lastTap = Date.now();
         }
     };
 
     @action
     scrollPan = (e: WheelEvent | { deltaX: number; deltaY: number }): void => {
         PresBox.Instance?.pauseAutoPres();
-        const dx = e.deltaX;
-        const dy = e.deltaY;
-        this.setPan(NumCast(this.Document[this.panXFieldKey]) - dx, NumCast(this.Document[this.panYFieldKey]) - dy, 0, true);
+        this.setPan(NumCast(this.Document[this.panXFieldKey]) - e.deltaX, NumCast(this.Document[this.panYFieldKey]) - e.deltaY, 0, true);
     };
 
     @action
@@ -2301,20 +2291,21 @@ class CollectionFreeFormBackgroundGrid extends React.Component<CollectionFreeFor
 export function CollectionBrowseClick(dv: DocumentView, clientX: number, clientY: number) {
     const browseTransitionTime = 500;
     SelectionManager.DeselectAll();
-    DocumentManager.Instance.showDocument(dv.rootDoc, { zoomScale: 0.8, willZoomCentered: true }, (focused: boolean) => {
-        if (!focused) {
-            const selfFfview = !dv.rootDoc._isGroup && dv.ComponentView instanceof CollectionFreeFormView ? dv.ComponentView : undefined;
-            let containers = dv.props.docViewPath();
-            let parFfview = dv.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView;
-            for (var cont of containers) {
-                parFfview = parFfview ?? cont.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView;
+    dv &&
+        DocumentManager.Instance.showDocument(dv.rootDoc, { zoomScale: 0.8, willZoomCentered: true }, (focused: boolean) => {
+            if (!focused) {
+                const selfFfview = !dv.rootDoc._isGroup && dv.ComponentView instanceof CollectionFreeFormView ? dv.ComponentView : undefined;
+                let containers = dv.props.docViewPath();
+                let parFfview = dv.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView;
+                for (var cont of containers) {
+                    parFfview = parFfview ?? cont.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView;
+                }
+                while (parFfview?.rootDoc._isGroup) parFfview = parFfview.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView;
+                const ffview = selfFfview && selfFfview.rootDoc[selfFfview.scaleFieldKey] !== 0.5 ? selfFfview : parFfview; // if focus doc is a freeform that is not at it's default 0.5 scale, then zoom out on it.  Otherwise, zoom out on the parent ffview
+                ffview?.zoomSmoothlyAboutPt(ffview.getTransform().transformPoint(clientX, clientY), ffview?.isAnnotationOverlay ? 1 : 0.5, browseTransitionTime);
+                Doc.linkFollowHighlight(dv?.props.Document, false);
             }
-            while (parFfview?.rootDoc._isGroup) parFfview = parFfview.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView;
-            const ffview = selfFfview && selfFfview.rootDoc[selfFfview.scaleFieldKey] !== 0.5 ? selfFfview : parFfview; // if focus doc is a freeform that is not at it's default 0.5 scale, then zoom out on it.  Otherwise, zoom out on the parent ffview
-            ffview?.zoomSmoothlyAboutPt(ffview.getTransform().transformPoint(clientX, clientY), ffview?.isAnnotationOverlay ? 1 : 0.5, browseTransitionTime);
-            Doc.linkFollowHighlight(dv?.props.Document, false);
-        }
-    });
+        });
 }
 ScriptingGlobals.add(CollectionBrowseClick);
 ScriptingGlobals.add(function nextKeyFrame(readOnly: boolean) {
-- 
cgit v1.2.3-70-g09d2

