Skip to content

[Enhancement] Refactor editor themes#6229

Merged
nathanlesage merged 29 commits into
Zettlr:developfrom
benniekiss:theme-structure
Apr 30, 2026
Merged

[Enhancement] Refactor editor themes#6229
nathanlesage merged 29 commits into
Zettlr:developfrom
benniekiss:theme-structure

Conversation

@benniekiss

Copy link
Copy Markdown
Collaborator

Description

This PR refactors the codemirror theme code to be more centralized, structured, and customizable.

It is not intended to change any styling beyond those needed for organization/simplicity

Changes

While this PR is quite large, it is essentially reproducing a lot of boiler plate and reorganizing where things are located.

The main change is the implementation of CSS variables to apply various styles to editor components. By using variables, theme implementation becomes much simpler because themes only have to update the variable values rather than target individual elements. Elements styling also remains synchronized and consistent across themes. Finally, it simplifies custom themeing, as users can target the variables rather than craft unique selectors per element.

The geometry styling for the editor was moved to editor.css outside of the main-override.ts file. I did this so that main-override and the other themes only handle visual styling (color, font, size, etc).

The code styling was moved into the theme code from the render-code renderer. This integrates code styling into the main themes, again for centralization and organization.

The syntax tag highlighting code was refactored into customTagHighlight and tagHighlight. This deduplicates a lot of tags, and better organizes the code.

Additional information

My goal was to change the themes as little as possible, if at all. I believe there are one or two elements that had a color changed, but otherwise, I think I was successful in leaving everything as is!

Tested on:

@benniekiss

Copy link
Copy Markdown
Collaborator Author

I also plan to update the docs with the available variables and acceptable values once this has gotten the go-ahead on the implementation

@nathanlesage nathanlesage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sooooo, sorry again for the delay! But now I've finally taken a look at it.

First, I really appreciate the cleanliness of the themes now, this looks great and more comprehensible. Also, I appreciate that the app now distinguishes between CodeMirror builtins and Zettlr-specific elements in the variables. Lastly, even though you've moved around a lot of code, it looks definitely more organized now. I tested this out locally, and it feels mostly similar, with some improvements and changes you made that feel like they are well-placed.

That said, I do have a few small comments. First, I am a little bit concerned by the main-override.ts file, specifically its size. This can also be due to the diff, but I wonder if it might make it easier if we split out the two theme variable definition blocks into their own utility files and just merge them in there? (Feel free to disagree if you've already tried that!) Lastly, a few more comments on the logic will help so that other contributors (read: primarily I) can adopt that new system correctly. For what it's worth, I think that your theme variable documentation that you plan can simply by a copy-and-paste of the interfaces you declared into the documentation, so this way we have the documentation exactly where we need it (inside the code), but also in the official documentation so that modders can quickly find it.

Oh, and, somehow the cursor blink animation feels slower now, that one you would need to take a look at. Other than that, I think it's a great effort!

* * Remove the steps(1)-function to remove the harsh transitions.
* * Make the transition more smooth with a 15% opacity transition period.
*/
@keyframes cm-blink {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something in these animations is off now. The cursor animation feels much slower than before. Can you take a look?

Comment thread source/common/modules/markdown-editor/theme/editor.ts
Comment thread source/common/modules/markdown-editor/theme/editor.ts
},
})

/* Code Theme

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought: Maybe separate the main theme and the code theme into their own respective files, and just merge them in here? That could help with keeping it a bit more easy to follow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me

@benniekiss

benniekiss commented Apr 26, 2026

Copy link
Copy Markdown
Collaborator Author

Latest commit goes a little further with reorganizing the folder structure. I split main-overrides into an editor and code module. I renamed main-override to index to modularize the folder, and re-exported all of the themes from it.

I also moved the individual themes into a themes folder to reduce the parent clutter.

Added some comments to the top of code.ts and editor.ts briefly explaining maintenance (adding/renaming variables)

I still need to address the cursor animation, and I'll get to that today or tomorrow.

@benniekiss

Copy link
Copy Markdown
Collaborator Author

Latest commit fixes the cursor animation.

@nathanlesage This is good to go on my end if you want to look it over

@nathanlesage

Copy link
Copy Markdown
Member

Hello hello! Looks good, I tested it and everything seems good to go! I'm just wondering because having a folder theme/themes/berlin.ts seems a bit silly. But you've done so much work already, I don't want to make you bother with it once more, this PR deserves to be merged. Thank you once again :)

@nathanlesage nathanlesage merged commit 41bcebc into Zettlr:develop Apr 30, 2026
1 check passed
@benniekiss

Copy link
Copy Markdown
Collaborator Author

Feel free to change that as you see fit! I felt that they had to go into some sub folder, but I couldn't think of anything good enough. styles maybe? But that also felt redundant

@benniekiss benniekiss deleted the theme-structure branch April 30, 2026 16:31
@nathanlesage

Copy link
Copy Markdown
Member

That's why I didn't suggest any alternative, because styles also feels somewhat off. I mean, in the end it's just names, and we'll be fine to find the themes! I felt I shouldn't bother anyone with that nitpick :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants