From ebb77ad1c5d7a6edb83668bed3688799bd2fc4fe Mon Sep 17 00:00:00 2001
From: Zachary Zhang <zacharyzhang7@gmail.com>
Date: Tue, 18 Jun 2024 14:53:35 -0400
Subject: working line lock

---
 src/client/views/nodes/DiagramBox.tsx | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

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

diff --git a/src/client/views/nodes/DiagramBox.tsx b/src/client/views/nodes/DiagramBox.tsx
index 15e569949..fcf6e580b 100644
--- a/src/client/views/nodes/DiagramBox.tsx
+++ b/src/client/views/nodes/DiagramBox.tsx
@@ -318,20 +318,34 @@ export class DiagramBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                     
                 });
                 const inkToDelete:Doc=lineArray[j];
-                if(typeof closestStartRect.x==='number'&&typeof closestStartRect.y==='number'&&typeof closestEndRect.x==='number'&&typeof closestEndRect.y==='number'&&typeof closestStartRect.width==='number'&&typeof closestStartRect.height==='number'){
+                if(typeof closestStartRect.x==='number'&&typeof closestStartRect.y==='number'&&typeof closestEndRect.x==='number'&&typeof closestEndRect.y==='number'&&typeof closestStartRect.width==='number'&&typeof closestStartRect.height==='number'&&typeof closestEndRect.height==='number'&&typeof closestEndRect.width==='number'){
                     const points: PointData[] = [
                         { X: closestStartRect.x, Y: closestStartRect.y },
                         { X: closestStartRect.x, Y: closestStartRect.y },
                         { X: closestEndRect.x, Y: closestEndRect.y },
                         { X: closestEndRect.x, Y: closestEndRect.y }
                     ];
+                    let inkX=0;
+                    let inkY=0;
+                    if(this.getMidPoint(closestEndRect).X<this.getMidPoint(closestStartRect).X){
+                        inkX=this.getMidPoint(closestEndRect).X
+                    }
+                    else{
+                        inkX=this.getMidPoint(closestStartRect).X
+                    }
+                    if(this.getMidPoint(closestEndRect).Y<this.getMidPoint(closestStartRect).Y){
+                        inkY=this.getMidPoint(closestEndRect).Y
+                    }
+                    else{
+                        inkY=this.getMidPoint(closestStartRect).Y
+                    }
                     const newInkDoc:Doc=Docs.Create.InkDocument(
                         points,
                         { title: 'stroke',
-                        x: closestStartRect.x+closestStartRect.width/2,
-                        y: closestStartRect.y+closestStartRect.height/2,
-                        _width: closestStartRect.width,
-                        _height: closestStartRect.height,
+                        x: inkX,
+                        y: inkY,
+                        _width: Math.abs(closestEndRect.x+closestEndRect.width/2-closestStartRect.x-closestStartRect.width/2),
+                        _height: Math.abs(closestEndRect.y+closestEndRect.height/2-closestStartRect.y-closestStartRect.height/2),
                         stroke_showLabel: BoolCast(Doc.UserDoc().activeInkHideTextLabels)}, // prettier-ignore
                         1)
                     
@@ -341,7 +355,7 @@ export class DiagramBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                                 if(!inkToDelete.transformed){
                                     docViewForYourCollection.ComponentView?.removeDocument(inkToDelete)
                                     docViewForYourCollection.ComponentView?.addDocument(newInkDoc);
-                                    newInkDoc.transformed=true;
+                                    newInkDoc.transformed=false;
     
                                 }
                                 const bruh2= DocListCast(this.Document.data).filter(doc => doc.title === 'line' || doc.title === 'stroke').map(doc => DocumentManager.Instance.getDocumentView(doc, this.DocumentView?.())).filter(inkView => inkView?.ComponentView instanceof InkingStroke).map(stroke => stroke?.ComponentView);
-- 
cgit v1.2.3-70-g09d2

