From 49b3c7cbe01f830a2b1d2c02452901fe360348d3 Mon Sep 17 00:00:00 2001
From: eleanor-park <eleanor_park@brown.edu>
Date: Thu, 11 Jul 2024 11:50:01 -0400
Subject: updates

---
 .../collectionFreeForm/CollectionFreeFormView.tsx      | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 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 0bdcc8450..779d16a9c 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -1269,8 +1269,11 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     };
 
     _drawing: Doc[] = [];
+    _drawingContainer: Doc | undefined = undefined;
     @undoBatch
-    createDrawing = (e: React.PointerEvent<Element>, strokeData: [InkData, string, string][], opts: DrawingOptions, gptRes: string, containerDoc?: Doc) => {
+    createDrawing = (strokeData: [InkData, string, string][], opts: DrawingOptions, gptRes: string, containerDoc?: Doc) => {
+        this._drawing = [];
+        this._drawingContainer = undefined;
         strokeData.forEach((stroke: [InkData, string, string]) => {
             const bounds = InkField.getBounds(stroke[0]);
             const B = this.screenToFreeformContentsXf.transformBounds(bounds.left, bounds.top, bounds.width, bounds.height);
@@ -1294,12 +1297,13 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
         const collection = this._marqueeViewRef.current?.collection(undefined, true, this._drawing);
         if (collection) {
             const docData = collection[DocData];
-            docData.title = opts.text;
+            docData.title = opts.text.match(/^(.*?)~~~.*$/)?.[0] || opts.text;
             docData.drawingInput = opts.text;
             docData.drawingComplexity = opts.complexity;
             docData.drawingColored = opts.autoColor;
             docData.drawingSize = opts.size;
             docData.drawingData = gptRes;
+            this._drawingContainer = collection;
         }
         this._batch?.end();
     };
@@ -1307,14 +1311,14 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     removeDrawing = (doc?: Doc) => {
         this._batch = UndoManager.StartBatch('regenerateDrawing');
         if (doc) {
-            const docData: Doc = doc[DocData];
-            const children = docData.data as unknown as Doc[];
-            this._props.removeDocument?.(doc);
+            const docData = DocCast(doc[DocData]);
+            const children = DocListCast(docData.data);
             this._props.removeDocument?.(children);
+            this._props.removeDocument?.(doc);
         } else {
             this._props.removeDocument?.(this._drawing);
+            if (this._drawingContainer) this._props.removeDocument?.(this._drawingContainer);
         }
-        this._drawing = [];
     };
 
     @action
@@ -2021,7 +2025,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
                 icon: 'eye',
             });
         optionItems.push({
-            description: (this._showDrawingEditor ? 'Close' : 'Show') + ' Drawing Editor',
+            description: 'Show Drawing Editor',
             event: action(() => {
                 this._showDrawingEditor = !this._showDrawingEditor;
                 this._showDrawingEditor ? SmartDrawHandler.Instance.displayRegenerate(this._downX, this._downY - 10, this.createDrawing, this.removeDrawing) : SmartDrawHandler.Instance.hideRegenerate();
-- 
cgit v1.2.3-70-g09d2

