Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hover - reduce flicker when hover appears on element click #202401

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vs/base/browser/ui/iconLabel/iconLabelHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface IHoverAction {
export interface IUpdatableHoverOptions {
actions?: IHoverAction[];
linkHandler?(url: string): void;
disableHideOnMouseDown?: boolean;
disableHideOnClick?: boolean;
}

export interface ICustomHover extends IDisposable {
Expand Down Expand Up @@ -195,7 +195,7 @@ export function setupCustomHover(hoverDelegate: IHoverDelegate, htmlElement: HTM
let isMouseDown = false;
const mouseDownEmitter = dom.addDisposableListener(htmlElement, dom.EventType.MOUSE_DOWN, () => {
isMouseDown = true;
if (!options?.disableHideOnMouseDown) {
if (!options?.disableHideOnClick) {
hideHover(true, true);
}
}, true);
Expand Down
12 changes: 7 additions & 5 deletions src/vs/editor/browser/services/hoverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ export class HoverService implements IHoverService {
}
}));
} else {
if ('targetElements' in options.target) {
for (const element of options.target.targetElements) {
hoverDisposables.add(addDisposableListener(element, EventType.CLICK, () => this.hideHover()));
if (!options.disableHideOnClick) {
if ('targetElements' in options.target) {
for (const element of options.target.targetElements) {
hoverDisposables.add(addDisposableListener(element, EventType.CLICK, () => this.hideHover()));
}
} else {
hoverDisposables.add(addDisposableListener(options.target, EventType.CLICK, () => this.hideHover()));
}
} else {
hoverDisposables.add(addDisposableListener(options.target, EventType.CLICK, () => this.hideHover()));
}
const focusedElement = getActiveElement();
if (focusedElement) {
Expand Down
7 changes: 7 additions & 0 deletions src/vs/platform/hover/browser/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export interface IHoverOptions {
* Options that define how the hover looks.
*/
appearance?: IHoverAppearanceOptions;

/**
* Option to disable automated hiding of the hover when clicking its
* target element. This should be set when clicking the target element
* shows the hover to prevent flicker.
*/
disableHideOnClick?: boolean;
}

export interface IHoverPositionOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/statusbar/statusbarItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export class StatusbarEntryItem extends Disposable {
const hoverContents = isMarkdownString(entry.tooltip) ? { markdown: entry.tooltip, markdownNotSupportedFallback: undefined } : entry.tooltip;
const entryOpensTooltip = entry.command === ShowTooltipCommand;
if (this.hover) {
this.hover.update(hoverContents, { disableHideOnMouseDown: entryOpensTooltip });
this.hover.update(hoverContents, { disableHideOnClick: entryOpensTooltip });
} else {
this.hover = this._register(setupCustomHover(this.hoverDelegate, this.container, hoverContents, { disableHideOnMouseDown: entryOpensTooltip }));
this.hover = this._register(setupCustomHover(this.hoverDelegate, this.container, hoverContents, { disableHideOnClick: entryOpensTooltip }));
}
this.focusListener.value = addDisposableListener(this.labelContainer, EventType.FOCUS, (e) => {
EventHelper.stop(e);
Expand Down