Skip to content

Commit 046cfbf

Browse files
authored
add custom hover for quick open (microsoft#191416)
* add custom hover for quick open * 💄 * 💄 * adjust delayer create logic
1 parent 20f0091 commit 046cfbf

File tree

4 files changed

+50
-49
lines changed

4 files changed

+50
-49
lines changed

src/vs/platform/quickinput/browser/quickInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface IQuickInputOptions {
4747
renderers: IListRenderer<T, any>[],
4848
options: IListOptions<T>,
4949
): List<T>;
50-
hoverDelegate: IHoverDelegate;
50+
hoverDelegate?: IHoverDelegate;
5151
styles: IQuickInputStyles;
5252
}
5353

src/vs/platform/quickinput/browser/quickInputController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ export class QuickInputController extends Disposable {
8383

8484
const titleBar = dom.append(container, $('.quick-input-titlebar'));
8585

86-
const leftActionBar = this._register(new ActionBar(titleBar));
86+
const actionBarOption = this.options.hoverDelegate ? { hoverDelegate: this.options.hoverDelegate } : undefined;
87+
const leftActionBar = this._register(new ActionBar(titleBar, actionBarOption));
8788
leftActionBar.domNode.classList.add('quick-input-left-action-bar');
8889

8990
const title = dom.append(titleBar, $('.quick-input-title'));
9091

91-
const rightActionBar = this._register(new ActionBar(titleBar));
92+
const rightActionBar = this._register(new ActionBar(titleBar, actionBarOption));
9293
rightActionBar.domNode.classList.add('quick-input-right-action-bar');
9394

9495
const headerContainer = dom.append(container, $('.quick-input-header'));

src/vs/platform/quickinput/browser/quickInputList.ts

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -541,46 +541,49 @@ export class QuickInputList {
541541
}
542542
}));
543543

544-
const delayer = new ThrottledDelayer(options.hoverDelegate.delay);
545-
// onMouseOver triggers every time a new element has been moused over
546-
// even if it's on the same list item.
547-
this.disposables.push(this.list.onMouseOver(async e => {
548-
// If we hover over an anchor element, we don't want to show the hover because
549-
// the anchor may have a tooltip that we want to show instead.
550-
if (e.browserEvent.target instanceof HTMLAnchorElement) {
551-
delayer.cancel();
552-
return;
553-
}
554-
if (
555-
// anchors are an exception as called out above so we skip them here
556-
!(e.browserEvent.relatedTarget instanceof HTMLAnchorElement) &&
557-
// check if the mouse is still over the same element
558-
dom.isAncestor(e.browserEvent.relatedTarget as Node, e.element?.element as Node)
559-
) {
560-
return;
561-
}
562-
try {
563-
await delayer.trigger(async () => {
564-
if (e.element) {
565-
this.showHover(e.element);
544+
if (options.hoverDelegate) {
545+
const delayer = new ThrottledDelayer(options.hoverDelegate.delay);
546+
// onMouseOver triggers every time a new element has been moused over
547+
// even if it's on the same list item.
548+
this.disposables.push(this.list.onMouseOver(async e => {
549+
// If we hover over an anchor element, we don't want to show the hover because
550+
// the anchor may have a tooltip that we want to show instead.
551+
if (e.browserEvent.target instanceof HTMLAnchorElement) {
552+
delayer.cancel();
553+
return;
554+
}
555+
if (
556+
// anchors are an exception as called out above so we skip them here
557+
!(e.browserEvent.relatedTarget instanceof HTMLAnchorElement) &&
558+
// check if the mouse is still over the same element
559+
dom.isAncestor(e.browserEvent.relatedTarget as Node, e.element?.element as Node)
560+
) {
561+
return;
562+
}
563+
try {
564+
await delayer.trigger(async () => {
565+
if (e.element) {
566+
this.showHover(e.element);
567+
}
568+
});
569+
} catch (e) {
570+
// Ignore cancellation errors due to mouse out
571+
if (!isCancellationError(e)) {
572+
throw e;
566573
}
567-
});
568-
} catch (e) {
569-
// Ignore cancellation errors due to mouse out
570-
if (!isCancellationError(e)) {
571-
throw e;
572574
}
573-
}
574-
}));
575-
this.disposables.push(this.list.onMouseOut(e => {
576-
// onMouseOut triggers every time a new element has been moused over
577-
// even if it's on the same list item. We only want one event, so we
578-
// check if the mouse is still over the same element.
579-
if (dom.isAncestor(e.browserEvent.relatedTarget as Node, e.element?.element as Node)) {
580-
return;
581-
}
582-
delayer.cancel();
583-
}));
575+
}));
576+
this.disposables.push(this.list.onMouseOut(e => {
577+
// onMouseOut triggers every time a new element has been moused over
578+
// even if it's on the same list item. We only want one event, so we
579+
// check if the mouse is still over the same element.
580+
if (dom.isAncestor(e.browserEvent.relatedTarget as Node, e.element?.element as Node)) {
581+
return;
582+
}
583+
delayer.cancel();
584+
}));
585+
this.disposables.push(delayer);
586+
}
584587
this.disposables.push(this._listElementChecked.event(_ => this.fireCheckedEvents()));
585588
this.disposables.push(
586589
this._onChangedAllVisibleChecked,
@@ -590,8 +593,7 @@ export class QuickInputList {
590593
this._onButtonTriggered,
591594
this._onSeparatorButtonTriggered,
592595
this._onLeave,
593-
this._onKeyDown,
594-
delayer
596+
this._onKeyDown
595597
);
596598
}
597599

@@ -839,10 +841,14 @@ export class QuickInputList {
839841
* @param element The element to show the hover for
840842
*/
841843
private showHover(element: IListElement): void {
844+
if (this.options.hoverDelegate === undefined) {
845+
return;
846+
}
842847
if (this._lastHover && !this._lastHover.isDisposed) {
843848
this.options.hoverDelegate.onDidHideHover?.();
844849
this._lastHover?.dispose();
845850
}
851+
846852
if (!element.element || !element.saneTooltip) {
847853
return;
848854
}

src/vs/platform/quickinput/browser/quickInputService.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ export class QuickInputService extends Themable implements IQuickInputService {
8686
renderers: IListRenderer<T, any>[],
8787
options: IWorkbenchListOptions<T>
8888
) => this.instantiationService.createInstance(WorkbenchList, user, container, delegate, renderers, options) as List<T>,
89-
hoverDelegate: {
90-
showHover(options, focus) {
91-
return undefined;
92-
},
93-
delay: 200
94-
},
9589
styles: this.computeStyles()
9690
};
9791

0 commit comments

Comments
 (0)