Skip to content

Commit 9b1b19a

Browse files
committed
notebook accessibility help
1 parent 8baeed4 commit 9b1b19a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ import { NotebookKernelHistoryService } from 'vs/workbench/contrib/notebook/brow
112112
import { INotebookLoggingService } from 'vs/workbench/contrib/notebook/common/notebookLoggingService';
113113
import { NotebookLoggingService } from 'vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl';
114114
import product from 'vs/platform/product/common/product';
115+
import { AccessibilityHelpAction } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
116+
import { NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
117+
import { runAccessibilityHelpAction } from 'vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp';
115118

116119
/*--------------------------------------------------------------------------------------------- */
117120

@@ -672,6 +675,20 @@ class NotebookLanguageSelectorScoreRefine {
672675
}
673676
}
674677

678+
class NotebookAccessibilityHelpContribution extends Disposable {
679+
static ID: 'chatAccessibilityHelpContribution';
680+
constructor() {
681+
super();
682+
this._register(AccessibilityHelpAction.addImplementation(105, 'notebook', async accessor => {
683+
const codeEditor = accessor.get(ICodeEditorService).getActiveCodeEditor() || accessor.get(ICodeEditorService).getFocusedCodeEditor();
684+
if (!codeEditor) {
685+
return;
686+
}
687+
runAccessibilityHelpAction(accessor, codeEditor);
688+
}, NOTEBOOK_IS_ACTIVE_EDITOR));
689+
}
690+
}
691+
675692
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
676693
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookContribution, LifecyclePhase.Starting);
677694
workbenchContributionsRegistry.registerWorkbenchContribution(CellContentProvider, LifecyclePhase.Starting);
@@ -680,6 +697,7 @@ workbenchContributionsRegistry.registerWorkbenchContribution(RegisterSchemasCont
680697
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookEditorManager, LifecyclePhase.Ready);
681698
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookLanguageSelectorScoreRefine, LifecyclePhase.Ready);
682699
workbenchContributionsRegistry.registerWorkbenchContribution(SimpleNotebookWorkingCopyEditorHandler, LifecyclePhase.Ready);
700+
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookAccessibilityHelpContribution, LifecyclePhase.Eventually);
683701

684702
registerSingleton(INotebookService, NotebookService, InstantiationType.Delayed);
685703
registerSingleton(INotebookEditorWorkerService, NotebookEditorWorkerServiceImpl, InstantiationType.Delayed);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { localize } from 'vs/nls';
7+
import { format } from 'vs/base/common/strings';
8+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
9+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
10+
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
11+
import { AccessibleViewType, IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
12+
13+
export function getAccessibilityHelpText(accessor: ServicesAccessor): string {
14+
const keybindingService = accessor.get(IKeybindingService);
15+
const content = [];
16+
content.push(localize('notebook.overview', 'The notebook view is a collection of code and markdown cells. Code cells can be executed and will produce output directly below the cell.'));
17+
content.push(descriptionForCommand('notebook.execute', localize('notebook.cell.executeAndFocusContainer', 'The Execute Cell command ({0}) executes the cell that currently has focus.',), localize('notebook.cell.executeAndFocusContainerNoKb', 'The Execute Cell command executes the cell that currently has focus and is currently not triggerable by a keybinding.'), keybindingService));
18+
19+
return content.join('\n');
20+
}
21+
22+
function descriptionForCommand(commandId: string, msg: string, noKbMsg: string, keybindingService: IKeybindingService): string {
23+
const kb = keybindingService.lookupKeybinding(commandId);
24+
if (kb) {
25+
return format(msg, kb.getAriaLabel());
26+
}
27+
return format(noKbMsg, commandId);
28+
}
29+
30+
export async function runAccessibilityHelpAction(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
31+
const accessibleViewService = accessor.get(IAccessibleViewService);
32+
const helpText = getAccessibilityHelpText(accessor);
33+
const provider = accessibleViewService.registerProvider({
34+
id: 'notebook',
35+
provideContent: () => helpText,
36+
onClose: () => {
37+
editor.focus();
38+
provider.dispose();
39+
},
40+
options: { type: AccessibleViewType.HelpMenu, ariaLabel: 'Notebook accessibility help' }
41+
});
42+
accessibleViewService.show('notebook');
43+
}

0 commit comments

Comments
 (0)