From 9cad9abcf164c7d81b8debf4aa2639d83edd227b Mon Sep 17 00:00:00 2001
From: andrewdkim <adkim414@gmail.com>
Date: Fri, 19 Jul 2019 11:13:12 -0400
Subject: dragging bugfix

---
 src/client/views/nodes/Keyframe.tsx | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

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

diff --git a/src/client/views/nodes/Keyframe.tsx b/src/client/views/nodes/Keyframe.tsx
index 81cbd274d..4cba6e8f9 100644
--- a/src/client/views/nodes/Keyframe.tsx
+++ b/src/client/views/nodes/Keyframe.tsx
@@ -55,7 +55,6 @@ export namespace KeyframeFunc{
     }; 
 }
 
-
 export const RegionDataSchema = createSchema({
     position: defaultSpec("number", 0),
     duration: defaultSpec("number", 0),
@@ -241,19 +240,24 @@ export class Keyframe extends React.Component<IProps> {
         let bar = this._bar.current!;
         let barX = bar.getBoundingClientRect().left;
         let offset = e.clientX - barX;
+        let leftRegion = KeyframeFunc.findAdjacentRegion(KeyframeFunc.Direction.left, this.regiondata, this.regions); 
         let firstkf: (Doc | undefined) = this.firstKeyframe; 
-        console.log(offset); 
         if (firstkf && this.regiondata.position + this.regiondata.fadeIn + offset>= NumCast(firstkf!.time)) {
+            let dif = NumCast(firstkf!.time) - (this.regiondata.position + this.regiondata.fadeIn); 
            this.regiondata.position = NumCast(firstkf!.time) - this.regiondata.fadeIn; 
-
+           this.regiondata.duration -= dif; 
         }else if (this.regiondata.duration - offset < this.regiondata.fadeIn + this.regiondata.fadeOut){ // no keyframes, just fades
             this.regiondata.position -= (this.regiondata.fadeIn + this.regiondata.fadeOut - this.regiondata.duration); 
             this.regiondata.duration = this.regiondata.fadeIn + this.regiondata.fadeOut; 
-        } else {
+        } else if (leftRegion && this.regiondata.position + offset <= leftRegion.position + leftRegion.duration) {
+            let dif = this.regiondata.position - (leftRegion.position + leftRegion.duration); 
+            this.regiondata.position = leftRegion.position + leftRegion.duration; 
+            this.regiondata.duration += dif; 
+            
+        }else {
             this.regiondata.duration -= offset;                
             this.regiondata.position += offset;
         }
-        
     }
 
 
@@ -264,9 +268,16 @@ export class Keyframe extends React.Component<IProps> {
         let bar = this._bar.current!;
         let barX = bar.getBoundingClientRect().right;
         let offset = e.clientX - barX;
-        if (this.regiondata.duration + offset < this.regiondata.fadeIn + this.regiondata.fadeOut){
+        let rightRegion = KeyframeFunc.findAdjacentRegion(KeyframeFunc.Direction.right, this.regiondata, this.regions); 
+        if (this.lastKeyframe! && this.regiondata.position + this.regiondata.duration - this.regiondata.fadeOut + offset <= NumCast((this.lastKeyframe! as Doc).time)) {
+            let dif = this.regiondata.position + this.regiondata.duration - this.regiondata.fadeOut - NumCast((this.lastKeyframe! as Doc).time);  
+            this.regiondata.duration -= dif; 
+        } else if (this.regiondata.duration + offset < this.regiondata.fadeIn + this.regiondata.fadeOut){ // nokeyframes, just fades
             this.regiondata.duration = this.regiondata.fadeIn + this.regiondata.fadeOut;
-        }else {        
+        } else if (rightRegion && this.regiondata.position + this.regiondata.duration + offset >= rightRegion.position){
+            let dif = rightRegion.position - (this.regiondata.position + this.regiondata.duration); 
+            this.regiondata.duration += dif; 
+        } else {        
             this.regiondata.duration += offset;
         }
     } 
-- 
cgit v1.2.3-70-g09d2

