Skip to content

Patch for CM5 native CSS nesting highlighting#4657

Open
Gazook89 wants to merge 2 commits intonaturalcrit:masterfrom
Gazook89:codemirror-patches
Open

Patch for CM5 native CSS nesting highlighting#4657
Gazook89 wants to merge 2 commits intonaturalcrit:masterfrom
Gazook89:codemirror-patches

Conversation

@Gazook89
Copy link
Copy Markdown
Collaborator

@Gazook89 Gazook89 commented Mar 1, 2026

Description

As described in issue #4655 CM5 doesn't highlight nested selectors.

The CSS mode included with CM5 has two sub-modes, x-LESS and x-SCSS, and they have a allowNested property set to true. So I took that and popped it into the base CSS mode as well, and it worked.

This adds patch-package to the dev dependencies, and after any npm install it patches node_modules/codemirror/mode/css to modify the CSS mode to include allowNested option, set to true.

Could this be done in a cleaner way, perhaps by modifying the language mode within our editor instance? Maybe. I tried. I couldn't find where I could access or add a allowNested option.

There are a few other things we could modify in the css mode in the same way like newer css properties, selectors, etc. This is just a trail balloon, though.

sets "allowNesting" to true for the CSS mode, and uses `patch-package` to maintain that through `npm install`s.
@Gazook89 Gazook89 added bug We say this works but it doesn't UI/UX User Interface, user experience labels Mar 1, 2026
@5e-Cleric 5e-Cleric moved this from Backlog to Waiting for Calc's First Review in @calculuschild's backlog Mar 1, 2026
@5e-Cleric 5e-Cleric added the 🔍 R0 - Needs first review 👀 PR ready but has not been reviewed label Mar 1, 2026
@calculuschild
Copy link
Copy Markdown
Member

calculuschild commented Mar 3, 2026

Patching the npm package feels a bit sketchy. I can see the CSS mode doesn't expose the allowNested option, but can we do something like this in our codeMirror setup to kind of wrap the old CSS mode in a custom mode and change it there?

// Get original mode
const origCssMode = CodeMirror.modes.css;

// Override it with a version that exposes the allowNested mode
CodeMirror.defineMode("css", function(config, parserConfig) {
  const mode = origCssMode(config, parserConfig);
  mode.allowNested = true;        // <- see if something like this works?
  return mode;
});

@Gazook89
Copy link
Copy Markdown
Collaborator Author

Yes that seems to work just fine. I tried to figure something out like that, but couldn't get it work, so thanks. Feel like a dummy.

@calculuschild
Copy link
Copy Markdown
Member

Yes that seems to work just fine. I tried to figure something out like that, but couldn't get it work, so thanks. Feel like a dummy.

Ok, in that case could you remove the patch-package dependency and then we can merge this?

@5e-Cleric 5e-Cleric added 🔍 R3 - Reviewed - Awaiting Fixes 🔧 PR is okayed but needs fixes before merging and removed 🔍 R0 - Needs first review 👀 PR ready but has not been reviewed labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug We say this works but it doesn't 🔍 R3 - Reviewed - Awaiting Fixes 🔧 PR is okayed but needs fixes before merging UI/UX User Interface, user experience

Projects

Status: Waiting for Calc's First Review

Development

Successfully merging this pull request may close these issues.

3 participants