Hello everyone, any ideas would be appreciated
What I want to do
I want to display a UI element (not a CSS pseudo-element) at the start of certain words within the editor. A key requirement is that the container width is not fixed. If a word wraps onto the next line due to line breaks, I need the UI element to wrap with it so that it stays at the beginning of the word on the new line.
<p>Hello <div class="widget-decoration"/>World</p>
<!-- ^ bad, "World" will break into a new line,
but .widget-decoration stays on the first line.
Unaware of any CSS that could fix this. -->
<p>Hello <span class="inline-decoration"><div class="widget-decoration"/>World</span></p>
<!-- ^ good, but DOM structure can't be achieved with ProseMirror? -->
How I do it
- Wrap words in a span via
Decoration.inline
. - Hook into view updates and manually render DOM elements inside the nodes produced by
Decoration.inline
. - Use
ignoreMutation
to avoid parsing the manually rendered DOM nodes
I hate manually modifying ProseMirror DOM. Any alternative approaches would be greatly appreciated!
Thanks, V!
PS. Can’t use marks. I could achieve the desired structure using Marks, however since I’m in a collaborative environment, I don’t want to be modify the document to achieve what is a view layer funcionality.