From ab0958eaba28b487512f38a23b3fc774749c4c66 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 29 Apr 2020 06:39:33 -0700 Subject: [PATCH] Add hover delay to env var widget Fixes #96574 --- .../widgets/environmentVariableInfoWidget.ts | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts b/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts index abbca340b23..55f3f2b7970 100644 --- a/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts +++ b/src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts @@ -5,11 +5,14 @@ import { Widget } from 'vs/base/browser/ui/widget'; import { IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable'; -import { getDomNodePagePosition } from 'vs/base/browser/dom'; import { MarkdownString } from 'vs/base/common/htmlContent'; import { ITerminalWidget, IHoverTarget, IHoverAnchor, HorizontalAnchorSide, VerticalAnchorSide } from 'vs/workbench/contrib/terminal/browser/widgets/widgets'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { HoverWidget } from 'vs/workbench/contrib/terminal/browser/widgets/hoverWidget'; +import { RunOnceScheduler } from 'vs/base/common/async'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import * as dom from 'vs/base/browser/dom'; +import { IDisposable } from 'vs/base/common/lifecycle'; export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWidget { readonly id = 'env-var-info'; @@ -17,12 +20,14 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi private _domNode: HTMLElement | undefined; private _container: HTMLElement | undefined; private _hoverWidget: HoverWidget | undefined; + private _mouseMoveListener: IDisposable | undefined; get requiresAction() { return this._info.requiresAction; } constructor( private _info: IEnvironmentVariableInfo, - @IInstantiationService private readonly _instantiationService: IInstantiationService + @IInstantiationService private readonly _instantiationService: IInstantiationService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { super(); } @@ -32,12 +37,37 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi this._domNode = document.createElement('div'); this._domNode.classList.add('terminal-env-var-info', 'codicon', `codicon-${this._info.getIcon()}`); container.appendChild(this._domNode); - this.onmouseover(this._domNode, () => this._showHover()); + + + const timeout = this._configurationService.getValue('editor.hover.delay'); + const scheduler: RunOnceScheduler = new RunOnceScheduler(() => this._showHover(), timeout); + this._register(scheduler); + let origin = { x: 0, y: 0 }; + + this.onmouseover(this._domNode, e => { + origin.x = e.browserEvent.pageX; + origin.y = e.browserEvent.pageY; + scheduler.schedule(); + + this._mouseMoveListener = dom.addDisposableListener(this._domNode!, dom.EventType.MOUSE_MOVE, e => { + // Reset the scheduler if the mouse moves too much + if (Math.abs(e.pageX - origin.x) > window.devicePixelRatio * 2 || Math.abs(e.pageY - origin.y) > window.devicePixelRatio * 2) { + origin.x = e.pageX; + origin.y = e.pageY; + scheduler.schedule(); + } + }); + }); + this.onnonbubblingmouseout(this._domNode, () => { + scheduler.cancel(); + this._mouseMoveListener?.dispose(); + }); } dispose() { super.dispose(); this._domNode?.parentElement?.removeChild(this._domNode); + this._mouseMoveListener?.dispose(); } focus() { @@ -67,7 +97,7 @@ class ElementHoverTarget implements IHoverTarget { } get anchor(): IHoverAnchor { - const position = getDomNodePagePosition(this._element); + const position = dom.getDomNodePagePosition(this._element); return { x: position.left, horizontalAnchorSide: HorizontalAnchorSide.Left, -- GitLab