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

add non yjs methods

parent 1adfe013
No related branches found
No related tags found
1 merge request!548Merge yjs with standard comments
...@@ -58,11 +58,11 @@ export default class CommentState { ...@@ -58,11 +58,11 @@ export default class CommentState {
const decorations = []; const decorations = [];
const ystate = ySyncPluginKey.getState(state); const ystate = ySyncPluginKey.getState(state);
const { doc, type, binding } = ystate;
const { map } = this.options; const { map } = this.options;
if (binding) { if (ystate?.binding) {
const { doc, type, binding } = ystate;
map.forEach((annotation, id) => { map.forEach((annotation, id) => {
if (typeof annotation.yjsFrom === 'number') { if (typeof annotation.yjsFrom === 'number') {
annotation.yjsFrom = absolutePositionToRelativePosition( annotation.yjsFrom = absolutePositionToRelativePosition(
...@@ -95,6 +95,26 @@ export default class CommentState { ...@@ -95,6 +95,26 @@ export default class CommentState {
return; return;
} }
decorations.push(
Decoration.inline(
from,
to,
{
class: 'comment',
'data-id': annotation.id,
},
{
id: annotation.id,
data: annotation,
inclusiveEnd: true,
},
),
);
});
} else {
this.allCommentsList().forEach(annotation => {
const { from, to } = annotation;
decorations.push( decorations.push(
Decoration.inline( Decoration.inline(
from, from,
...@@ -113,25 +133,6 @@ export default class CommentState { ...@@ -113,25 +133,6 @@ export default class CommentState {
}); });
} }
// this.allCommentsList().forEach(annotation => {
// const { from, to } = annotation;
// decorations.push(
// Decoration.inline(
// from,
// to,
// {
// class: 'comment',
// 'data-id': annotation.id,
// },
// {
// id: annotation.id,
// data: annotation,
// inclusiveEnd: true,
// },
// ),
// );
// });
this.decorations = DecorationSet.create(state.doc, decorations); this.decorations = DecorationSet.create(state.doc, decorations);
} }
...@@ -192,7 +193,16 @@ export default class CommentState { ...@@ -192,7 +193,16 @@ export default class CommentState {
if (ystate?.binding && ystate?.binding.mapping) { if (ystate?.binding && ystate?.binding.mapping) {
this.updateCommentPostions(ystate); this.updateCommentPostions(ystate);
return this; return this;
// eslint-disable-next-line no-else-return
} else {
this.options.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);
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