Skip to content

Commit 44623fa

Browse files
authored
Add action label and keybindings for the editor hover status bar in the editor hover accessible view/help (microsoft#218269)
adding label and keybindings into the editor hover accessibility view and help
1 parent 0354163 commit 44623fa

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/vs/base/browser/ui/hover/hoverWidget.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ export class HoverAction extends Disposable {
5050
return new HoverAction(parent, actionOptions, keybindingLabel);
5151
}
5252

53+
public readonly actionLabel: string;
54+
public readonly actionKeybindingLabel: string | null;
55+
5356
private readonly actionContainer: HTMLElement;
5457
private readonly action: HTMLElement;
5558

5659
private constructor(parent: HTMLElement, actionOptions: { label: string; iconClass?: string; run: (target: HTMLElement) => void; commandId: string }, keybindingLabel: string | null) {
5760
super();
5861

62+
this.actionLabel = actionOptions.label;
63+
this.actionKeybindingLabel = keybindingLabel;
64+
5965
this.actionContainer = dom.append(parent, $('div.action-container'));
6066
this.actionContainer.setAttribute('tabindex', '0');
6167

src/vs/editor/contrib/hover/browser/contentHoverRendered.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ColorHoverParticipant } from 'vs/editor/contrib/colorPicker/browser/col
2121
import { localize } from 'vs/nls';
2222
import { InlayHintsHover } from 'vs/editor/contrib/inlayHints/browser/inlayHintsHover';
2323
import { BugIndicatingError } from 'vs/base/common/errors';
24+
import { HoverAction } from 'vs/base/browser/ui/hover/hoverWidget';
2425

2526
export class RenderedContentHover extends Disposable {
2627

@@ -175,6 +176,10 @@ interface IRenderedContentStatusBar {
175176
* The HTML element containing the hover status bar.
176177
*/
177178
hoverElement: HTMLElement;
179+
/**
180+
* The actions of the hover status bar.
181+
*/
182+
actions: HoverAction[];
178183
}
179184

180185
type IRenderedContentHoverPartOrStatusBar = IRenderedContentHoverPart | IRenderedContentStatusBar;
@@ -189,6 +194,10 @@ class RenderedStatusBar implements IDisposable {
189194
return this._statusBar.hoverElement;
190195
}
191196

197+
get actions(): HoverAction[] {
198+
return this._statusBar.actions;
199+
}
200+
192201
dispose() {
193202
this._statusBar.dispose();
194203
}
@@ -270,6 +279,7 @@ class RenderedContentHoverParts extends Disposable {
270279
this._renderedParts.push({
271280
type: 'statusBar',
272281
hoverElement: renderedStatusBar.hoverElement,
282+
actions: renderedStatusBar.actions,
273283
});
274284
}
275285
return toDisposable(() => { disposables.dispose(); });
@@ -332,7 +342,16 @@ class RenderedContentHoverParts extends Disposable {
332342
return '';
333343
}
334344
if (renderedPart.type === 'statusBar') {
335-
return localize('hoverAccessibilityStatusBar', "This is a hover status bar.");
345+
const statusBarDescription = [localize('hoverAccessibilityStatusBar', "This is a hover status bar.")];
346+
for (const action of renderedPart.actions) {
347+
const keybinding = action.actionKeybindingLabel;
348+
if (keybinding) {
349+
statusBarDescription.push(localize('hoverAccessibilityStatusBarActionWithKeybinding', "It has an action with label {0} and keybinding {1}.", action.actionLabel, keybinding));
350+
} else {
351+
statusBarDescription.push(localize('hoverAccessibilityStatusBarActionWithoutKeybinding', "It has an action with label {0}.", action.actionLabel));
352+
}
353+
}
354+
return statusBarDescription.join('\n');
336355
}
337356
return renderedPart.participant.getAccessibleContent(renderedPart.hoverPart);
338357
}

src/vs/editor/contrib/hover/browser/contentHoverStatusBar.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const $ = dom.$;
1313
export class EditorHoverStatusBar extends Disposable implements IEditorHoverStatusBar {
1414

1515
public readonly hoverElement: HTMLElement;
16+
public readonly actions: HoverAction[] = [];
17+
1618
private readonly actionsElement: HTMLElement;
1719
private _hasContent: boolean = false;
1820

@@ -39,7 +41,9 @@ export class EditorHoverStatusBar extends Disposable implements IEditorHoverStat
3941
const keybinding = this._keybindingService.lookupKeybinding(actionOptions.commandId);
4042
const keybindingLabel = keybinding ? keybinding.getLabel() : null;
4143
this._hasContent = true;
42-
return this._register(HoverAction.render(this.actionsElement, actionOptions, keybindingLabel));
44+
const action = this._register(HoverAction.render(this.actionsElement, actionOptions, keybindingLabel));
45+
this.actions.push(action);
46+
return action;
4347
}
4448

4549
public append(element: HTMLElement): HTMLElement {

0 commit comments

Comments
 (0)