Skip to content
Snippets Groups Projects
Commit 16a17410 authored by chris's avatar chris
Browse files

fix for comment creation on single note

parent b5551e1b
No related branches found
No related tags found
1 merge request!243Feature improvments
...@@ -133,15 +133,26 @@ const isOnSameTextBlock = state => { ...@@ -133,15 +133,26 @@ const isOnSameTextBlock = state => {
const createComment = (state, dispatch, group, viewid) => { const createComment = (state, dispatch, group, viewid) => {
const { const {
selection: { $from, $to }, selection: { $from, $to },
tr,
} = state; } = state;
let footnote = false; let footnote = false;
let footnoteNode;
state.doc.nodesBetween($from.pos, $to.pos, (node, from) => { state.doc.nodesBetween($from.pos, $to.pos, (node, from) => {
if (node.type.name === 'footnote') { if (node.type.name === 'footnote') {
footnote = true; footnote = true;
footnoteNode = node;
} }
}); });
if (footnote) return createCommentOnFootnote(state, dispatch, group, viewid); if (footnote) {
if (
footnoteNode.content.size + 2 ===
state.selection.to - state.selection.from
) {
return createCommentOnSingleFootnote(state, dispatch, group, viewid);
}
return createCommentOnFootnote(state, dispatch, group, viewid);
}
toggleMark(state.config.schema.marks.comment, { toggleMark(state.config.schema.marks.comment, {
id: uuidv4(), id: uuidv4(),
...@@ -151,6 +162,23 @@ const createComment = (state, dispatch, group, viewid) => { ...@@ -151,6 +162,23 @@ const createComment = (state, dispatch, group, viewid) => {
})(state, dispatch); })(state, dispatch);
}; };
const createCommentOnSingleFootnote = (state, dispatch, group, viewid) => {
const { tr } = state;
tr.step(
new AddMarkStep(
state.selection.from,
state.selection.from + 1,
state.config.schema.marks.comment.create({
id: uuidv4(),
group,
conversation: [],
viewid,
}),
),
);
dispatch(tr);
};
const createCommentOnFootnote = (state, dispatch, group, viewid) => { const createCommentOnFootnote = (state, dispatch, group, viewid) => {
const { const {
selection: { $from }, selection: { $from },
......
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