Skip to content

Commit 54ce10d

Browse files
authored
move custom hover logic into BaseActionViewItem (microsoft#155278)
fixes microsoft#153429
1 parent 17213dc commit 54ce10d

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

src/vs/base/browser/ui/actionbar/actionViewItems.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IBaseActionViewItemOptions {
2323
draggable?: boolean;
2424
isMenu?: boolean;
2525
useEventAsContext?: boolean;
26+
hoverDelegate?: IHoverDelegate;
2627
}
2728

2829
export class BaseActionViewItem extends Disposable implements IActionViewItem {
@@ -32,6 +33,8 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem {
3233
_context: unknown;
3334
readonly _action: IAction;
3435

36+
private customHover?: ICustomHover;
37+
3538
get action() {
3639
return this._action;
3740
}
@@ -210,8 +213,27 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem {
210213
// implement in subclass
211214
}
212215

216+
protected getTooltip(): string | undefined {
217+
return this.getAction().tooltip;
218+
}
219+
213220
protected updateTooltip(): void {
214-
// implement in subclass
221+
if (!this.element) {
222+
return;
223+
}
224+
const title = this.getTooltip() ?? '';
225+
this.element.setAttribute('aria-label', title);
226+
if (!this.options.hoverDelegate) {
227+
this.element.title = title;
228+
} else {
229+
this.element.title = '';
230+
if (!this.customHover) {
231+
this.customHover = setupCustomHover(this.options.hoverDelegate, this.element, title);
232+
this._store.add(this.customHover);
233+
} else {
234+
this.customHover.update(title);
235+
}
236+
}
215237
}
216238

217239
protected updateClass(): void {
@@ -236,7 +258,6 @@ export interface IActionViewItemOptions extends IBaseActionViewItemOptions {
236258
icon?: boolean;
237259
label?: boolean;
238260
keybinding?: string | null;
239-
hoverDelegate?: IHoverDelegate;
240261
}
241262

242263
export class ActionViewItem extends BaseActionViewItem {
@@ -245,7 +266,6 @@ export class ActionViewItem extends BaseActionViewItem {
245266
protected override options: IActionViewItemOptions;
246267

247268
private cssClass?: string;
248-
private customHover?: ICustomHover;
249269

250270
constructor(context: unknown, action: IAction, options: IActionViewItemOptions = {}) {
251271
super(context, action, options);
@@ -317,7 +337,7 @@ export class ActionViewItem extends BaseActionViewItem {
317337
}
318338
}
319339

320-
override updateTooltip(): void {
340+
override getTooltip() {
321341
let title: string | null = null;
322342

323343
if (this.getAction().tooltip) {
@@ -330,24 +350,7 @@ export class ActionViewItem extends BaseActionViewItem {
330350
title = nls.localize({ key: 'titleLabel', comment: ['action title', 'action keybinding'] }, "{0} ({1})", title, this.options.keybinding);
331351
}
332352
}
333-
this._applyUpdateTooltip(title);
334-
}
335-
336-
protected _applyUpdateTooltip(title: string | undefined | null): void {
337-
if (title && this.label) {
338-
this.label.setAttribute('aria-label', title);
339-
if (!this.options.hoverDelegate) {
340-
this.label.title = title;
341-
} else {
342-
this.label.title = '';
343-
if (!this.customHover) {
344-
this.customHover = setupCustomHover(this.options.hoverDelegate, this.label, title);
345-
this._store.add(this.customHover);
346-
} else {
347-
this.customHover.update(title);
348-
}
349-
}
350-
}
353+
return title ?? undefined;
351354
}
352355

353356
override updateClass(): void {

src/vs/platform/actions/browser/menuEntryActionViewItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export class MenuEntryActionViewItem extends ActionViewItem {
231231
}
232232
}
233233

234-
override updateTooltip(): void {
234+
override getTooltip() {
235235
const keybinding = this._keybindingService.lookupKeybinding(this._commandAction.id, this._contextKeyService);
236236
const keybindingLabel = keybinding && keybinding.getLabel();
237237

@@ -249,7 +249,7 @@ export class MenuEntryActionViewItem extends ActionViewItem {
249249

250250
title = localize('titleAndKbAndAlt', "{0}\n[{1}] {2}", title, UILabelProvider.modifierLabels[OS].altKey, altTitleSection);
251251
}
252-
this._applyUpdateTooltip(title);
252+
return title;
253253
}
254254

255255
override updateClass(): void {

src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ export class CommandCenterControl {
6565
searchIcon.classList.add('search-icon');
6666

6767
this.workspaceTitle.classList.add('search-label');
68-
this._updateFromWindowTitle();
68+
this.updateTooltip();
6969
reset(this.label, searchIcon, this.workspaceTitle);
7070
// this._renderAllQuickPickItem(container);
7171

72-
this._store.add(windowTitle.onDidChange(this._updateFromWindowTitle, this));
72+
this._store.add(windowTitle.onDidChange(this.updateTooltip, this));
7373
}
7474

75-
private _updateFromWindowTitle() {
76-
75+
override getTooltip() {
7776
// label: just workspace name and optional decorations
7877
const { prefix, suffix } = windowTitle.getTitleDecorations();
7978
let label = windowTitle.workspaceName;
@@ -93,7 +92,8 @@ export class CommandCenterControl {
9392
const title = kb
9493
? localize('title', "Search {0} ({1}) \u2014 {2}", windowTitle.workspaceName, kb, windowTitle.value)
9594
: localize('title2', "Search {0} \u2014 {1}", windowTitle.workspaceName, windowTitle.value);
96-
this._applyUpdateTooltip(title);
95+
96+
return title;
9797
}
9898
}
9999
return instantiationService.createInstance(InputLikeViewItem, action, { hoverDelegate });

0 commit comments

Comments
 (0)