Skip to content

Commit

Permalink
Use resolveContentAndKeybindingItems for diff editor, accessible vi…
Browse files Browse the repository at this point in the history
…ew, and terminal (#213179)
  • Loading branch information
meganrogge authored May 21, 2024
1 parent f2f4adc commit ba9fe55
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 112 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/accessibility/browser/accessibleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface IAccessibleViewService {
getOpenAriaHint(verbositySettingKey: string): string | null;
getCodeBlockContext(): ICodeBlockActionContext | undefined;
configureKeybindings(): void;
openHelpLink(): void;
}


Expand Down
82 changes: 25 additions & 57 deletions src/vs/workbench/contrib/accessibility/browser/accessibleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ export class AccessibleView extends Disposable {
return symbols.length ? symbols : undefined;
}

openHelpLink(): void {
if (!this._currentProvider?.options.readMoreUrl) {
return;
}
this._openerService.open(URI.parse(this._currentProvider.options.readMoreUrl));
}

configureKeybindings(): void {
const items = this._currentProvider?.options?.configureKeybindingItems;
const provider = this._currentProvider;
Expand Down Expand Up @@ -470,10 +477,10 @@ export class AccessibleView extends Disposable {
this._currentProvider = provider;
this._accessibleViewCurrentProviderId.set(provider.id);
const verbose = this._verbosityEnabled();
const readMoreLink = provider.options.readMoreUrl ? localize("openDoc", "\n\nOpen a browser window with more information related to accessibility (H).") : '';
const readMoreLink = provider.options.readMoreUrl ? localize("openDoc", "\n\nOpen a browser window with more information related to accessibility<keybinding:{0}>.", AccessibilityCommandId.AccessibilityHelpOpenHelpLink) : '';
let disableHelpHint = '';
if (provider instanceof AdvancedContentProvider && provider.options.type === AccessibleViewType.Help && verbose) {
disableHelpHint = this._getDisableVerbosityHint(provider.verbositySettingKey);
disableHelpHint = this._getDisableVerbosityHint();
}
const accessibilitySupport = this._accessibilityService.isScreenReaderOptimized();
let message = '';
Expand All @@ -494,15 +501,15 @@ export class AccessibleView extends Disposable {
const exitThisDialogHint = verbose && !provider.options.position ? localize('exit', '\n\nExit this dialog (Escape).') : '';
let content = provider.provideContent();
if (provider.options.type === AccessibleViewType.Help) {
const resolvedContent = resolveContentAndKeybindingItems(this._keybindingService, content);
const resolvedContent = resolveContentAndKeybindingItems(this._keybindingService, content + readMoreLink + disableHelpHint + exitThisDialogHint);
if (resolvedContent) {
content = resolvedContent.content.value;
if (resolvedContent.configureKeybindingItems) {
provider.options.configureKeybindingItems = resolvedContent.configureKeybindingItems;
}
}
}
const newContent = message + content + readMoreLink + disableHelpHint + exitThisDialogHint;
const newContent = message + content;
this.calculateCodeBlocks(newContent);
this._currentContent = newContent;
this._updateContextKeys(provider, true);
Expand Down Expand Up @@ -708,66 +715,24 @@ export class AccessibleView extends Disposable {
if (this._currentProvider?.id !== AccessibleViewProviderId.Chat) {
return;
}
let hint = '';
const insertAtCursorKb = this._keybindingService.lookupKeybinding('workbench.action.chat.insertCodeBlock')?.getAriaLabel();
const insertIntoNewFileKb = this._keybindingService.lookupKeybinding('workbench.action.chat.insertIntoNewFile')?.getAriaLabel();
const runInTerminalKb = this._keybindingService.lookupKeybinding('workbench.action.chat.runInTerminal')?.getAriaLabel();

if (insertAtCursorKb) {
hint += localize('insertAtCursor', " - Insert the code block at the cursor ({0}).\n", insertAtCursorKb);
} else {
hint += localize('insertAtCursorNoKb', " - Insert the code block at the cursor by configuring a keybinding for the Chat: Insert Code Block command.\n");
}
if (insertIntoNewFileKb) {
hint += localize('insertIntoNewFile', " - Insert the code block into a new file ({0}).\n", insertIntoNewFileKb);
} else {
hint += localize('insertIntoNewFileNoKb', " - Insert the code block into a new file by configuring a keybinding for the Chat: Insert into New File command.\n");
}
if (runInTerminalKb) {
hint += localize('runInTerminal', " - Run the code block in the terminal ({0}).\n", runInTerminalKb);
} else {
hint += localize('runInTerminalNoKb', " - Run the coe block in the terminal by configuring a keybinding for the Chat: Insert into Terminal command.\n");
}

return hint;
return [localize('insertAtCursor', " - Insert the code block at the cursor<keybinding:workbench.action.chat.insertCodeBlock>."),
localize('insertIntoNewFile', " - Insert the code block into a new file<keybinding:workbench.action.chat.insertIntoNewFile>."),
localize('runInTerminal', " - Run the code block in the terminal<keybinding:'workbench.action.chat.runInTerminal>.\n")].join('\n');
}

private _getNavigationHint(): string {
let hint = '';
const nextKeybinding = this._keybindingService.lookupKeybinding(AccessibilityCommandId.ShowNext)?.getAriaLabel();
const previousKeybinding = this._keybindingService.lookupKeybinding(AccessibilityCommandId.ShowPrevious)?.getAriaLabel();
if (nextKeybinding && previousKeybinding) {
hint = localize('accessibleViewNextPreviousHint', "Show the next ({0}) or previous ({1}) item.", nextKeybinding, previousKeybinding);
} else {
hint = localize('chatAccessibleViewNextPreviousHintNoKb', "Show the next or previous item by configuring keybindings for the Show Next & Previous in Accessible View commands.");
}
return hint;
return localize('accessibleViewNextPreviousHint', "Show the next item<keybinding:{0}> or previous item<keybinding:{1}>.", AccessibilityCommandId.ShowNext, AccessibilityCommandId.ShowPrevious);
}
private _getDisableVerbosityHint(verbositySettingKey: AccessibilityVerbositySettingId | string): string {
if (!this._configurationService.getValue(verbositySettingKey)) {
return '';
}
let hint = '';
const disableKeybinding = this._keybindingService.lookupKeybinding(AccessibilityCommandId.DisableVerbosityHint, this._contextKeyService)?.getAriaLabel();
if (disableKeybinding) {
hint = localize('acessibleViewDisableHint', "\n\nDisable accessibility verbosity for this feature ({0}).", disableKeybinding);
} else {
hint = localize('accessibleViewDisableHintNoKb', "\n\nAdd a keybinding for the command Disable Accessible View Hint, which disables accessibility verbosity for this feature.s");
}
return hint;

private _getDisableVerbosityHint(): string {
return localize('acessibleViewDisableHint', "\n\nDisable accessibility verbosity for this feature<keybinding:{0}>.", AccessibilityCommandId.DisableVerbosityHint);
}

private _getGoToSymbolHint(providerHasSymbols?: boolean): string {
const goToSymbolKb = this._keybindingService.lookupKeybinding(AccessibilityCommandId.GoToSymbol)?.getAriaLabel();
let goToSymbolHint = '';
if (providerHasSymbols) {
if (goToSymbolKb) {
goToSymbolHint = localize('goToSymbolHint', 'Go to a symbol ({0}).', goToSymbolKb);
} else {
goToSymbolHint = localize('goToSymbolHintNoKb', 'To go to a symbol, configure a keybinding for the command Go To Symbol in Accessible View');
}
private _getGoToSymbolHint(providerHasSymbols?: boolean): string | undefined {
if (!providerHasSymbols) {
return;
}
return goToSymbolHint;
return localize('goToSymbolHint', 'Go to a symbol<keybinding:{0}>.', AccessibilityCommandId.GoToSymbol);
}
}

Expand All @@ -792,6 +757,9 @@ export class AccessibleViewService extends Disposable implements IAccessibleView
configureKeybindings(): void {
this._accessibleView?.configureKeybindings();
}
openHelpLink(): void {
this._accessibleView?.openHelpLink();
}
showLastProvider(id: AccessibleViewProviderId): void {
this._accessibleView?.showLastProvider(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ class AccessibilityHelpConfigureKeybindingsAction extends Action2 {
}
registerAction2(AccessibilityHelpConfigureKeybindingsAction);


class AccessibilityHelpOpenHelpLinkAction extends Action2 {
constructor() {
super({
id: AccessibilityCommandId.AccessibilityHelpOpenHelpLink,
precondition: ContextKeyExpr.and(accessibilityHelpIsShown),
keybinding: {
primary: KeyMod.Alt | KeyCode.KeyH,
weight: KeybindingWeight.WorkbenchContrib
},
title: localize('editor.action.accessibilityHelpOpenHelpLink', "Accessibility Help Open Help Link")
});
}
run(accessor: ServicesAccessor): void {
accessor.get(IAccessibleViewService).openHelpLink();
}
}
registerAction2(AccessibilityHelpOpenHelpLinkAction);

class AccessibleViewAcceptInlineCompletionAction extends Action2 {
constructor() {
super({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@
*--------------------------------------------------------------------------------------------*/

import { Disposable } from 'vs/base/common/lifecycle';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { accessibleViewIsShown } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
import * as strings from 'vs/base/common/strings';
import { AccessibilityHelpAction, AccessibleViewAction } from 'vs/workbench/contrib/accessibility/browser/accessibleViewActions';
import { AccessibleViewType, AdvancedContentProvider, ExtensionContentProvider, IAccessibleViewService } from 'vs/platform/accessibility/browser/accessibleView';
import { AccessibleViewRegistry } from 'vs/platform/accessibility/browser/accessibleViewRegistry';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';

export function descriptionForCommand(commandId: string, msg: string, noKbMsg: string, keybindingService: IKeybindingService): string {
const kb = keybindingService.lookupKeybinding(commandId);
if (kb) {
return strings.format(msg, kb.getAriaLabel());
}
return strings.format(noKbMsg, commandId);
}


export class AccesibleViewHelpContribution extends Disposable {
static ID: 'accesibleViewHelpContribution';
constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const enum AccessibilityCommandId {
NextCodeBlock = 'editor.action.accessibleViewNextCodeBlock',
PreviousCodeBlock = 'editor.action.accessibleViewPreviousCodeBlock',
AccessibilityHelpConfigureKeybindings = 'editor.action.accessibilityHelpConfigureKeybindings',
AccessibilityHelpOpenHelpLink = 'editor.action.accessibilityHelpOpenHelpLink',
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,13 @@ export class DiffEditorAccessibilityHelp implements IAccessibleViewImplentation
return;
}

const next = keybindingService.lookupKeybinding(AccessibleDiffViewerNext.id)?.getAriaLabel();
const previous = keybindingService.lookupKeybinding(AccessibleDiffViewerPrev.id)?.getAriaLabel();
let switchSides;
const switchSidesKb = keybindingService.lookupKeybinding('diffEditor.switchSide')?.getAriaLabel();
if (switchSidesKb) {
switchSides = localize('msg3', "Run the command Diff Editor: Switch Side ({0}) to toggle between the original and modified editors.", switchSidesKb);
} else {
switchSides = localize('switchSidesNoKb', "Run the command Diff Editor: Switch Side, which is currently not triggerable via keybinding, to toggle between the original and modified editors.");
}

const switchSides = localize('msg3', "Run the command Diff Editor: Switch Side<keybinding:diffEditor.switchSide> to toggle between the original and modified editors.");
const diffEditorActiveAnnouncement = localize('msg5', "The setting, accessibility.verbosity.diffEditorActive, controls if a diff editor announcement is made when it becomes the active editor.");

const keys = ['accessibility.signals.diffLineDeleted', 'accessibility.signals.diffLineInserted', 'accessibility.signals.diffLineModified'];
const content = [
localize('msg1', "You are in a diff editor."),
localize('msg2', "View the next ({0}) or previous ({1}) diff in diff review mode, which is optimized for screen readers.", next, previous),
localize('msg2', "View the next<keybinding:{0}> or previous<keybinding:{1}> diff in diff review mode, which is optimized for screen readers.", AccessibleDiffViewerNext.id, AccessibleDiffViewerPrev.id),
switchSides,
diffEditorActiveAnnouncement,
localize('msg4', "To control which accessibility signals should be played, the following settings can be configured: {0}.", keys.join(', ')),
Expand Down
Loading

0 comments on commit ba9fe55

Please sign in to comment.