Decorator precedence and node splitting

I have an extension which adds decorations based on the syntax tree. I’d like to be able to decorate some ranges with borders or border radiuses (or any other rendering where the start and end of the node is important), but there are conflicts with other extensions which can decorate these elements as well (like search, bracket matching, and selection matches).

Even if my extension has a lower precedence, the decorated range can end up getting ‘split’:

example with the word hello decorated and a selection match:

extensions: [
  Prec.low(MyDecorator)
  Prec.high(highlightSelectionMatches())
]
<span class="my-decoration">
  he
</span>
<span class="my-decoration">
  <span class="cm-selectionMatch">l</span>
  lo
</span>

But it seems like the more logical result (and the one I’d want) would be:

<span class="my-decoration">
  he
  <span class="cm-selectionMatch">l</span>
  lo
</span>

Is there a way to have that behavior currently? Is the current behavior by design (and needed for some other reason), or is it unintentional and not important usually?

Related: The search module doesn’t export its extensions, and the searchHighlighter extension is configured to lowest precedence. While the extensions could be changed to either export the necessary extensions or allow the precedence to be configurable, is there a way that I can override that precedence in my own code instead?

Can you set up an example where a low-precedence decoration is split by a high-precedence one at codemirror.net/try/? Because that should not happen.

Sure. Here’s a markdown example: markdown

I was not able to reproduce it in javascript though, so there’s something I’m missing here: javascript

Here’s a better version of the issue (removed the basicSetup extensions and unnecessary syntaxTree stuff): markdown

Thanks, the helped me figure out what was going on. This was a bug in the way the view was being redrawn, and should be fixed in @codemirror/state 6.1.1.

2 Likes