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 = () => (
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}
/>
......
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
};
......
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