|
| 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.cell.edit', |
| 18 | + localize('notebook.cell.edit', 'The Edit Cell command ({0}) will focus on the cell input.'), |
| 19 | + localize('notebook.cell.editNoKb', 'The Edit Cell command will focus on the cell input and is currently not triggerable by a keybinding.'), keybindingService)); |
| 20 | + content.push(descriptionForCommand('notebook.cell.quitEdit', |
| 21 | + localize('notebook.cell.quitEdit', 'The Quit Edit command ({0}) will set focus on the cell container. The default (Escape) key may need to be pressed twice first exit the virtual cursor if active.'), |
| 22 | + localize('notebook.cell.quitEditNoKb', 'The Quit Edit command will set focus on the cell container and is currently not triggerable by a keybinding.'), keybindingService)); |
| 23 | + content.push(descriptionForCommand('notebook.cell.focusInOutput', |
| 24 | + localize('notebook.cell.focusInOutput', 'The Focus Output command ({0}) will set focus in the cell\'s output.'), |
| 25 | + localize('notebook.cell.focusInOutputNoKb', 'The Quit Edit command will set focus in the cell\'s output and is currently not triggerable by a keybinding.'), keybindingService)); |
| 26 | + content.push(localize('notebook.cellNavigation', 'The up and down arrows will move focus between cells while focused on the outer cell container')); |
| 27 | + content.push(descriptionForCommand('notebook.cell.executeAndFocusContainer', |
| 28 | + localize('notebook.cell.executeAndFocusContainer', 'The Execute Cell command ({0}) executes the cell that currently has focus.',), |
| 29 | + localize('notebook.cell.executeAndFocusContainerNoKb', 'The Execute Cell command executes the cell that currently has focus and is currently not triggerable by a keybinding.'), keybindingService)); |
| 30 | + content.push(localize('notebook.cell.insertCodeCellBelowAndFocusContainer', 'The Insert Cell Above/Below commands will create new empty code cells')); |
| 31 | + content.push(localize('notebook.changeCellType', 'The Change Cell to Code/Markdown commands are used to switch between cell types.')); |
| 32 | + |
| 33 | + |
| 34 | + return content.join('\n'); |
| 35 | +} |
| 36 | + |
| 37 | +function descriptionForCommand(commandId: string, msg: string, noKbMsg: string, keybindingService: IKeybindingService): string { |
| 38 | + const kb = keybindingService.lookupKeybinding(commandId); |
| 39 | + if (kb) { |
| 40 | + return format(msg, kb.getAriaLabel()); |
| 41 | + } |
| 42 | + return format(noKbMsg, commandId); |
| 43 | +} |
| 44 | + |
| 45 | +export async function runAccessibilityHelpAction(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> { |
| 46 | + const accessibleViewService = accessor.get(IAccessibleViewService); |
| 47 | + const helpText = getAccessibilityHelpText(accessor); |
| 48 | + const provider = accessibleViewService.registerProvider({ |
| 49 | + id: 'notebook', |
| 50 | + provideContent: () => helpText, |
| 51 | + onClose: () => { |
| 52 | + editor.focus(); |
| 53 | + provider.dispose(); |
| 54 | + }, |
| 55 | + options: { type: AccessibleViewType.HelpMenu, ariaLabel: 'Notebook accessibility help' } |
| 56 | + }); |
| 57 | + accessibleViewService.show('notebook'); |
| 58 | +} |
0 commit comments