Skip to content
Snippets Groups Projects
Commit 7f974e5a authored by chris's avatar chris
Browse files

fix deco positions

parent 39afbd7f
No related branches found
No related tags found
1 merge request!555Publish@0.9.18
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import React, { useLayoutEffect, useContext } from 'react'; import React, { useLayoutEffect, useContext } from 'react';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import {
ySyncPluginKey,
relativePositionToAbsolutePosition,
absolutePositionToRelativePosition,
} from 'y-prosemirror';
import CommentBubble from './CommentBubble'; import CommentBubble from './CommentBubble';
import { CommentDecorationPluginKey } from '../../../plugins/CommentDecorationPlugin'; import { CommentDecorationPluginKey } from '../../../plugins/CommentDecorationPlugin';
...@@ -31,6 +36,10 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { ...@@ -31,6 +36,10 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
event.preventDefault(); event.preventDefault();
const { selection } = state; const { selection } = state;
if (context.app.config.get('config.YjsService')) {
return createYjsComments(selection);
}
dispatch( dispatch(
state.tr.setMeta(CommentDecorationPluginKey, { state.tr.setMeta(CommentDecorationPluginKey, {
type: 'addComment', type: 'addComment',
...@@ -52,6 +61,47 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { ...@@ -52,6 +61,47 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
dispatch(state.tr); dispatch(state.tr);
}; };
const createYjsComments = selection => {
const ystate = ySyncPluginKey.getState(state);
const { doc, type, binding } = ystate;
const from = absolutePositionToRelativePosition(
selection.from,
type,
binding.mapping,
);
const to = absolutePositionToRelativePosition(
selection.to,
type,
binding.mapping,
);
dispatch(
state.tr.setMeta(CommentDecorationPluginKey, {
type: 'addComment',
from: relativePositionToAbsolutePosition(
doc,
type,
from,
binding.mapping,
),
to: relativePositionToAbsolutePosition(doc, type, to, binding.mapping),
data: {
yjsFrom: selection.from,
yjsTo: selection.to,
pmFrom: selection.from,
pmTo: selection.to,
type: 'comment',
conversation: [],
title: '',
group,
viewId: activeViewId,
},
}),
);
dispatch(state.tr);
};
const isCommentAllowed = () => { const isCommentAllowed = () => {
let allowed = true; let allowed = true;
state.doc.nodesBetween( state.doc.nodesBetween(
......
...@@ -208,15 +208,10 @@ export default class CommentState { ...@@ -208,15 +208,10 @@ export default class CommentState {
if (ystate?.binding && ystate?.binding.mapping) { if (ystate?.binding && ystate?.binding.mapping) {
this.updateCommentPostions(ystate); this.updateCommentPostions(ystate);
this.createDecorations(state);
return this; return this;
// eslint-disable-next-line no-else-return // eslint-disable-next-line no-else-return
} else { } else {
map.forEach((annotation, _) => {
if ('from' in annotation && 'to' in annotation) {
annotation.from = transaction.mapping.map(annotation.from);
annotation.to = transaction.mapping.map(annotation.to);
}
});
this.createDecorations(state); this.createDecorations(state);
return this; return this;
} }
......
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