Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token background colors to themes #212294

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mattmundell
Copy link

@mattmundell mattmundell commented May 8, 2024

Add support for background colors to theme rules.

Closes #3429.

I did this before noticing #3429. Maybe helps someone wanting to patch their own version.

Example

id = 'patch'
tokenizer = {
  root: [
    [/^---\s.*/, "bredfill"],
    [/^\+\+\+\s.*/, "bredfill"],
    [/^\@\@\s.*/, "bredfill"],
    [/^-.*/, "minus"],
    [/^\+.*/, "plus"],
  ],
}

Mon.languages.register({ id: id,
                         firstLine: '^diff --git.*',
                         'mime-type': ['text/x-diff', 'text/x-patch', 'application/x-patch'],
                         extensions: ['.patch', '.diff'] })
Mon.languages.setMonarchTokensProvider(id, { tokenizer: tokenizer })

themeSolarized.rules.push({ "foreground": '073642',
                            "background": 'eee8d5',
                            "token": "bredfill" })

example

@mattmundell
Copy link
Author

@microsoft-github-policy-service agree

@alexdima
Copy link
Member

alexdima commented Jun 6, 2024

Thank you! While this is straight-forward to implement, I have always had 2 major concerns why I didn't implement this:

  • what is the effect of blending other background colors with the theme defined background for tokens? How does selection, find matches, word highglights, etc. look like when the theme defines such a background color
  • which of the top 20 most used themes define background colors for tokens? if we are to begin respecting now the tokens background tokens, most users will be surprised and they will interpret this as a breaking change; with the previous vscode version their code looked one way, they did nothing, and now the code has certain (unexpected) background colors.

@mattmundell
Copy link
Author

  • what is the effect of blending other background colors with the theme defined background for tokens? How does selection, find matches, word highglights, etc. look like when the theme defines such a background color

With 1291b04 the token backgrounds go below the decoration layer, so selection etc are always visible.

Here's the plain case. Cursor is at the start of line 17. The light blue is the line highlight. Tokens with backgrounds are on lines 12-14.
shot1

Here's with word highlight over the background.
shot2

And with the selection over the background. Note that the line highlight is removed whenever there's a selection.
shot3

which of the top 20 most used themes define background colors for tokens? if we are to begin respecting now the tokens background tokens, most users will be surprised and they will interpret this as a breaking change; with the previous vscode version their code looked one way, they did nothing, and now the code has certain (unexpected) background colors.

Good point. Perhaps a flag on the theme could control whether backgrounds are used in rules.

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.

[themes] Themes don't support background styling
3 participants