Skip to content
Snippets Groups Projects
Commit 17037f7d authored by chris's avatar chris
Browse files

active comment even if it is fragmented

parent 422fa309
No related branches found
No related tags found
1 merge request!119Comment service
......@@ -7,7 +7,19 @@ const commentPlugin = new PluginKey("commentPlugin");
const getComment = state => {
const commentMark = state.schema.marks["comment"];
const commentOnSelection = DocumentHelpers.findMark(state, commentMark);
const commentOnSelection = DocumentHelpers.findFragmentedMark(
state,
commentMark
);
// Don't allow Active comment if selection is not collapsed
if (
state.selection.from !== state.selection.to &&
commentOnSelection &&
commentOnSelection.attrs.conversation.length
) {
return;
}
if (commentOnSelection) {
const commentNodes = DocumentHelpers.findChildrenByMark(
......@@ -40,12 +52,6 @@ const getComment = state => {
};
}
}
if (
state.selection.from !== state.selection.to &&
commentOnSelection &&
commentOnSelection.attrs.conversation.length
)
return;
return commentOnSelection;
};
......
......@@ -42,6 +42,33 @@ const getSelectionMark = (state, PMmark) => {
return markFound;
};
const findFragmentedMark = (state, PMmark) => {
const { selection: { $from, $to }, doc } = state;
const fromPos = [$from.pos, $from.pos + 1];
const toPos = [$to.pos, $to.pos + 1];
let markFound;
for (let i = 0; i < fromPos.length; i++) {
doc.nodesBetween(fromPos[i], toPos[i], (node, from) => {
if (node.marks) {
const actualMark = node.marks.find(mark => mark.type === PMmark);
if (actualMark) {
markFound = {
from,
to: from + node.nodeSize,
attrs: actualMark.attrs
};
}
}
});
if (markFound) {
return markFound;
break;
}
}
return markFound;
};
export const flatten = (node, descend = true) => {
if (!node) {
throw new Error('Invalid "node" parameter');
......@@ -92,5 +119,6 @@ export default {
findInlineNodes,
findChildrenByMark,
findChildrenByAttr,
getSelectionMark
getSelectionMark,
findFragmentedMark
};
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