Skip to content

Commit

Permalink
fix #197792
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Nov 15, 2023
1 parent 36819f9 commit bff6047
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle
import { Registry } from 'vs/platform/registry/common/platform';
import { IAccessibleViewService, AccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
import { UnfocusedViewDimmingContribution } from 'vs/workbench/contrib/accessibility/browser/unfocusedViewDimmingContribution';
import { EditorAccessibilityHelpContribution, HoverAccessibleViewContribution, InlineCompletionsAccessibleViewContribution, NotificationAccessibleViewContribution } from 'vs/workbench/contrib/accessibility/browser/accessibilityContributions';
import { HoverAccessibleViewContribution, InlineCompletionsAccessibleViewContribution, NotificationAccessibleViewContribution } from 'vs/workbench/contrib/accessibility/browser/accessibilityContributions';
import { AccessibilityStatus } from 'vs/workbench/contrib/accessibility/browser/accessibilityStatus';
import { CommentsAccessibilityHelpContribution } from 'vs/workbench/contrib/comments/browser/comments.contribution';
import { IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
import { AccessibleNotificationService } from 'vs/workbench/contrib/accessibility/browser/accessibleNotificationService';
import { EditorAccessibilityHelpContribution } from 'vs/workbench/contrib/accessibility/browser/editorAccessibilityHelp';

registerAccessibilityConfiguration();
registerSingleton(IAccessibleViewService, AccessibleViewService, InstantiationType.Delayed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const accessibleViewCurrentProviderId = new RawContextKey<string>('access
export const enum AccessibilityWorkbenchSettingId {
DimUnfocusedEnabled = 'accessibility.dimUnfocused.enabled',
DimUnfocusedOpacity = 'accessibility.dimUnfocused.opacity',
HideAccessibleView = 'accessibility.hideAccessibleView'
HideAccessibleView = 'accessibility.hideAccessibleView',
AccessibleViewCloseOnKeyPress = 'accessibility.accessibleView.closeOnKeyPress'
}

export const enum ViewDimUnfocusedOpacityProperties {
Expand Down Expand Up @@ -159,7 +160,12 @@ const configuration: IConfigurationNode = {
'default': SpeechTimeoutDefault,
'minimum': 0,
'tags': ['accessibility']
}
},
[AccessibilityWorkbenchSettingId.AccessibleViewCloseOnKeyPress]: {
markdownDescription: localize('terminal.integrated.accessibleView.closeOnKeyPress', "On keypress, close the accessible view and focus the element from which it was invoked."),
type: 'boolean',
default: true
},
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@
*--------------------------------------------------------------------------------------------*/

import { Disposable } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { AccessibilityHelpNLS } from 'vs/editor/common/standaloneStrings';
import { ToggleTabFocusModeAction } from 'vs/editor/contrib/toggleTabFocusMode/browser/toggleTabFocusMode';
import { localize } from 'vs/nls';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { AccessibilityVerbositySettingId, AccessibleViewProviderId, accessibleViewIsShown } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
import * as strings from 'vs/base/common/strings';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { NEW_UNTITLED_FILE_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileConstants';
import { ModesHoverController } from 'vs/editor/contrib/hover/browser/hover';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { getNotificationFromContext } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
import { IListService, WorkbenchList } from 'vs/platform/list/browser/listService';
import { NotificationFocusedContext } from 'vs/workbench/common/contextkeys';
import { IAccessibleViewService, IAccessibleContentProvider, IAccessibleViewOptions, AccessibleViewType } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
import { IAccessibleViewService, IAccessibleViewOptions, AccessibleViewType } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { alert } from 'vs/base/browser/ui/aria/aria';
import { AccessibilityHelpAction, AccessibleViewAction } from 'vs/workbench/contrib/accessibility/browser/accessibleViewActions';
Expand All @@ -37,124 +31,10 @@ import { ThemeIcon } from 'vs/base/common/themables';
import { Codicon } from 'vs/base/common/codicons';
import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController';
import { InlineCompletionContextKeys } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionContextKeys';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';
import { CommentAccessibilityHelpNLS } from 'vs/workbench/contrib/comments/browser/comments.contribution';
import { CommentCommandId } from 'vs/workbench/contrib/comments/common/commentCommandIds';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { AudioCue } from 'vs/platform/audioCues/browser/audioCueService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';

export class EditorAccessibilityHelpContribution extends Disposable {
static ID: 'editorAccessibilityHelpContribution';
constructor() {
super();
this._register(AccessibilityHelpAction.addImplementation(95, 'editor', async accessor => {
const codeEditorService = accessor.get(ICodeEditorService);
const accessibleViewService = accessor.get(IAccessibleViewService);
const instantiationService = accessor.get(IInstantiationService);
const commandService = accessor.get(ICommandService);
let codeEditor = codeEditorService.getActiveCodeEditor() || codeEditorService.getFocusedCodeEditor();
if (!codeEditor) {
await commandService.executeCommand(NEW_UNTITLED_FILE_COMMAND_ID);
codeEditor = codeEditorService.getActiveCodeEditor()!;
}
accessibleViewService.show(instantiationService.createInstance(EditorAccessibilityHelpProvider, codeEditor));
}, EditorContextKeys.focus));
}
}

class EditorAccessibilityHelpProvider implements IAccessibleContentProvider {
id = AccessibleViewProviderId.Editor;
onClose() {
this._editor.focus();
}
options: IAccessibleViewOptions = { type: AccessibleViewType.Help, readMoreUrl: 'https://go.microsoft.com/fwlink/?linkid=851010' };
verbositySettingKey = AccessibilityVerbositySettingId.Editor;
constructor(
private readonly _editor: ICodeEditor,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
}

provideContent(): string {
const options = this._editor.getOptions();
const content = [];

if (options.get(EditorOption.inDiffEditor)) {
if (options.get(EditorOption.readOnly)) {
content.push(AccessibilityHelpNLS.readonlyDiffEditor);
} else {
content.push(AccessibilityHelpNLS.editableDiffEditor);
}
} else {
if (options.get(EditorOption.readOnly)) {
content.push(AccessibilityHelpNLS.readonlyEditor);
} else {
content.push(AccessibilityHelpNLS.editableEditor);
}
}
const saveAudioCue = this._configurationService.getValue(AudioCue.save.settingsKey);
switch (saveAudioCue) {
case 'never':
content.push(AccessibilityHelpNLS.saveAudioCueDisabled);
break;
case 'always':
content.push(AccessibilityHelpNLS.saveAudioCueAlways);
break;
case 'userGesture':
content.push(AccessibilityHelpNLS.saveAudioCueUserGesture);
break;
}
const formatAudioCue = this._configurationService.getValue(AudioCue.format.settingsKey);
switch (formatAudioCue) {
case 'never':
content.push(AccessibilityHelpNLS.formatAudioCueDisabled);
break;
case 'always':
content.push(AccessibilityHelpNLS.formatAudioCueAlways);
break;
case 'userGesture':
content.push(AccessibilityHelpNLS.formatAudioCueUserGesture);
break;
}

const commentCommandInfo = getCommentCommandInfo(this._keybindingService, this._contextKeyService, this._editor);
if (commentCommandInfo) {
content.push(commentCommandInfo);
}

if (options.get(EditorOption.stickyScroll).enabled) {
content.push(descriptionForCommand('editor.action.focusStickyScroll', AccessibilityHelpNLS.stickScrollKb, AccessibilityHelpNLS.stickScrollNoKb, this._keybindingService));
}

if (options.get(EditorOption.tabFocusMode)) {
content.push(descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOnMsg, AccessibilityHelpNLS.tabFocusModeOnMsgNoKb, this._keybindingService));
} else {
content.push(descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOffMsg, AccessibilityHelpNLS.tabFocusModeOffMsgNoKb, this._keybindingService));
}
return content.join('\n\n');
}
}

export function getCommentCommandInfo(keybindingService: IKeybindingService, contextKeyService: IContextKeyService, editor: ICodeEditor): string | undefined {
const editorContext = contextKeyService.getContext(editor.getDomNode()!);
if (editorContext.getValue<boolean>(CommentContextKeys.activeEditorHasCommentingRange.key)) {
const commentCommandInfo: string[] = [];
commentCommandInfo.push(CommentAccessibilityHelpNLS.intro);
commentCommandInfo.push(descriptionForCommand(CommentCommandId.Add, CommentAccessibilityHelpNLS.addComment, CommentAccessibilityHelpNLS.addCommentNoKb, keybindingService));
commentCommandInfo.push(descriptionForCommand(CommentCommandId.NextThread, CommentAccessibilityHelpNLS.nextCommentThreadKb, CommentAccessibilityHelpNLS.nextCommentThreadNoKb, keybindingService));
commentCommandInfo.push(descriptionForCommand(CommentCommandId.PreviousThread, CommentAccessibilityHelpNLS.previousCommentThreadKb, CommentAccessibilityHelpNLS.previousCommentThreadNoKb, keybindingService));
commentCommandInfo.push(descriptionForCommand(CommentCommandId.NextRange, CommentAccessibilityHelpNLS.nextRange, CommentAccessibilityHelpNLS.nextRangeNoKb, keybindingService));
commentCommandInfo.push(descriptionForCommand(CommentCommandId.PreviousRange, CommentAccessibilityHelpNLS.previousRange, CommentAccessibilityHelpNLS.previousRangeNoKb, keybindingService));
return commentCommandInfo.join('\n');
}
return;
}

function descriptionForCommand(commandId: string, msg: string, noKbMsg: string, keybindingService: IKeybindingService): string {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class AccessibleView extends Disposable {
};
const disposableStore = new DisposableStore();
disposableStore.add(this._editorWidget.onKeyDown((e) => {
if (e.keyCode === KeyCode.Escape || shouldHide(e.browserEvent, this._keybindingService)) {
if (e.keyCode === KeyCode.Escape || shouldHide(e.browserEvent, this._keybindingService, this._configurationService)) {
hide(e);
} else if (e.keyCode === KeyCode.KeyH && provider.options.readMoreUrl) {
const url: string = provider.options.readMoreUrl!;
Expand Down Expand Up @@ -766,7 +766,10 @@ export interface IAccessibleViewSymbol extends IPickerQuickAccessItem {
lineNumber?: number;
}

function shouldHide(event: KeyboardEvent, keybindingService: IKeybindingService): boolean {
function shouldHide(event: KeyboardEvent, keybindingService: IKeybindingService, configurationService: IConfigurationService): boolean {
if (!configurationService.getValue(AccessibilityWorkbenchSettingId.AccessibleViewCloseOnKeyPress)) {
return false;
}
const standardKeyboardEvent = new StandardKeyboardEvent(event);
const resolveResult = keybindingService.softDispatch(standardKeyboardEvent, standardKeyboardEvent.target);

Expand Down
Loading

0 comments on commit bff6047

Please sign in to comment.