Skip to content
Snippets Groups Projects
Commit 4bf4b5b2 authored by chris's avatar chris
Browse files

fix active comment merge

parent d409a824
No related branches found
No related tags found
1 merge request!108show comments as one in plugin
...@@ -49,7 +49,7 @@ const Editoria = () => ( ...@@ -49,7 +49,7 @@ const Editoria = () => (
fileUpload={file => renderImage(file)} 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>`} 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} layout={EditoriaLayout}
// TrackChange TrackChange
// onChange={source => console.log(source)} // onChange={source => console.log(source)}
user={user} user={user}
/> />
......
import { minBy, maxBy } from "lodash"; import { minBy, maxBy, last } from "lodash";
import { Plugin, PluginKey } from "prosemirror-state"; import { Plugin, PluginKey } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view"; import { Decoration, DecorationSet } from "prosemirror-view";
import { DocumentHelpers } from "wax-prosemirror-utilities"; import { DocumentHelpers } from "wax-prosemirror-utilities";
...@@ -10,33 +10,33 @@ const getComment = state => { ...@@ -10,33 +10,33 @@ const getComment = state => {
const commentMark = state.schema.marks["comment"]; const commentMark = state.schema.marks["comment"];
const commentOnSelection = DocumentHelpers.findMark(state, commentMark); const commentOnSelection = DocumentHelpers.findMark(state, commentMark);
if (commentOnSelection) { if (commentOnSelection) {
const commentNodes = DocumentHelpers.findChildrenByMark( const commentNodes = DocumentHelpers.findChildrenByMark(
state.doc, state.doc,
commentMark, commentMark,
true true
); );
const allCommentsWithSameId = [];
const allCommentsWithSameId = [];
commentNodes.map(node => { commentNodes.map(node => {
node.node.marks.filter(mark => { node.node.marks.filter(mark => {
if ( if (
mark.type.name === "comment" && mark.type.name === "comment" &&
commentOnSelection.attrs.id === mark.attrs.id commentOnSelection.attrs.id === mark.attrs.id
) { ) {
mark.from = node.pos; allCommentsWithSameId.push(node);
mark.to = node.pos + node.node.text.length;
allCommentsWithSameId.push(mark);
} }
}); });
}); });
if (allCommentsWithSameId.length > 1) { if (allCommentsWithSameId.length > 1) {
const minPos = minBy(allCommentsWithSameId, "from"); const minPos = minBy(allCommentsWithSameId, "pos");
const maxPos = maxBy(allCommentsWithSameId, "to"); const maxPos = maxBy(allCommentsWithSameId, "pos");
return { return {
from: minPos.from, from: minPos.pos,
to: maxPos.to, to: maxPos.pos + last(allCommentsWithSameId).node.nodeSize,
attrs: commentOnSelection.attrs, attrs: commentOnSelection.attrs,
contained: commentOnSelection.contained contained: commentOnSelection.contained
}; };
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment