yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
345 stars 120 forks source link

[Feature request] Support multiple marks with same mark type. #61

Open vivaxy opened 3 years ago

vivaxy commented 3 years ago

Is your feature request related to a problem? Please describe. ProseMirror marks can have attributes. We can custom the mark with excludes to coexist with the mark of the same type, but different attributes.

For example, the annotation feature allows users to comment on the same text. The mark is defined like:

marks: {
  annotation: {
    attrs: { id: { default: null } },
    excludes: '',
    parseDOM: [{ tag: 'annotation', getAttrs(dom) { Number(dom.getAttributes('data-id')) } }],
    toDOM(node) { return ['annotation', { dataId: node.attrs.id }, 0] }
  }
}

Suppose we have a doc ABC, and two users adding annotations at the same time: User1: Add annotation to AB. yDoc is <annotation id="1"> -> A -> B -> </annotation> -> C. User2: Add annotation to BC. yDoc is A -> <annotation id="2"> -> B -> C -> </annotation>.

After merging, yDoc is <annotation id="1"> -> A -> <annotation id="2"> -> B -> </annotation> -> C -> </annotation>. The yDoc data is confusing the closing position of annotations, resulting C to be left out of the annotations.

Describe the solution you'd like Not sure right now.

Describe alternatives you've considered N/A

Additional context N/A

BrianHung commented 3 years ago

Similar to #34