ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.59k stars 335 forks source link

Add `ignoreMutation` function for MarkView #1423

Closed Mr3zee closed 10 months ago

Mr3zee commented 10 months ago

Can we, please, have an ability to add ignoreMutation for MarkView's? I would be really helpful!

marijnh commented 10 months ago

Mark views do not support the kind of dynamic behavior that would make ignoreMutation useful, they just allow you to create a custom wrapper element. You'll have to find another solution (decorations, possibly) if you want to do something more complicated with your marks. But mind that they may be split by the presence of other marks.

Mr3zee commented 10 months ago

@marijnh but this is not dynamic behavior. There is MarkViewDesc that basically has ignoreMutation function, that just can not be extended via libraries API's, does not it make sense to provide these means of extensibility?

marijnh commented 10 months ago

Do you have an example of a use case for this?

Mr3zee commented 10 months ago

@marijnh I do. I have a text highlighting functionality. It highlights a word on hover and some words around it (not necessarily adjacent ones). To highlight the words that are not hovered I need to add a css class to corresponding DOM elements (the word wrapping into DOM elements is done by inline decorations). This causes mutations that I can suppress in paragraph node view. But if a word is wrapped into some mark, this does not work. Mutation is captured by a mark desc and the element is recreated thus rollbacking my changes. If I could ignore this mutation in a mark - the problem would disappear.

marijnh commented 10 months ago

That kind of thing is not what ignoreMutation is for—it is intended to help filter out mutations inside widgets and such. Use decorations to style content, don't directly manipulate the DOM.

Mr3zee commented 10 months ago

@marijnh technically, I'm this a mutation of the inline decoration element. But inline decorations do not have this filter either