Skip to content

Commit 84d97b6

Browse files
authored
* Fixes microsoft#185028 * Consider accessibility.verbosity.diffEditor * Mentions audio cues in diff editor help. * Fixes API change.
1 parent ec700fa commit 84d97b6

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

src/vs/editor/browser/widget/diffEditor.contribution.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import { localize } from 'vs/nls';
1111
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1212
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1313

14-
class DiffReviewNext extends EditorAction {
14+
export class DiffReviewNext extends EditorAction {
15+
public static id = 'editor.action.diffReview.next';
16+
1517
constructor() {
1618
super({
17-
id: 'editor.action.diffReview.next',
19+
id: DiffReviewNext.id,
1820
label: localize('editor.action.diffReview.next', "Go to Next Difference"),
1921
alias: 'Go to Next Difference',
2022
precondition: ContextKeyExpr.has('isInDiffEditor'),
@@ -32,10 +34,12 @@ class DiffReviewNext extends EditorAction {
3234
}
3335
}
3436

35-
class DiffReviewPrev extends EditorAction {
37+
export class DiffReviewPrev extends EditorAction {
38+
public static id = 'editor.action.diffReview.prev';
39+
3640
constructor() {
3741
super({
38-
id: 'editor.action.diffReview.prev',
42+
id: DiffReviewPrev.id,
3943
label: localize('editor.action.diffReview.prev', "Go to Previous Difference"),
4044
alias: 'Go to Previous Difference',
4145
precondition: ContextKeyExpr.has('isInDiffEditor'),

src/vs/editor/browser/widget/diffEditorWidget2/diffEditorEditors.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { localize } from 'vs/nls';
1616
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1717
import { DiffEditorOptions } from './diffEditorOptions';
1818
import { IObservable, IReader } from 'vs/base/common/observable';
19+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1920

2021
export class DiffEditorEditors extends Disposable {
2122
public readonly modified: CodeEditorWidget;
@@ -31,7 +32,8 @@ export class DiffEditorEditors extends Disposable {
3132
codeEditorWidgetOptions: IDiffCodeEditorWidgetOptions,
3233
private readonly _createInnerEditor: (instantiationService: IInstantiationService, container: HTMLElement, options: Readonly<IEditorOptions>, editorWidgetOptions: ICodeEditorWidgetOptions) => CodeEditorWidget,
3334
private readonly _modifiedReadOnlyOverride: IObservable<boolean>,
34-
@IInstantiationService private readonly _instantiationService: IInstantiationService
35+
@IInstantiationService private readonly _instantiationService: IInstantiationService,
36+
@IKeybindingService private readonly _keybindingService: IKeybindingService,
3537
) {
3638
super();
3739

@@ -150,7 +152,10 @@ export class DiffEditorEditors extends Disposable {
150152
}
151153

152154
private _updateAriaLabel(ariaLabel: string | undefined): string | undefined {
153-
const ariaNavigationTip = localize('diff-aria-navigation-tip', ' use Shift + F7 to navigate changes');
155+
if (!ariaLabel) {
156+
ariaLabel = '';
157+
}
158+
const ariaNavigationTip = localize('diff-aria-navigation-tip', ' use {0} to open the accessibility help.', this._keybindingService.lookupKeybinding('editor.action.accessibilityHelp')?.getAriaLabel());
154159
if (this._options.accessibilityVerbose.get()) {
155160
return ariaLabel + ariaNavigationTip;
156161
} else if (ariaLabel) {

src/vs/workbench/contrib/codeEditor/browser/diffEditorHelper.ts

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as nls from 'vs/nls';
6+
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
77
import { IDiffEditor } from 'vs/editor/browser/editorBrowser';
88
import { registerDiffEditorContribution } from 'vs/editor/browser/editorExtensions';
9-
import { IDiffEditorContribution } from 'vs/editor/common/editorCommon';
10-
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
11-
import { FloatingClickWidget } from 'vs/workbench/browser/codeeditor';
9+
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
10+
import { DiffReviewNext, DiffReviewPrev } from 'vs/editor/browser/widget/diffEditor.contribution';
11+
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';
12+
import { EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
1213
import { IDiffComputationResult } from 'vs/editor/common/diff/smartLinesDiffComputer';
13-
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
14+
import { IDiffEditorContribution } from 'vs/editor/common/editorCommon';
15+
import * as nls from 'vs/nls';
1416
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
17+
import { ContextKeyEqualsExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
18+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
19+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1520
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
16-
import { EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
21+
import { FloatingClickWidget } from 'vs/workbench/browser/codeeditor';
22+
import { AccessibilityHelpAction } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
23+
import { AccessibleViewType, IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
24+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1725

1826
const enum WidgetState {
1927
Hidden,
@@ -35,6 +43,44 @@ class DiffEditorHelperContribution extends Disposable implements IDiffEditorCont
3543
@INotificationService private readonly _notificationService: INotificationService,
3644
) {
3745
super();
46+
47+
this._register(AccessibilityHelpAction.addImplementation(105, 'diff-editor', async accessor => {
48+
const accessibleViewService = accessor.get(IAccessibleViewService);
49+
const editorService = accessor.get(IEditorService);
50+
const codeEditorService = accessor.get(ICodeEditorService);
51+
const keybindingService = accessor.get(IKeybindingService);
52+
53+
const next = keybindingService.lookupKeybinding(DiffReviewNext.id)?.getAriaLabel();
54+
const previous = keybindingService.lookupKeybinding(DiffReviewPrev.id)?.getAriaLabel();
55+
56+
if (!(editorService.activeTextEditorControl instanceof DiffEditorWidget2)) {
57+
return;
58+
}
59+
60+
const codeEditor = codeEditorService.getActiveCodeEditor() || codeEditorService.getFocusedCodeEditor();
61+
if (!codeEditor) {
62+
return;
63+
}
64+
65+
const keys = ['audioCues.diffLineDeleted', 'audioCues.diffLineInserted', 'audioCues.diffLineModified'];
66+
67+
accessibleViewService.show({
68+
id: 'diffEditor',
69+
provideContent: () => [
70+
nls.localize('msg1', "You are in a diff editor."),
71+
nls.localize('msg2', "Press {0} or {1} to view the next or previous diff in the diff review mode that is optimized for screen readers.", next, previous),
72+
nls.localize('msg3', "To control which audio cues should be played, the following settings can be configured: {0}.", keys.join(', ')),
73+
].join('\n'),
74+
onClose: () => {
75+
codeEditor.focus();
76+
},
77+
options: { type: AccessibleViewType.HelpMenu, ariaLabel: nls.localize('chat-help-label', "Diff editor accessibility help") }
78+
});
79+
}, ContextKeyExpr.and(
80+
ContextKeyEqualsExpr.create('diffEditorVersion', 2),
81+
ContextKeyEqualsExpr.create('isInDiffEditor', true),
82+
)));
83+
3884
this._helperWidget = null;
3985
this._helperWidgetListener = null;
4086
this._state = WidgetState.Hidden;

0 commit comments

Comments
 (0)