From 7f136c6826ee7adcd25ba28decd1f8bbf5668de1 Mon Sep 17 00:00:00 2001
From: Mohammad Amoush <mohammad_amoush@brown.edu>
Date: Thu, 11 Jul 2019 12:58:36 -0400
Subject: Couple of more case fixes

---
 .../views/presentationview/PresentationElement.tsx | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

(limited to 'src/client/views/presentationview/PresentationElement.tsx')

diff --git a/src/client/views/presentationview/PresentationElement.tsx b/src/client/views/presentationview/PresentationElement.tsx
index 2b9b73e45..0ba03d78a 100644
--- a/src/client/views/presentationview/PresentationElement.tsx
+++ b/src/client/views/presentationview/PresentationElement.tsx
@@ -567,11 +567,19 @@ export default class PresentationElement extends React.Component<PresentationEle
 
     updateGroupsOnDrop2 = async (droppedDoc: Doc, de: DragManager.DropEvent) => {
 
+        let x = this.ScreenToLocalListTransform(de.x, de.y);
+        let rect = this.header!.getBoundingClientRect();
+        let bounds = this.ScreenToLocalListTransform(rect.left, rect.top + rect.height / 2);
+        let before = x[1] < bounds[1];
+
         let droppedDocIndex = this.props.allListElements.indexOf(droppedDoc);
 
         let dropIndexDiff = Math.abs(this.props.index - droppedDocIndex);
 
-        if (dropIndexDiff <= 1) {
+        if (dropIndexDiff <= 1 && before) {
+            return;
+        }
+        if (dropIndexDiff === 0 && !before) {
             return;
         }
 
@@ -582,10 +590,7 @@ export default class PresentationElement extends React.Component<PresentationEle
         let droppedDocSelectedButtons: boolean[] = await this.getSelectedButtonsOfDoc(droppedDoc);
         let curDocGuid = StrCast(droppedDoc.presentId, null);
 
-        let x = this.ScreenToLocalListTransform(de.x, de.y);
-        let rect = this.header!.getBoundingClientRect();
-        let bounds = this.ScreenToLocalListTransform(rect.left, rect.top + rect.height / 2);
-        let before = x[1] < bounds[1];
+
 
 
 
@@ -593,6 +598,8 @@ export default class PresentationElement extends React.Component<PresentationEle
         if (p.groupMappings.has(curDocGuid)) {
             console.log("Splicing from a group");
             let groupArray = this.props.groupMappings.get(curDocGuid)!;
+
+            //Error here: You Should splice the beforehand things as well, if present!!
             groupArray.splice(groupArray.indexOf(droppedDoc), 1);
             if (groupArray.length === 0) {
                 this.props.groupMappings.delete(curDocGuid);
@@ -652,6 +659,13 @@ export default class PresentationElement extends React.Component<PresentationEle
                         droppedDoc.presentId = aboveDocGuid;
                         p.groupMappings.set(aboveDocGuid, newGroup);
                     }
+                } else {
+                    let propsPresId = StrCast(this.props.document.presentId);
+                    if (this.selectedButtons[buttonIndex.Group]) {
+                        let propsArray = this.props.groupMappings.get(propsPresId)!;
+                        propsArray.unshift(droppedDoc);
+                        droppedDoc.presentId = propsPresId;
+                    }
                 }
             } else {
                 let propsDocGuid = StrCast(this.props.document.presentId);
-- 
cgit v1.2.3-70-g09d2

