In DecorationSet -- can I give priority to sub-ranges?

I would like to use a DecorationSet to highlight ranges and certain words inside ranges.

For example, this part of the sentence is italics and four nouns are bold, within the italics range. I’d like to display italics text as green and bold text as red.

I have the start and end positions of each range and would like to combine these five ranges to one DecorationSet to achieve the desired outcome. However, the longest range (green – italics) takes precedence over the shorter sub-ranges (red-bold) and hides their color. Is there a way to reverse this precedence so that both the long range and the shorter sub-ranges become visible?

Not with a single decoration set. However, if you can split this into multiple sets, the ones added through extensions with higher precedence will become the inner DOM nodes.

This is promising.

Is this possible from within one extension – or would all decorations of the same extension necessarily have the same precedence?

You can have one field or plugin provide multiple decoration sets with different precedences.

1 Like

Thanks a lot for your advice. I see now how it works.