@@ -140,23 +140,40 @@ export class HoverController extends Disposable implements IEditorContribution {
140
140
private _onEditorMouseDown ( mouseEvent : IEditorMouseEvent ) : void {
141
141
142
142
this . _hoverState . mouseDown = true ;
143
- const target = mouseEvent . target ;
144
143
145
- if ( target . type === MouseTargetType . CONTENT_WIDGET && target . detail === ContentHoverWidget . ID ) {
146
- // mouse down on top of content hover widget
144
+ const shouldNotHideCurrentHoverWidget = this . _shouldNotHideCurrentHoverWidget ( mouseEvent ) ;
145
+ if ( shouldNotHideCurrentHoverWidget ) {
147
146
return ;
148
147
}
149
148
150
- if ( target . type === MouseTargetType . OVERLAY_WIDGET && target . detail === MarginHoverWidget . ID ) {
151
- // mouse down on top of margin hover widget
152
- return ;
149
+ this . _hideWidgets ( ) ;
150
+ }
151
+
152
+ private _shouldNotHideCurrentHoverWidget ( mouseEvent : IPartialEditorMouseEvent ) : boolean {
153
+ if (
154
+ this . _isMouseOnContentHoverWidget ( mouseEvent )
155
+ || this . _isMouseOnMarginHoverWidget ( mouseEvent )
156
+ || this . _isContentWidgetResizing ( )
157
+ ) {
158
+ return true ;
153
159
}
160
+ return false ;
161
+ }
154
162
155
- if ( this . _contentWidget ?. widget . isResizing ) {
156
- return ;
163
+ private _isMouseOnMarginHoverWidget ( mouseEvent : IPartialEditorMouseEvent ) : boolean {
164
+ const target = mouseEvent . target ;
165
+ if ( ! target ) {
166
+ return false ;
157
167
}
168
+ return target . type === MouseTargetType . OVERLAY_WIDGET && target . detail === MarginHoverWidget . ID ;
169
+ }
158
170
159
- this . _hideWidgets ( ) ;
171
+ private _isMouseOnContentHoverWidget ( mouseEvent : IPartialEditorMouseEvent ) : boolean {
172
+ const target = mouseEvent . target ;
173
+ if ( ! target ) {
174
+ return false ;
175
+ }
176
+ return target . type === MouseTargetType . CONTENT_WIDGET && target . detail === ContentHoverWidget . ID ;
160
177
}
161
178
162
179
private _onEditorMouseUp ( ) : void {
@@ -166,11 +183,9 @@ export class HoverController extends Disposable implements IEditorContribution {
166
183
private _onEditorMouseLeave ( mouseEvent : IPartialEditorMouseEvent ) : void {
167
184
168
185
this . _cancelScheduler ( ) ;
169
- const targetElement = ( mouseEvent . event . browserEvent . relatedTarget ) as HTMLElement ;
170
186
171
- if ( this . _contentWidget ?. widget . isResizing || this . _contentWidget ?. containsNode ( targetElement ) ) {
172
- // When the content widget is resizing
173
- // When the mouse is inside hover widget
187
+ const shouldNotHideCurrentHoverWidget = this . _shouldNotHideCurrentHoverWidget ( mouseEvent ) ;
188
+ if ( shouldNotHideCurrentHoverWidget ) {
174
189
return ;
175
190
}
176
191
if ( _sticky ) {
@@ -179,21 +194,22 @@ export class HoverController extends Disposable implements IEditorContribution {
179
194
this . _hideWidgets ( ) ;
180
195
}
181
196
182
- private _isMouseOverHoverWidget ( mouseEvent : IEditorMouseEvent ) : boolean {
197
+ private _shouldNotRecomputeCurrentHoverWidget ( mouseEvent : IEditorMouseEvent ) : boolean {
183
198
184
- const sticky = this . _hoverSettings . sticky ;
199
+ const isHoverSticky = this . _hoverSettings . sticky ;
185
200
186
- const isMouseOnMarginHoverWidget = ( mouseEvent : IEditorMouseEvent , sticky : boolean ) => {
187
- const target = mouseEvent . target ;
188
- return sticky
189
- && target . type === MouseTargetType . OVERLAY_WIDGET
190
- && target . detail === MarginHoverWidget . ID ;
201
+ const isMouseOnStickyMarginHoverWidget = ( mouseEvent : IEditorMouseEvent , isHoverSticky : boolean ) => {
202
+ const isMouseOnMarginHoverWidget = this . _isMouseOnMarginHoverWidget ( mouseEvent ) ;
203
+ return isHoverSticky && isMouseOnMarginHoverWidget ;
191
204
}
192
- const isMouseOnContentHoverWidget = ( mouseEvent : IEditorMouseEvent , sticky : boolean ) => {
193
- const target = mouseEvent . target ;
194
- const isMouseOnContentHoverWidget = target . type === MouseTargetType . CONTENT_WIDGET && target . detail === ContentHoverWidget . ID ;
205
+ const isMouseOnStickyContentHoverWidget = ( mouseEvent : IEditorMouseEvent , isHoverSticky : boolean ) => {
206
+ const isMouseOnContentHoverWidget = this . _isMouseOnContentHoverWidget ( mouseEvent ) ;
207
+ return isHoverSticky && isMouseOnContentHoverWidget ;
208
+ }
209
+ const isMouseOnColorPicker = ( mouseEvent : IEditorMouseEvent ) => {
210
+ const isMouseOnContentHoverWidget = this . _isMouseOnContentHoverWidget ( mouseEvent ) ;
195
211
const isColorPickerVisible = this . _contentWidget ?. isColorPickerVisible ;
196
- return isMouseOnContentHoverWidget && ( sticky || isColorPickerVisible ) ;
212
+ return isMouseOnContentHoverWidget && isColorPickerVisible ;
197
213
}
198
214
// TODO@aiday -mar verify if the following is necessary code
199
215
const isTextSelectedWithinContentHoverWidget = ( mouseEvent : IEditorMouseEvent , sticky : boolean ) => {
@@ -203,9 +219,10 @@ export class HoverController extends Disposable implements IEditorContribution {
203
219
}
204
220
205
221
if (
206
- isMouseOnMarginHoverWidget ( mouseEvent , sticky )
207
- || isMouseOnContentHoverWidget ( mouseEvent , sticky )
208
- || isTextSelectedWithinContentHoverWidget ( mouseEvent , sticky )
222
+ isMouseOnStickyMarginHoverWidget ( mouseEvent , isHoverSticky )
223
+ || isMouseOnStickyContentHoverWidget ( mouseEvent , isHoverSticky )
224
+ || isMouseOnColorPicker ( mouseEvent )
225
+ || isTextSelectedWithinContentHoverWidget ( mouseEvent , isHoverSticky )
209
226
) {
210
227
return true ;
211
228
}
@@ -225,17 +242,19 @@ export class HoverController extends Disposable implements IEditorContribution {
225
242
return ;
226
243
}
227
244
228
- const mouseIsOverWidget = this . _isMouseOverHoverWidget ( mouseEvent ) ;
229
- // If the mouse is over the widget and the hiding timeout is defined, then cancel it
230
- if ( mouseIsOverWidget ) {
245
+ const shouldNotRecomputeCurrentHoverWidget = this . _shouldNotRecomputeCurrentHoverWidget ( mouseEvent ) ;
246
+ if ( shouldNotRecomputeCurrentHoverWidget ) {
231
247
this . _reactToEditorMouseMoveRunner . cancel ( ) ;
232
248
return ;
233
249
}
234
250
251
+ const hidingDelay = this . _hoverSettings . hidingDelay ;
252
+ const isContentHoverWidgetVisible = this . _contentWidget ?. isVisible ;
235
253
// If the mouse is not over the widget, and if sticky is on,
236
254
// then give it a grace period before reacting to the mouse event
237
- const hidingDelay = this . _hoverSettings . hidingDelay ;
238
- if ( this . _contentWidget ?. isVisible && sticky && hidingDelay > 0 ) {
255
+ const shouldRescheduleHoverComputation = isContentHoverWidgetVisible && sticky && hidingDelay > 0 ;
256
+
257
+ if ( shouldRescheduleHoverComputation ) {
239
258
if ( ! this . _reactToEditorMouseMoveRunner . isScheduled ( ) ) {
240
259
this . _reactToEditorMouseMoveRunner . schedule ( hidingDelay ) ;
241
260
}
@@ -386,6 +405,10 @@ export class HoverController extends Disposable implements IEditorContribution {
386
405
this . _getOrCreateContentWidget ( ) . startShowingAtRange ( range , mode , source , focus ) ;
387
406
}
388
407
408
+ private _isContentWidgetResizing ( ) : boolean {
409
+ return this . _contentWidget ?. widget . isResizing || false ;
410
+ }
411
+
389
412
public focus ( ) : void {
390
413
this . _contentWidget ?. focus ( ) ;
391
414
}
0 commit comments