如何在 VSCode 用户设置中指定深色和浅色主题的颜色

uEv*_*gU1 8 colors variant visual-studio-code

我想为深色或浅色主题变体自定义 VSCode 颜色设置例如:

"workbench.colorCustomizations": {
    "light": {
        "editor.background": "#ff0000",
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,据我所知,只能为所有情况或特定主题定义颜色,例如

"workbench.colorCustomizations": {
    "editor.background": "#ff0000",
    "[Default Light+]": {
        "editor.background": "#ff0000"
    }
}
Run Code Online (Sandbox Code Playgroud)

该解决方案的问题在于,它适用于任何地方或适用于一个特定主题,而不是一般的任何轻变主题。

实际上,颜色确实有深色/浅色/高对比度变体的默认值。例如,当通过扩展的 package.json 中的contributes.colors 添加颜色时,可以这样做:

"contributes": {
    "colors": [
        {
          "id": "mycolour",
          "description": "my colour",
          "defaults": {
            "dark": "#ffffff",
            "light": "#000000",
            "highContrast": "#010203"
          }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在用户设置中自定义颜色的通用变体,就像在contribus.colors中一样?我在这个主题上找到的文档并不是我所说的详尽的(基本上只是几个例子),但可能有一些我错过的东西。另外,我在上面的示例中使用了 workbench.* ,因为我最感兴趣的是该设置,而不是 editor.* 颜色设置。

小智 9

看起来根据 @uEv340yQ3gU1 的回答,暂时不支持此功能。然而,在/sf/answers/4844002621/我发现现在支持指定多个主题和通配符!请参阅https://code.visualstudio.com/updates/v1_59#_extended-theme-customization-syntax

我们可以通过指定通配符[*Light*][*Dark*](以及您经常使用的任何主题,例如 Monokai)来完成一个不错的解决方法。看起来像这样

"workbench.colorCustomizations": {
    // Default
    "editor.background": "#000000",
    // Exception for light themes
    "[*Light*][AnotherTheme]": {
        "editor.background": "#ffffff"
    }
}
Run Code Online (Sandbox Code Playgroud)

我目前使用它来指定自定义括号着色,在深色主题上使用白色作为第一个括号,在浅色主题上使用黑色!吴


uEv*_*gU1 1

https://github.com/microsoft/vscode/issues/101418是对此的功能请求,但它已于 2021 年关闭并锁定。