@@ -22,10 +22,22 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
22
22
23
23
const $ = dom . $ ;
24
24
25
+ function elementsOverlap ( el1 : HTMLElement , el2 : HTMLElement ) {
26
+ const domRect1 = el1 . getBoundingClientRect ( ) ;
27
+ const domRect2 = el2 . getBoundingClientRect ( ) ;
28
+ return ! (
29
+ domRect1 . top > domRect2 . bottom ||
30
+ domRect1 . right < domRect2 . left ||
31
+ domRect1 . bottom < domRect2 . top ||
32
+ domRect1 . left > domRect2 . right
33
+ ) ;
34
+ }
35
+
25
36
export class ColorPickerHeader extends Disposable {
26
37
27
38
private readonly _domNode : HTMLElement ;
28
39
private readonly _pickedColorNode : HTMLElement ;
40
+ private readonly _pickedColorRepresentation : HTMLElement ;
29
41
private readonly _originalColorNode : HTMLElement ;
30
42
private readonly _closeButton : CloseButton | null = null ;
31
43
private backgroundColor : Color ;
@@ -37,6 +49,8 @@ export class ColorPickerHeader extends Disposable {
37
49
dom . append ( container , this . _domNode ) ;
38
50
39
51
this . _pickedColorNode = dom . append ( this . _domNode , $ ( '.picked-color' ) ) ;
52
+ this . _pickedColorRepresentation = dom . append ( this . _pickedColorNode , document . createElement ( 'div' ) ) ;
53
+ const icon = dom . append ( this . _pickedColorNode , $ ( '.codicon.codicon-color-mode' ) ) ;
40
54
41
55
const tooltip = localize ( 'clickToToggleColorOptions' , "Click to toggle color options (rgb/hsl/hex)" ) ;
42
56
this . _pickedColorNode . setAttribute ( 'title' , tooltip ) ;
@@ -66,6 +80,16 @@ export class ColorPickerHeader extends Disposable {
66
80
this . _domNode . classList . add ( 'standalone-colorpicker' ) ;
67
81
this . _closeButton = this . _register ( new CloseButton ( this . _domNode ) ) ;
68
82
}
83
+
84
+ const resizeObserver = new ResizeObserver ( ( ) => {
85
+ this . _pickedColorRepresentation . style . display = 'block' ;
86
+ if ( elementsOverlap ( this . _pickedColorRepresentation , icon ) ) {
87
+ this . _pickedColorRepresentation . style . display = 'none' ;
88
+ } else {
89
+ this . _pickedColorRepresentation . style . display = 'block' ;
90
+ }
91
+ } ) ;
92
+ resizeObserver . observe ( this . _domNode ) ;
69
93
}
70
94
71
95
public get domNode ( ) : HTMLElement {
@@ -91,8 +115,7 @@ export class ColorPickerHeader extends Disposable {
91
115
}
92
116
93
117
private onDidChangePresentation ( ) : void {
94
- this . _pickedColorNode . textContent = this . model . presentation ? this . model . presentation . label : '' ;
95
- this . _pickedColorNode . prepend ( $ ( '.codicon.codicon-color-mode' ) ) ;
118
+ this . _pickedColorRepresentation . textContent = this . model . presentation ? this . model . presentation . label : '' ;
96
119
}
97
120
}
98
121
0 commit comments