Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/browser/notebookAccessibleView.ts
3296 views
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
import { AccessibleViewProviderId, AccessibleViewType, AccessibleContentProvider } from '../../../../platform/accessibility/browser/accessibleView.js';
6
import { IAccessibleViewImplementation } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js';
7
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
8
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
9
import { AccessibilityVerbositySettingId } from '../../accessibility/browser/accessibilityConfiguration.js';
10
import { getNotebookEditorFromEditorPane } from './notebookBrowser.js';
11
import { NOTEBOOK_CELL_LIST_FOCUSED } from '../common/notebookContextKeys.js';
12
import { IEditorService } from '../../../services/editor/common/editorService.js';
13
import { InputFocusedContext } from '../../../../platform/contextkey/common/contextkeys.js';
14
import { getAllOutputsText } from './viewModel/cellOutputTextHelper.js';
15
16
export class NotebookAccessibleView implements IAccessibleViewImplementation {
17
readonly priority = 100;
18
readonly name = 'notebook';
19
readonly type = AccessibleViewType.View;
20
readonly when = ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, InputFocusedContext.toNegated());
21
getProvider(accessor: ServicesAccessor) {
22
const editorService = accessor.get(IEditorService);
23
return getAccessibleOutputProvider(editorService);
24
}
25
}
26
27
export function getAccessibleOutputProvider(editorService: IEditorService) {
28
const activePane = editorService.activeEditorPane;
29
const notebookEditor = getNotebookEditorFromEditorPane(activePane);
30
const notebookViewModel = notebookEditor?.getViewModel();
31
const selections = notebookViewModel?.getSelections();
32
const notebookDocument = notebookViewModel?.notebookDocument;
33
34
if (!selections || !notebookDocument || !notebookEditor?.textModel) {
35
return;
36
}
37
38
const viewCell = notebookViewModel.viewCells[selections[0].start];
39
const outputContent = getAllOutputsText(notebookDocument, viewCell);
40
41
if (!outputContent) {
42
return;
43
}
44
45
return new AccessibleContentProvider(
46
AccessibleViewProviderId.Notebook,
47
{ type: AccessibleViewType.View },
48
() => { return outputContent; },
49
() => {
50
notebookEditor?.setFocus(selections[0]);
51
notebookEditor.focus();
52
},
53
AccessibilityVerbositySettingId.Notebook,
54
);
55
}
56
57
58