From 4bf4b5b2aa182740bb2527937af525583ecc1e6d Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 19 Jun 2020 17:17:27 +0300
Subject: [PATCH] fix active comment merge

---
 editors/editoria/src/Editoria.js               |  2 +-
 .../src/comments/ActiveComment.js              | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/editors/editoria/src/Editoria.js b/editors/editoria/src/Editoria.js
index e67d6f82e..c4dc8f5c9 100644
--- a/editors/editoria/src/Editoria.js
+++ b/editors/editoria/src/Editoria.js
@@ -49,7 +49,7 @@ const Editoria = () => (
       fileUpload={file => renderImage(file)}
       value={`<p class="paragraph"><span class="comment" data-id="834ba3c5-1fcf-4a42-8e2f-1f975f229716" data-conversation="[]" data-group="main">and a </span><span class="insertion" data-id="" data-user="1234" data-username="demo" data-date="26541557" data-group=""><span class="comment" data-id="834ba3c5-1fcf-4a42-8e2f-1f975f229716" data-conversation="[]" data-group="main">sdasdssd</span></span><span class="comment" data-id="834ba3c5-1fcf-4a42-8e2f-1f975f229716" data-conversation="[]" data-group="main">paragraph</span></p><p class="paragraph">more</p>`}
       layout={EditoriaLayout}
-      // TrackChange
+      TrackChange
       // onChange={source => console.log(source)}
       user={user}
     />
diff --git a/wax-prosemirror-plugins/src/comments/ActiveComment.js b/wax-prosemirror-plugins/src/comments/ActiveComment.js
index fffbe4c03..b2396b8cb 100644
--- a/wax-prosemirror-plugins/src/comments/ActiveComment.js
+++ b/wax-prosemirror-plugins/src/comments/ActiveComment.js
@@ -1,4 +1,4 @@
-import { minBy, maxBy } from "lodash";
+import { minBy, maxBy, last } from "lodash";
 import { Plugin, PluginKey } from "prosemirror-state";
 import { Decoration, DecorationSet } from "prosemirror-view";
 import { DocumentHelpers } from "wax-prosemirror-utilities";
@@ -10,33 +10,33 @@ const getComment = state => {
 
   const commentMark = state.schema.marks["comment"];
   const commentOnSelection = DocumentHelpers.findMark(state, commentMark);
+
   if (commentOnSelection) {
     const commentNodes = DocumentHelpers.findChildrenByMark(
       state.doc,
       commentMark,
       true
     );
-    const allCommentsWithSameId = [];
 
+    const allCommentsWithSameId = [];
     commentNodes.map(node => {
       node.node.marks.filter(mark => {
         if (
           mark.type.name === "comment" &&
           commentOnSelection.attrs.id === mark.attrs.id
         ) {
-          mark.from = node.pos;
-          mark.to = node.pos + node.node.text.length;
-          allCommentsWithSameId.push(mark);
+          allCommentsWithSameId.push(node);
         }
       });
     });
+
     if (allCommentsWithSameId.length > 1) {
-      const minPos = minBy(allCommentsWithSameId, "from");
-      const maxPos = maxBy(allCommentsWithSameId, "to");
+      const minPos = minBy(allCommentsWithSameId, "pos");
+      const maxPos = maxBy(allCommentsWithSameId, "pos");
 
       return {
-        from: minPos.from,
-        to: maxPos.to,
+        from: minPos.pos,
+        to: maxPos.pos + last(allCommentsWithSameId).node.nodeSize,
         attrs: commentOnSelection.attrs,
         contained: commentOnSelection.contained
       };
-- 
GitLab