@@ -10,7 +10,7 @@ import { TernarySearchTree } from 'vs/base/common/map';
1010import { IDisposable , toDisposable , DisposableStore } from 'vs/base/common/lifecycle' ;
1111import { isThenable } from 'vs/base/common/async' ;
1212import { LinkedList } from 'vs/base/common/linkedList' ;
13- import { createStyleSheet , createCSSRule , removeCSSRulesContainingSelector , getDynamicStyleSheetRules } from 'vs/base/browser/dom' ;
13+ import { createStyleSheet , createCSSRule , removeCSSRulesContainingSelector } from 'vs/base/browser/dom' ;
1414import { IThemeService , ITheme } from 'vs/platform/theme/common/themeService' ;
1515import { IdGenerator } from 'vs/base/common/idGenerator' ;
1616import { isFalsyOrWhitespace } from 'vs/base/common/strings' ;
@@ -22,25 +22,25 @@ import { ILogService } from 'vs/platform/log/common/log';
2222
2323class DecorationRule {
2424
25- static keyOf ( data : IDecorationData [ ] ) : string {
26- let result = '' ;
27- for ( const d of data ) {
28- const { color, letter } = d ;
29- result += `${ color } /${ letter } ` ;
25+ static keyOf ( data : IDecorationData | IDecorationData [ ] ) : string {
26+ if ( Array . isArray ( data ) ) {
27+ return data . map ( DecorationRule . keyOf ) . join ( ',' ) ;
28+ } else {
29+ const { color, letter } = data ;
30+ return `${ color } /${ letter } ` ;
3031 }
31- return result ;
3232 }
3333
3434 private static readonly _classNames = new IdGenerator ( 'monaco-decorations-style-' ) ;
3535
36- readonly data : IDecorationData [ ] ;
36+ readonly data : IDecorationData | IDecorationData [ ] ;
3737 readonly itemColorClassName : string ;
3838 readonly itemBadgeClassName : string ;
3939 readonly bubbleBadgeClassName : string ;
4040
4141 private _refCounter : number = 0 ;
4242
43- constructor ( data : IDecorationData [ ] ) {
43+ constructor ( data : IDecorationData | IDecorationData [ ] ) {
4444 this . data = data ;
4545 this . itemColorClassName = DecorationRule . _classNames . nextId ( ) ;
4646 this . itemBadgeClassName = DecorationRule . _classNames . nextId ( ) ;
@@ -56,13 +56,30 @@ class DecorationRule {
5656 }
5757
5858 appendCSSRules ( element : HTMLStyleElement , theme : ITheme ) : void {
59+ if ( ! Array . isArray ( this . data ) ) {
60+ this . _appendForOne ( this . data , element , theme ) ;
61+ } else {
62+ this . _appendForMany ( this . data , element , theme ) ;
63+ }
64+ }
5965
66+ private _appendForOne ( data : IDecorationData , element : HTMLStyleElement , theme : ITheme ) : void {
67+ const { color, letter } = data ;
6068 // label
61- const { color } = this . data [ 0 ] ;
69+ createCSSRule ( `.${ this . itemColorClassName } ` , `color: ${ getColor ( theme , color ) } ;` , element ) ;
70+ // letter
71+ if ( letter ) {
72+ createCSSRule ( `.${ this . itemBadgeClassName } ::after` , `content: "${ letter } "; color: ${ getColor ( theme , color ) } ;` , element ) ;
73+ }
74+ }
75+
76+ private _appendForMany ( data : IDecorationData [ ] , element : HTMLStyleElement , theme : ITheme ) : void {
77+ // label
78+ const { color } = data [ 0 ] ;
6279 createCSSRule ( `.${ this . itemColorClassName } ` , `color: ${ getColor ( theme , color ) } ;` , element ) ;
6380
6481 // badge
65- const letters = this . data . filter ( d => ! isFalsyOrWhitespace ( d . letter ) ) . map ( d => d . letter ) ;
82+ const letters = data . filter ( d => ! isFalsyOrWhitespace ( d . letter ) ) . map ( d => d . letter ) ;
6683 if ( letters . length ) {
6784 createCSSRule ( `.${ this . itemBadgeClassName } ::after` , `content: "${ letters . join ( ', ' ) } "; color: ${ getColor ( theme , color ) } ;` , element ) ;
6885 }
@@ -117,8 +134,6 @@ class DecorationStyles {
117134
118135 rule . acquire ( ) ;
119136
120- this . _validate ( ) ;
121-
122137 let labelClassName = rule . itemColorClassName ;
123138 let badgeClassName = rule . itemBadgeClassName ;
124139 let tooltip = data . filter ( d => ! isFalsyOrWhitespace ( d . tooltip ) ) . map ( d => d . tooltip ) . join ( ' • ' ) ;
@@ -138,7 +153,6 @@ class DecorationStyles {
138153 this . _decorationRules . delete ( key ) ;
139154 rule . removeCSSRules ( this . _styleElement ) ;
140155 rule = undefined ;
141- this . _validate ( ) ;
142156 }
143157 }
144158 } ;
@@ -150,13 +164,6 @@ class DecorationStyles {
150164 rule . appendCSSRules ( this . _styleElement , this . _themeService . getTheme ( ) ) ;
151165 } ) ;
152166 }
153-
154- private _validate ( ) : void {
155- const ruleCount = getDynamicStyleSheetRules ( this . _styleElement ) . length ;
156- if ( this . _decorationRules . size * 3 !== ruleCount ) {
157- console . trace ( 'THIS IS BAD - CHECK YOUR DECORATIONS SOMETHING IS OUT OF SYNC' ) ;
158- }
159- }
160167}
161168
162169class FileDecorationChangeEvent implements IResourceDecorationChangeEvent {
0 commit comments