@@ -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 } from 'vs/base/browser/dom' ;
13+ import { createStyleSheet , createCSSRule , removeCSSRulesContainingSelector , getDynamicStyleSheetRules } 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 | 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 } ` ;
25+ static keyOf ( data : IDecorationData [ ] ) : string {
26+ let result = '' ;
27+ for ( const d of data ) {
28+ const { color, letter } = d ;
29+ result += `${ color } /${ letter } ` ;
3130 }
31+ return result ;
3232 }
3333
3434 private static readonly _classNames = new IdGenerator ( 'monaco-decorations-style-' ) ;
3535
36- readonly data : IDecorationData | IDecorationData [ ] ;
36+ readonly data : IDecorationData [ ] ;
3737 readonly itemColorClassName : string ;
3838 readonly itemBadgeClassName : string ;
3939 readonly bubbleBadgeClassName : string ;
4040
4141 private _refCounter : number = 0 ;
4242
43- constructor ( data : IDecorationData | IDecorationData [ ] ) {
43+ constructor ( data : IDecorationData [ ] ) {
4444 this . data = data ;
4545 this . itemColorClassName = DecorationRule . _classNames . nextId ( ) ;
4646 this . itemBadgeClassName = DecorationRule . _classNames . nextId ( ) ;
@@ -56,30 +56,13 @@ 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- }
6559
66- private _appendForOne ( data : IDecorationData , element : HTMLStyleElement , theme : ITheme ) : void {
67- const { color, letter } = data ;
6860 // label
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 ] ;
61+ const { color } = this . data [ 0 ] ;
7962 createCSSRule ( `.${ this . itemColorClassName } ` , `color: ${ getColor ( theme , color ) } ;` , element ) ;
8063
8164 // badge
82- const letters = data . filter ( d => ! isFalsyOrWhitespace ( d . letter ) ) . map ( d => d . letter ) ;
65+ const letters = this . data . filter ( d => ! isFalsyOrWhitespace ( d . letter ) ) . map ( d => d . letter ) ;
8366 if ( letters . length ) {
8467 createCSSRule ( `.${ this . itemBadgeClassName } ::after` , `content: "${ letters . join ( ', ' ) } "; color: ${ getColor ( theme , color ) } ;` , element ) ;
8568 }
@@ -134,6 +117,8 @@ class DecorationStyles {
134117
135118 rule . acquire ( ) ;
136119
120+ this . _validate ( ) ;
121+
137122 let labelClassName = rule . itemColorClassName ;
138123 let badgeClassName = rule . itemBadgeClassName ;
139124 let tooltip = data . filter ( d => ! isFalsyOrWhitespace ( d . tooltip ) ) . map ( d => d . tooltip ) . join ( ' • ' ) ;
@@ -153,6 +138,7 @@ class DecorationStyles {
153138 this . _decorationRules . delete ( key ) ;
154139 rule . removeCSSRules ( this . _styleElement ) ;
155140 rule = undefined ;
141+ this . _validate ( ) ;
156142 }
157143 }
158144 } ;
@@ -164,6 +150,13 @@ class DecorationStyles {
164150 rule . appendCSSRules ( this . _styleElement , this . _themeService . getTheme ( ) ) ;
165151 } ) ;
166152 }
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+ }
167160}
168161
169162class FileDecorationChangeEvent implements IResourceDecorationChangeEvent {
0 commit comments