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

Decoration override by Theme #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ If you want to have different regex flags for different regexes, or if you want
}
```

If you want to set decorations for different themes you can use:

```js
"highlight.regexes": {
"(//TODO)(:)": {
"regexFlags": "g",
"filterLanguageRegex": "markdown",
"filterFileRegex": ".*\\.ext",
"decorations": [ // Decoration options for not specified themes
{ "color": "yellow" },
{ "color": "red" }
],
"[One Dark Pro]": {
"decorations": [
{ "color": "green" },
{ "color": "tomato" }
]
}
}
}
```

Decoration values can also include placeholders like `$1` or `$2` that will be replaced with the content of the respective capturing group, enabling complex use cases like CSS colors highlighting.

All the supported decoration options are defined [here](https://code.visualstudio.com/docs/extensionAPI/vscode-api#DecorationRenderOptions).
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const Config = {

return vscode.workspace.getConfiguration ().get ( extension ) as any;

},

colorTheme() {
const theme = vscode.workspace.getConfiguration ().get ( "workbench.colorTheme" ) || "Default";
return `[${theme}]`;
}

};
Expand Down
9 changes: 7 additions & 2 deletions src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const Decorator = {
/* CONFIG */

config: undefined,
colorTheme: undefined,

initConfig () {

Decorator.config = Config.get ();
Decorator.colorTheme = Config.colorTheme ();

},

Expand Down Expand Up @@ -70,8 +72,11 @@ const Decorator = {
const decorations = Decorator.config.decorations,
types = Decorator.regexesStrs.map ( reStr => {

const options = Decorator.config.regexes[reStr],
reDecorations = _.castArray ( options.decorations || options );
const options = Decorator.config.regexes[reStr];
let themeDecorations = undefined;
const themeOptions = options[Decorator.colorTheme];
if (themeOptions) { themeDecorations = themeOptions.decorations; }
const reDecorations = _.castArray ( themeDecorations || options.decorations || options );

return reDecorations.map ( options => {

Expand Down