Skip to content

Commit a26e4fd

Browse files
committed
Use intersection observer to hide hovers
Fixes microsoft#106127
1 parent d9e2c45 commit a26e4fd

4 files changed

Lines changed: 13 additions & 20 deletions

File tree

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
838838
setTimeout(() => this.layout(this._timeoutDimension!), 0);
839839
}
840840
}
841-
if (!visible) {
842-
this._widgetManager.hideHovers();
843-
}
844841
}
845842

846843
public scrollDownLine(): void {

src/vs/workbench/contrib/terminal/browser/widgets/widgetManager.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
import { IDisposable } from 'vs/base/common/lifecycle';
77
import { ITerminalWidget } from 'vs/workbench/contrib/terminal/browser/widgets/widgets';
8-
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
98

109
export class TerminalWidgetManager implements IDisposable {
1110
private _container: HTMLElement | undefined;
1211
private _attached: Map<string, ITerminalWidget> = new Map();
1312

14-
constructor(@IHoverService private readonly _hoverService: IHoverService) {
13+
constructor() {
1514
}
1615

1716
attachToElement(terminalWrapper: HTMLElement) {
@@ -23,17 +22,12 @@ export class TerminalWidgetManager implements IDisposable {
2322
}
2423

2524
dispose(): void {
26-
this.hideHovers();
2725
if (this._container && this._container.parentElement) {
2826
this._container.parentElement.removeChild(this._container);
2927
this._container = undefined;
3028
}
3129
}
3230

33-
hideHovers(): void {
34-
this._hoverService.hideHover();
35-
}
36-
3731
attachWidget(widget: ITerminalWidget): IDisposable | undefined {
3832
if (!this._container) {
3933
return;

src/vs/workbench/services/hover/browser/hover.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export interface IHoverService {
3030
* ```
3131
*/
3232
showHover(options: IHoverOptions, focus?: boolean): void;
33-
34-
/**
35-
* Hides the hover if it was visible.
36-
*/
37-
hideHover(): void;
3833
}
3934

4035
export interface IHoverOptions {

src/vs/workbench/services/hover/browser/hoverService.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
1212
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1313
import { HoverWidget } from 'vs/workbench/services/hover/browser/hoverWidget';
1414
import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview';
15+
import { IDisposable } from 'vs/base/common/lifecycle';
1516

1617
export class HoverService implements IHoverService {
1718
declare readonly _serviceBrand: undefined;
@@ -35,14 +36,20 @@ export class HoverService implements IHoverService {
3536
const provider = this._contextViewService as IContextViewProvider;
3637
provider.showContextView(new HoverContextViewDelegate(hover, focus));
3738
hover.onRequestLayout(() => provider.layout());
39+
40+
if ('IntersectionObserver' in window) {
41+
const observer = new IntersectionObserver(e => this._intersectionChange(e, hover), { threshold: 0 });
42+
const firstTargetElement = 'targetElements' in options.target ? options.target.targetElements[0] : options.target;
43+
observer.observe(firstTargetElement);
44+
hover.onDispose(() => observer.disconnect());
45+
}
3846
}
3947

40-
hideHover(): void {
41-
if (!this._currentHoverOptions) {
42-
return;
48+
private _intersectionChange(entries: IntersectionObserverEntry[], hover: IDisposable): void {
49+
const entry = entries[entries.length - 1];
50+
if (!entry.isIntersecting) {
51+
hover.dispose();
4352
}
44-
this._currentHoverOptions = undefined;
45-
this._contextViewService.hideContextView();
4653
}
4754
}
4855

0 commit comments

Comments
 (0)