Recommended way to create bounded content

I have a custom inline node and I want to display a little annotation number at the end of it. That annotation must be bound to that node and be removed when the node is removed and must not be separated from the node as well. also it should not be possible to edit it. What would be the recommended approach for that?

I considered 2 things:

  1. Create a custom inline node called “annotation” but it will presumably appear that separating it from node next to it would be very easy
  2. Somehow create a non document node for my original custom node, like absolute div and position it. But it will mean I will have to add paddings to the right side of original custom node

Anything better?

This sounds like you want a widget decoration. Just make sure, in the plugin that maintains the decoration, to recompute the widget positions when the document changes, based on where need the annotations.

Thanks. I actually had a question in my head of what is the difference between decorations and marks, since in the documentation example the decoration served pretty much similar purpose as marks.

My last resort solution was to check the document structure every change and adjust things if I find anything weird. I already traverse state json, but would love to avoid that