Skip to content

Commit 12443ca

Browse files
authored
hover - reduce flicker when hover appears on element click (microsoft#202401)
* hover - reduce flicker when hover appears on element click * fix it
1 parent bc94d88 commit 12443ca

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/vs/base/browser/ui/iconLabel/iconLabelHover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface IHoverAction {
4747
export interface IUpdatableHoverOptions {
4848
actions?: IHoverAction[];
4949
linkHandler?(url: string): void;
50-
disableHideOnMouseDown?: boolean;
50+
disableHideOnClick?: boolean;
5151
}
5252

5353
export interface ICustomHover extends IDisposable {
@@ -195,7 +195,7 @@ export function setupCustomHover(hoverDelegate: IHoverDelegate, htmlElement: HTM
195195
let isMouseDown = false;
196196
const mouseDownEmitter = dom.addDisposableListener(htmlElement, dom.EventType.MOUSE_DOWN, () => {
197197
isMouseDown = true;
198-
if (!options?.disableHideOnMouseDown) {
198+
if (!options?.disableHideOnClick) {
199199
hideHover(true, true);
200200
}
201201
}, true);

src/vs/editor/browser/services/hoverService.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ export class HoverService implements IHoverService {
9797
}
9898
}));
9999
} else {
100-
if ('targetElements' in options.target) {
101-
for (const element of options.target.targetElements) {
102-
hoverDisposables.add(addDisposableListener(element, EventType.CLICK, () => this.hideHover()));
100+
if (!options.disableHideOnClick) {
101+
if ('targetElements' in options.target) {
102+
for (const element of options.target.targetElements) {
103+
hoverDisposables.add(addDisposableListener(element, EventType.CLICK, () => this.hideHover()));
104+
}
105+
} else {
106+
hoverDisposables.add(addDisposableListener(options.target, EventType.CLICK, () => this.hideHover()));
103107
}
104-
} else {
105-
hoverDisposables.add(addDisposableListener(options.target, EventType.CLICK, () => this.hideHover()));
106108
}
107109
const focusedElement = getActiveElement();
108110
if (focusedElement) {

src/vs/platform/hover/browser/hover.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ export interface IHoverOptions {
114114
* Options that define how the hover looks.
115115
*/
116116
appearance?: IHoverAppearanceOptions;
117+
118+
/**
119+
* Option to disable automated hiding of the hover when clicking its
120+
* target element. This should be set when clicking the target element
121+
* shows the hover to prevent flicker.
122+
*/
123+
disableHideOnClick?: boolean;
117124
}
118125

119126
export interface IHoverPositionOptions {

src/vs/workbench/browser/parts/statusbar/statusbarItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ export class StatusbarEntryItem extends Disposable {
119119
const hoverContents = isMarkdownString(entry.tooltip) ? { markdown: entry.tooltip, markdownNotSupportedFallback: undefined } : entry.tooltip;
120120
const entryOpensTooltip = entry.command === ShowTooltipCommand;
121121
if (this.hover) {
122-
this.hover.update(hoverContents, { disableHideOnMouseDown: entryOpensTooltip });
122+
this.hover.update(hoverContents, { disableHideOnClick: entryOpensTooltip });
123123
} else {
124-
this.hover = this._register(setupCustomHover(this.hoverDelegate, this.container, hoverContents, { disableHideOnMouseDown: entryOpensTooltip }));
124+
this.hover = this._register(setupCustomHover(this.hoverDelegate, this.container, hoverContents, { disableHideOnClick: entryOpensTooltip }));
125125
}
126126
this.focusListener.value = addDisposableListener(this.labelContainer, EventType.FOCUS, (e) => {
127127
EventHelper.stop(e);

0 commit comments

Comments
 (0)