8000 use better message in help dialog for unassigned kb in help dialog, p… · githubnext/vscode@47e6c3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 47e6c3a

Browse files
authored
use better message in help dialog for unassigned kb in help dialog, provide configure assigned kb command, clean up code (microsoft#221728)
1 parent 0cba3e6 commit 47e6c3a

File tree

5 files changed

+121
-58
lines changed

5 files changed

+121
-58
lines changed

src/vs/platform/accessibility/browser/accessibleView.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export interface IAccessibleViewOptions {
6969
* Keybinding items to configure
7070
*/
7171
configureKeybindingItems?: IQuickPickItem[];
72+
73+
/**
74+
* Keybinding items that are already configured
75+
*/
76+
configuredKeybindingItems?: IQuickPickItem[];
7277
}
7378

7479

@@ -123,7 +128,7 @@ export interface IAccessibleViewService {
123128
*/
124129
getOpenAriaHint(verbositySettingKey: string): string | null;
125130
getCodeBlockContext(): ICodeBlockActionContext | undefined;
126-
configureKeybindings(): void;
131+
configureKeybindings(unassigned: boolean): void;
127132
openHelpLink(): void;
128133
}
129134

src/vs/workbench/contrib/accessibility/browser/accessibleView.ts

Lines changed: 87 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ export class AccessibleView extends Disposable {
334334
this._instantiationService.createInstance(AccessibleViewSymbolQuickPick, this).show(this._currentProvider);
335335
}
336336

337-
calculateCodeBlocks(markdown: string): void {
337+
calculateCodeBlocks(markdown?: string): void {
338+
if (!markdown) {
339+
return;
340+
}
338341
if (this._currentProvider?.id !== AccessibleViewProviderId.Chat) {
339342
return;
340343
}
@@ -391,10 +394,10 @@ export class AccessibleView extends Disposable {
391394
this._openerService.open(URI.parse(this._currentProvider.options.readMoreUrl));
392395
}
393396

394-
configureKeybindings(): void {
397+
configureKeybindings(unassigned: boolean): void {
395398
this._inQuickPick = true;
396399
const provider = this._updateLastProvider();
397-
const items = provider?.options?.configureKeybindingItems;
400+
const items = unassigned ? provider?.options?.configureKeybindingItems : provider?.options?.configuredKeybindingItems;
398401
if (!items) {
399402
return;
400403
}
@@ -496,45 +499,39 @@ export class AccessibleView extends Disposable {
496499
this._accessibleViewGoToSymbolSupported.set(this._goToSymbolsSupported() ? this.getSymbols()?.length! > 0 : false);
497500
}
498501

499-
private _render(provider: AccesibleViewContentProvider, container: HTMLElement, showAccessibleViewHelp?: boolean, updatedContent?: string): IDisposable {
500-
this._currentProvider = provider;
501-
this._accessibleViewCurrentProviderId.set(provider.id);
502-
const verbose = this._verbosityEnabled();
503-
const readMoreLink = provider.options.readMoreUrl ? localize("openDoc", "\n\nOpen a browser window with more information related to accessibility<keybinding:{0}>.", AccessibilityCommandId.AccessibilityHelpOpenHelpLink) : '';
504-
let disableHelpHint = '';
505-
if (provider instanceof AccessibleContentProvider && provider.options.type === AccessibleViewType.Help && verbose) {
506-
disableHelpHint = this._getDisableVerbosityHint();
502+
private _updateContent(provider: AccesibleViewContentProvider, updatedContent?: string): void {
503+
let content = updatedContent ?? provider.provideContent();
504+
if (provider.options.type === AccessibleViewType.View) {
505+
this._currentContent = content;
506+
return;
507507
}
508-
const accessibilitySupport = this._accessibilityService.isScreenReaderOptimized();
509-
let message = '';
510-
if (provider.options.type === AccessibleViewType.Help) {
511-
const turnOnMessage = (
512-
isMacintosh
513-
? AccessibilityHelpNLS.changeConfigToOnMac
514-
: AccessibilityHelpNLS.changeConfigToOnWinLinux
515-
);
516-
if (accessibilitySupport && provider instanceof AccessibleContentProvider && provider.verbositySettingKey === AccessibilityVerbositySettingId.Editor) {
517-
message = AccessibilityHelpNLS.auto_on;
518-
message += '\n';
519-
} else if (!accessibilitySupport) {
520-
message = AccessibilityHelpNLS.auto_off + '\n' + turnOnMessage;
521-
message += '\n';
508+
const readMoreLinkHint = this._readMoreHint(provider);
509+
const disableHelpHint = this._disableVerbosityHint(provider);
510+
const screenReaderModeHint = this._screenReaderModeHint(provider);
511+
const exitThisDialogHint = this._exitDialogHint(provider);
512+
let configureKbHint = '';
513+
let configureAssignedKbHint = '';
514+
const resolvedContent = resolveContentAndKeybindingItems(this._keybindingService, screenReaderModeHint + content + readMoreLinkHint + disableHelpHint + exitThisDialogHint);
515+
if (resolvedContent) {
516+
content = resolvedContent.content.value;
517+
if (resolvedContent.configureKeybindingItems) {
518+
provider.options.configureKeybindingItems = resolvedContent.configureKeybindingItems;
519+
configureKbHint = this._configureUnassignedKbHint();
522520
}
523-
}
524-
const exitThisDialogHint = verbose && !provider.options.position ? localize('exit', '\n\nExit this dialog (Escape).') : '';
525-
let content = updatedContent ?? provider.provideContent();
526-
if (provider.options.type === AccessibleViewType.Help) {
527-
const resolvedContent = resolveContentAndKeybindingItems(this._keybindingService, content + readMoreLink + disableHelpHint + exitThisDialogHint);
528-
if (resolvedContent) {
529-
content = resolvedContent.content.value;
530-
if (resolvedContent.configureKeybindingItems) {
531-
provider.options.configureKeybindingItems = resolvedContent.configureKeybindingItems;
532-
}
521+
if (resolvedContent.configuredKeybindingItems) {
522+
provider.options.configuredKeybindingItems = resolvedContent.configuredKeybindingItems;
523+
configureAssignedKbHint = this._configureAssignedKbHint();
533524
}
534525
}
535-
const newContent = message + content;
536-
this.calculateCodeBlocks(newContent);
537-
this._currentContent = newContent;
526+
this._currentContent = content + configureKbHint + configureAssignedKbHint;
527+
}
528+
529+
private _render(provider: AccesibleViewContentProvider, container: HTMLElement, showAccessibleViewHelp?: boolean, updatedContent?: string): IDisposable {
530+
this._currentProvider = provider;
531+
this._accessibleViewCurrentProviderId.set(provider.id);
532+
const verbose = this._verbosityEnabled();
533+
this._updateContent(provider, updatedContent);
534+
this.calculateCodeBlocks(this._currentContent);
538535
this._updateContextKeys(provider, true);
539536
const widgetIsFocused = this._editorWidget.hasTextFocus() || this._editorWidget.hasWidgetFocus();
540537
this._getTextModel(URI.from({ path: `accessible-view-${provider.id}`, scheme: 'accessible-view', fragment: this._currentContent })).then((model) => {
@@ -708,7 +705,7 @@ export class AccessibleView extends Disposable {
708705
accessibleViewHelpProvider = new AccessibleContentProvider(
709706
lastProvider.id as AccessibleViewProviderId,
710707
{ type: AccessibleViewType.Help },
711-
() => lastProvider.options.customHelp ? lastProvider?.options.customHelp() : this._getAccessibleViewHelpDialogContent(this._goToSymbolsSupported()),
708+
() => lastProvider.options.customHelp ? lastProvider?.options.customHelp() : this._accessibleViewHelpDialogContent(this._goToSymbolsSupported()),
712709
() => {
713710
this._contextViewService.hideContextView();
714711
// HACK: Delay to allow the context view to hide #207638
@@ -720,7 +717,7 @@ export class AccessibleView extends Disposable {
720717
accessibleViewHelpProvider = new ExtensionContentProvider(
721718
lastProvider.id as AccessibleViewProviderId,
722719
{ type: AccessibleViewType.Help },
723-
() => lastProvider.options.customHelp ? lastProvider?.options.customHelp() : this._getAccessibleViewHelpDialogContent(this._goToSymbolsSupported()),
720+
() => lastProvider.options.customHelp ? lastProvider?.options.customHelp() : this._accessibleViewHelpDialogContent(this._goToSymbolsSupported()),
724721
() => {
725722
this._contextViewService.hideContextView();
726723
// HACK: Delay to allow the context view to hide #207638
@@ -735,9 +732,9 @@ export class AccessibleView extends Disposable {
735732
}
736733
}
737734

738-
private _getAccessibleViewHelpDialogContent(providerHasSymbols?: boolean): string {
739-
const navigationHint = this._getNavigationHint();
740-
const goToSymbolHint = this._getGoToSymbolHint(providerHasSymbols);
735+
private _accessibleViewHelpDialogContent(providerHasSymbols?: boolean): string {
736+
const navigationHint = this._navigationHint();
737+
const goToSymbolHint = this._goToSymbolHint(providerHasSymbols);
741738
const toolbarHint = localize('toolbar', "Navigate to the toolbar (Shift+Tab).");
742739
const chatHints = this._getChatHints();
743740

@@ -766,20 +763,61 @@ export class AccessibleView extends Disposable {
766763
localize('runInTerminal', " - Run the code block in the terminal<keybinding:'workbench.action.chat.runInTerminal>.\n")].join('\n');
767764
}
768765

769-
private _getNavigationHint(): string {
766+
private _navigationHint(): string {
770767
return localize('accessibleViewNextPreviousHint', "Show the next item<keybinding:{0}> or previous item<keybinding:{1}>.", AccessibilityCommandId.ShowNext, AccessibilityCommandId.ShowPrevious);
771768
}
772769

773-
private _getDisableVerbosityHint(): string {
774-
return localize('acessibleViewDisableHint', "\n\nDisable accessibility verbosity for this feature<keybinding:{0}>.", AccessibilityCommandId.DisableVerbosityHint);
770+
private _disableVerbosityHint(provider: AccesibleViewContentProvider): string {
771+
if (provider.options.type === AccessibleViewType.Help && this._verbosityEnabled()) {
772+
return localize('acessibleViewDisableHint', "\n\nDisable accessibility verbosity for this feature<keybinding:{0}>.", AccessibilityCommandId.DisableVerbosityHint);
773+
}
774+
return '';
775775
}
776776

777-
private _getGoToSymbolHint(providerHasSymbols?: boolean): string | undefined {
777+
private _goToSymbolHint(providerHasSymbols?: boolean): string | undefined {
778778
if (!providerHasSymbols) {
779779
return;
780780
}
781781
return localize('goToSymbolHint', 'Go to a symbol<keybinding:{0}>.', AccessibilityCommandId.GoToSymbol);
782782
}
783+
784+
private _configureUnassignedKbHint(): string {
785+
const configureKb = this._keybindingService.lookupKeybinding(AccessibilityCommandId.AccessibilityHelpConfigureKeybindings)?.getAriaLabel();
786+
const keybindingToConfigureQuickPick = configureKb ? '(' + configureKb + ')' : 'by assigning a keybinding to the command Accessibility Help Configure Keybindings.';
787+
return localize('configureKb', '\n\nConfigure keybindings for commands that lack them {0}.', keybindingToConfigureQuickPick);
788+
}
789+
790+
private _configureAssignedKbHint(): string {
791+
const configureKb = this._keybindingService.lookupKeybinding(AccessibilityCommandId.AccessibilityHelpConfigureAssignedKeybindings)?.getAriaLabel();
792+
const keybindingToConfigureQuickPick = configureKb ? '(' + configureKb + ')' : 'by assigning a keybinding to the command Accessibility Help Configure Assigned Keybindings.';
793+
return localize('configureKbAssigned', '\n\nConfigure keybindings for commands that already have assignments {0}.', keybindingToConfigureQuickPick);
794+
}
795+
796+
private _screenReaderModeHint(provider: AccesibleViewContentProvider): string {
797+
const accessibilitySupport = this._accessibilityService.isScreenReaderOptimized();
798+
let screenReaderModeHint = '';
799+
const turnOnMessage = (
800+
isMacintosh
801+
? AccessibilityHelpNLS.changeConfigToOnMac
802+
: AccessibilityHelpNLS.changeConfigToOnWinLinux
803+
);
804+
if (accessibilitySupport && provider.id === AccessibleViewProviderId.Editor) {
805+
screenReaderModeHint = AccessibilityHelpNLS.auto_on;
806+
screenReaderModeHint += '\n';
807+
} else if (!accessibilitySupport) {
808+
screenReaderModeHint = AccessibilityHelpNLS.auto_off + '\n' + turnOnMessage;
809+
screenReaderModeHint += '\n';
810+
}
811+
return screenReaderModeHint;
812+
}
813+
814+
private _exitDialogHint(provider: AccesibleViewContentProvider): string {
815+
return this._verbosityEnabled() && !provider.options.position ? localize('exit', '\n\nExit this dialog (Escape).') : '';
816+
}
817+
818+
private _readMoreHint(provider: AccesibleViewContentProvider): string {
819+
return provider.options.readMoreUrl ? localize("openDoc", "\n\nOpen a browser window with more information related to accessibility<keybinding:{0}>.", AccessibilityCommandId.AccessibilityHelpOpenHelpLink) : '';
820+
}
783821
}
784822

785823
export class AccessibleViewService extends Disposable implements IAccessibleViewService {
@@ -800,8 +838,8 @@ export class AccessibleViewService extends Disposable implements IAccessibleView
800838
}
801839
this._accessibleView.show(provider, undefined, undefined, position);
802840
}
803-
configureKeybindings(): void {
804-
this._accessibleView?.configureKeybindings();
841+
configureKeybindings(unassigned: boolean): void {
842+
this._accessibleView?.configureKeybindings(unassigned);
805843
}
806844
openHelpLink(): void {
807845
this._accessibleView?.openHelpLink();

src/vs/workbench/contrib/accessibility/browser/accessibleViewActions.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class AccessibleViewNextCodeBlockAction extends Action2 {
6262
mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.PageDown, },
6363
weight: KeybindingWeight.WorkbenchContrib,
6464
},
65-
// to
6665
icon: Codicon.arrowRight,
6766
menu:
6867
{
@@ -242,11 +241,29 @@ class AccessibilityHelpConfigureKeybindingsAction extends Action2 {
242241
});
243242
}
244243
async run(accessor: ServicesAccessor): Promise<void> {
245-
await accessor.get(IAccessibleViewService).configureKeybindings();
244+
await accessor.get(IAccessibleViewService).configureKeybindings(true);
246245
}
247246
}
248247
registerAction2(AccessibilityHelpConfigureKeybindingsAction);
249248

249+
class AccessibilityHelpConfigureAssignedKeybindingsAction extends Action2 {
250+
constructor() {
251+
super({
252+
id: AccessibilityCommandId.AccessibilityHelpConfigureAssignedKeybindings,
253+
precondition: ContextKeyExpr.and(accessibilityHelpIsShown),
254+
keybinding: {
255+
primary: KeyMod.Alt | KeyCode.KeyA,
256+
weight: KeybindingWeight.WorkbenchContrib
257+
},
258+
title: localize('editor.action.accessibilityHelpConfigureAssignedKeybindings', "Accessibility Help Configure Assigned Keybindings")
259+
});
260+
}
261+
async run(accessor: ServicesAccessor): Promise<void> {
262+
await accessor.get(IAccessibleViewService).configureKeybindings(false);
263+
}
264+
}
265+
registerAction2(AccessibilityHelpConfigureAssignedKeybindingsAction);
266+
250267

251268
class AccessibilityHelpOpenHelpLinkAction extends Action2 {
252269
constructor() {

src/vs/workbench/contrib/accessibility/browser/accessibleViewKeybindingResolver.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,37 @@
66
import { MarkdownString } from 'vs/base/common/htmlContent';
77
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
88
import { IPickerQuickAccessItem } from 'vs/platform/quickinput/browser/pickerQuickAccess';
9-
import { AccessibilityCommandId } from 'vs/workbench/contrib/accessibility/common/accessibilityCommands';
109

11-
export function resolveContentAndKeybindingItems(keybindingService: IKeybindingService, value?: string): { content: MarkdownString; configureKeybindingItems: IPickerQuickAccessItem[] | undefined } | undefined {
10+
export function resolveContentAndKeybindingItems(keybindingService: IKeybindingService, value?: string): { content: MarkdownString; configureKeybindingItems: IPickerQuickAccessItem[] | undefined; configuredKeybindingItems: IPickerQuickAccessItem[] | undefined } | undefined {
1211
if (!value) {
1312
return;
1413
}
1514
const configureKeybindingItems: IPickerQuickAccessItem[] = [];
15+
const configuredKeybindingItems: IPickerQuickAccessItem[] = [];
1616
const matches = value.matchAll(/\<keybinding:(?<commandId>.*)\>/gm);
1717
for (const match of [...matches]) {
1818
const commandId = match?.groups?.commandId;
1919
let kbLabel;
2020
if (match?.length && commandId) {
2121
const keybinding = keybindingService.lookupKeybinding(commandId)?.getAriaLabel();
2222
if (!keybinding) {
23-
const configureKb = keybindingService.lookupKeybinding(AccessibilityCommandId.AccessibilityHelpConfigureKeybindings)?.getAriaLabel();
24-
const keybindingToConfigureQuickPick = configureKb ? '(' + configureKb + ')' : 'by assigning a keybinding to the command Accessibility Help Configure Keybindings.';
25-
kbLabel = `, configure a keybinding ` + keybindingToConfigureQuickPick;
23+
kbLabel = ` (unassigned keybinding)`;
2624
configureKeybindingItems.push({
2725
label: commandId,
2826
id: commandId
2927
});
3028
} else {
3129
kbLabel = ' (' + keybinding + ')';
30+
configuredKeybindingItems.push({
31+
label: commandId,
32+
id: commandId
33+
});
3234
}
3335
value = value.replace(match[0], kbLabel);
3436
}
3537
}
3638
const content = new MarkdownString(value);
3739
content.isTrusted = true;
38-
return { content, configureKeybindingItems: configureKeybindingItems.length ? configureKeybindingItems : undefined };
40+
return { content, configureKeybindingItems: configureKeybindingItems.length ? configureKeybindingItems : undefined, configuredKeybindingItems: configuredKeybindingItems.length ? configuredKeybindingItems : undefined };
3941
}
4042

src/vs/workbench/contrib/accessibility/common/accessibilityCommands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export const enum AccessibilityCommandId {
1414
NextCodeBlock = 'editor.action.accessibleViewNextCodeBlock',
1515
PreviousCodeBlock = 'editor.action.accessibleViewPreviousCodeBlock',
1616
AccessibilityHelpConfigureKeybindings = 'editor.action.accessibilityHelpConfigureKeybindings',
17+
AccessibilityHelpConfigureAssignedKeybindings = 'editor.action.accessibilityHelpConfigureAssignedKeybindings',
1718
AccessibilityHelpOpenHelpLink = 'editor.action.accessibilityHelpOpenHelpLink',
1819
}

0 commit comments

Comments
 (0)
0