From 36a15a3ecc3d7aacc1bdb3c2ffda70b527694395 Mon Sep 17 00:00:00 2001
From: barlas <yannisbarlas@gmail.com>
Date: Sun, 8 Jan 2017 23:25:22 +0200
Subject: [PATCH] handle collapsed deletions on another users annotation

---
 .../track_change/TrackChangesProvider.js      | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
index 6931544..d5e1e3c 100644
--- a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
+++ b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
@@ -175,10 +175,10 @@ class TrackChangesProvider {
     if (notOnTrack) return this.selectCharacterAndMarkDeleted(options)
 
     if (isOnAdd) {
-      console.log('delete collapsed on add')
       const annotation = this.getAnnotationByStatus('add')
       const isOnLeftEdge = this.isOnLeftEdge(annotation)
       const isOnRightEdge = this.isOnRightEdge(annotation)
+      const isFromSameUser = this.isAnnotationFromTheSameUser(annotation)
       const key = direction.key
 
       // when on own additions, simply delete the character
@@ -187,18 +187,24 @@ class TrackChangesProvider {
       // TODO -- watch it for different users
       if (
         (isOnLeftEdge && key === 'BACKSPACE') ||
-        (isOnRightEdge && key === 'DELETE')
+        (isOnRightEdge && key === 'DELETE') ||
+        (!isFromSameUser && !isOnDelete)
       ) {
         return this.selectCharacterAndMarkDeleted(options)
       }
 
-      return this.deleteCharacter(direction.move)
+      if (!isFromSameUser && isOnDelete) {
+        // pass -- jump to 'is on delete' handler underneath
+      } else {
+        return this.deleteCharacter(direction.move)
+      }
     }
 
     if (isOnDelete) {
       const annotation = this.getAnnotationByStatus('delete')
       const isOnLeftEdge = this.isOnLeftEdge(annotation)
       const isOnRightEdge = this.isOnRightEdge(annotation)
+      const isFromSameUser = this.isAnnotationFromTheSameUser(annotation)
       const key = direction.key
 
       let moveOnly, point
@@ -215,7 +221,12 @@ class TrackChangesProvider {
       }
 
       if (moveOnly) return this.moveCursorTo(point)
-      return this.expandAnnotationToDirection(annotation, direction)
+
+      if (isFromSameUser) {
+        return this.expandAnnotationToDirection(annotation, direction)
+      } else {
+        return this.selectCharacterAndMarkDeleted(options)
+      }
     }
   }
 
-- 
GitLab