提交 ab0958ea 编写于 作者: D Daniel Imms

Add hover delay to env var widget

Fixes #96574
上级 232ff6c4
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
import { Widget } from 'vs/base/browser/ui/widget'; import { Widget } from 'vs/base/browser/ui/widget';
import { IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable';
import { getDomNodePagePosition } from 'vs/base/browser/dom';
import { MarkdownString } from 'vs/base/common/htmlContent'; import { MarkdownString } from 'vs/base/common/htmlContent';
import { ITerminalWidget, IHoverTarget, IHoverAnchor, HorizontalAnchorSide, VerticalAnchorSide } from 'vs/workbench/contrib/terminal/browser/widgets/widgets'; import { ITerminalWidget, IHoverTarget, IHoverAnchor, HorizontalAnchorSide, VerticalAnchorSide } from 'vs/workbench/contrib/terminal/browser/widgets/widgets';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { HoverWidget } from 'vs/workbench/contrib/terminal/browser/widgets/hoverWidget'; 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 { export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWidget {
readonly id = 'env-var-info'; readonly id = 'env-var-info';
...@@ -17,12 +20,14 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi ...@@ -17,12 +20,14 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi
private _domNode: HTMLElement | undefined; private _domNode: HTMLElement | undefined;
private _container: HTMLElement | undefined; private _container: HTMLElement | undefined;
private _hoverWidget: HoverWidget | undefined; private _hoverWidget: HoverWidget | undefined;
private _mouseMoveListener: IDisposable | undefined;
get requiresAction() { return this._info.requiresAction; } get requiresAction() { return this._info.requiresAction; }
constructor( constructor(
private _info: IEnvironmentVariableInfo, private _info: IEnvironmentVariableInfo,
@IInstantiationService private readonly _instantiationService: IInstantiationService @IInstantiationService private readonly _instantiationService: IInstantiationService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) { ) {
super(); super();
} }
...@@ -32,12 +37,37 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi ...@@ -32,12 +37,37 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi
this._domNode = document.createElement('div'); this._domNode = document.createElement('div');
this._domNode.classList.add('terminal-env-var-info', 'codicon', `codicon-${this._info.getIcon()}`); this._domNode.classList.add('terminal-env-var-info', 'codicon', `codicon-${this._info.getIcon()}`);
container.appendChild(this._domNode); container.appendChild(this._domNode);
this.onmouseover(this._domNode, () => this._showHover());
const timeout = this._configurationService.getValue<number>('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() { dispose() {
super.dispose(); super.dispose();
this._domNode?.parentElement?.removeChild(this._domNode); this._domNode?.parentElement?.removeChild(this._domNode);
this._mouseMoveListener?.dispose();
} }
focus() { focus() {
...@@ -67,7 +97,7 @@ class ElementHoverTarget implements IHoverTarget { ...@@ -67,7 +97,7 @@ class ElementHoverTarget implements IHoverTarget {
} }
get anchor(): IHoverAnchor { get anchor(): IHoverAnchor {
const position = getDomNodePagePosition(this._element); const position = dom.getDomNodePagePosition(this._element);
return { return {
x: position.left, x: position.left,
horizontalAnchorSide: HorizontalAnchorSide.Left, horizontalAnchorSide: HorizontalAnchorSide.Left,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册