Skip to content

Commit

Permalink
semantic styling: apply defaults only when no match
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Mar 30, 2020
1 parent 8291390 commit 80cd0ee
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/vs/workbench/services/themes/common/colorThemeData.ts
Expand Up @@ -170,25 +170,6 @@ export class ColorThemeData implements IWorkbenchColorTheme {
}
}
}
for (const rule of tokenClassificationRegistry.getTokenStylingDefaultRules()) {
const matchScore = rule.selector.match(type, modifiers, language);
if (matchScore >= 0) {
let style: TokenStyle | undefined;
if (rule.defaults.scopesToProbe) {
style = this.resolveScopes(rule.defaults.scopesToProbe);
if (style) {
_processStyle(matchScore, style, rule.defaults.scopesToProbe);
}
}
if (!style && useDefault !== false) {
const tokenStyleValue = rule.defaults[this.type];
style = this.resolveTokenStyleValue(tokenStyleValue);
if (style) {
_processStyle(matchScore, style, tokenStyleValue!);
}
}
}
}
for (const rule of this.tokenStylingRules) {
const matchScore = rule.selector.match(type, modifiers, language);
if (matchScore >= 0) {
Expand All @@ -201,6 +182,36 @@ export class ColorThemeData implements IWorkbenchColorTheme {
_processStyle(matchScore, rule.style, rule);
}
}
let hasUndefinedStyleProperty = false;
for (let k in score) {
const key = k as keyof TokenStyle;
if (score[key] === -1) {
hasUndefinedStyleProperty = true;
} else {
score[key] = Number.MAX_VALUE; // set it to the max, so it won't be replaced by a default
}
}
if (hasUndefinedStyleProperty) {
for (const rule of tokenClassificationRegistry.getTokenStylingDefaultRules()) {
const matchScore = rule.selector.match(type, modifiers, language);
if (matchScore >= 0) {
let style: TokenStyle | undefined;
if (rule.defaults.scopesToProbe) {
style = this.resolveScopes(rule.defaults.scopesToProbe);
if (style) {
_processStyle(matchScore, style, rule.defaults.scopesToProbe);
}
}
if (!style && useDefault !== false) {
const tokenStyleValue = rule.defaults[this.type];
style = this.resolveTokenStyleValue(tokenStyleValue);
if (style) {
_processStyle(matchScore, style, tokenStyleValue!);
}
}
}
}
}
return TokenStyle.fromData(result);

}
Expand Down

0 comments on commit 80cd0ee

Please sign in to comment.