Skip to content

Commit 50c781b

Browse files
authored
Refactoring _isMouseOverHoverWidget (microsoft#210194)
refactoring `_isMouseOverHoverWidget`
1 parent 77e5711 commit 50c781b

File tree

1 file changed

+22
-29
lines changed
  • src/vs/editor/contrib/hover/browser

1 file changed

+22
-29
lines changed

src/vs/editor/contrib/hover/browser/hover.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -179,41 +179,34 @@ export class HoverController extends Disposable implements IEditorContribution {
179179
this._hideWidgets();
180180
}
181181

182-
private _isMouseOverWidget(mouseEvent: IEditorMouseEvent): boolean {
182+
private _isMouseOverHoverWidget(mouseEvent: IEditorMouseEvent): boolean {
183183

184-
const target = mouseEvent.target;
185184
const sticky = this._hoverSettings.sticky;
186-
if (
187-
sticky
188-
&& target.type === MouseTargetType.CONTENT_WIDGET
189-
&& target.detail === ContentHoverWidget.ID
190-
) {
191-
// mouse moved on top of content hover widget
192-
return true;
185+
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;
193191
}
194-
if (
195-
sticky
196-
&& this._contentWidget?.containsNode(mouseEvent.event.browserEvent.view?.document.activeElement)
197-
&& !mouseEvent.event.browserEvent.view?.getSelection()?.isCollapsed
198-
) {
199-
// selected text within content hover widget
200-
return true;
192+
const isMouseOnContentHoverWidget = (mouseEvent: IEditorMouseEvent, sticky: boolean) => {
193+
const target = mouseEvent.target;
194+
const isMouseOnContentHoverWidget = target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ContentHoverWidget.ID;
195+
const isColorPickerVisible = this._contentWidget?.isColorPickerVisible;
196+
return isMouseOnContentHoverWidget && (sticky || isColorPickerVisible);
201197
}
202-
if (
203-
!sticky
204-
&& target.type === MouseTargetType.CONTENT_WIDGET
205-
&& target.detail === ContentHoverWidget.ID
206-
&& this._contentWidget?.isColorPickerVisible
207-
) {
208-
// though the hover is not sticky, the color picker is sticky
209-
return true;
198+
// TODO@aiday-mar verify if the following is necessary code
199+
const isTextSelectedWithinContentHoverWidget = (mouseEvent: IEditorMouseEvent, sticky: boolean) => {
200+
return sticky
201+
&& this._contentWidget?.containsNode(mouseEvent.event.browserEvent.view?.document.activeElement)
202+
&& !mouseEvent.event.browserEvent.view?.getSelection()?.isCollapsed
210203
}
204+
211205
if (
212-
sticky
213-
&& target.type === MouseTargetType.OVERLAY_WIDGET
214-
&& target.detail === MarginHoverWidget.ID
206+
isMouseOnMarginHoverWidget(mouseEvent, sticky)
207+
|| isMouseOnContentHoverWidget(mouseEvent, sticky)
208+
|| isTextSelectedWithinContentHoverWidget(mouseEvent, sticky)
215209
) {
216-
// mouse moved on top of overlay hover widget
217210
return true;
218211
}
219212
return false;
@@ -232,7 +225,7 @@ export class HoverController extends Disposable implements IEditorContribution {
232225
return;
233226
}
234227

235-
const mouseIsOverWidget = this._isMouseOverWidget(mouseEvent);
228+
const mouseIsOverWidget = this._isMouseOverHoverWidget(mouseEvent);
236229
// If the mouse is over the widget and the hiding timeout is defined, then cancel it
237230
if (mouseIsOverWidget) {
238231
this._reactToEditorMouseMoveRunner.cancel();

0 commit comments

Comments
 (0)