The rule precedence of baseTheme containing `&dark` is not consistent

I’ve encountered a minor theming question that’s more of an annoyance than an issue, but I wanted to ask for clarifications. Specifically, a CodeMirror instance can be styled according to the color scheme (dark or light) via special selectors &dark/&light. But these selectors do not make them precedent over the built-in rules without one. This makes the precendence of rules not consistent.

This property was mentioned by this older thread using a legacy syntax, but my intention is to style the base elements further.

I can try to explain it with the following scenerio: The base theme has a rule named &dark .cm-cursor targeting the cursor in dark themes. If I include the same rule to specify a different color in my base theme, the original color will be overridden. However, things behave differently when the base theme rule is not scoped with &dark. Take a look at .cm-selectionMatch targeting highlight decorations matching the current selection. That rule has no dark counterparts. I want to specify it as &dark .cm-selectionMatch, but confusingly it will not override the original rule.

Demo link.

A solution is to only ever use regular themes to override what the base theme has provided. But I think the use could be avoided with a more consistent, cascading way, like treating &dark as two classes in conjunction (conceptually .cm-editor.dark).

That depends on what your expectations are. Since we’re using CSS for styling, we’re beholden to its precedence system. Every theme or base theme rule gets one implicit class selector added to it, and thus gets the same amount of added precedence. There’s nothing in the docs promising that &light/&dark selectors add precedence.

1 Like

I got the idea. Thanks.