Normalizing leaf nodes

I’m trying to highlight tokens using CodeMirror 6, but CodeMirror doesn’t match the DOM to the AST. While the AST returns a single token, CodeMirror renders two spans. Is there a way to force codemirror to normalize the DOM?

In the screenshot you can see two equivalent tokens (in the Lezer AST). But on line 2 the token is rendered as 2 spans. The way I get into this state is by first starting with 2 separate tokens, then deleting content between them. It’s a bit hard to repro. (and I’m sure the AST has one token, not 2, although the screenshot doesn’t show this)

If this is a bug in CodeMirror, and not known limitation/feature, I can work on a better repro.

Besides this issue CodeMirror 6 has been really a breeze. The years of experience building code editors really shows in the clean API, and I’m grateful for the thorough documentation.

That was a bug. This patch should address it.

1 Like