Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/browser/replEditorAccessibleView.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
6
import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';
7
import { AccessibleViewType, AccessibleContentProvider, AccessibleViewProviderId } from '../../../../platform/accessibility/browser/accessibleView.js';
8
import { IAccessibleViewImplementation } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js';
9
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
10
import { IEditorService } from '../../../services/editor/common/editorService.js';
11
import { AccessibilityVerbositySettingId } from '../../accessibility/browser/accessibilityConfiguration.js';
12
import { isReplEditorControl } from '../../replNotebook/browser/replEditor.js';
13
import { IS_COMPOSITE_NOTEBOOK, NOTEBOOK_CELL_LIST_FOCUSED } from '../common/notebookContextKeys.js';
14
import { getAllOutputsText } from './viewModel/cellOutputTextHelper.js';
15
16
/**
17
* The REPL input is already accessible, so we can show a view for the most recent execution output.
18
*/
19
export class ReplEditorAccessibleView implements IAccessibleViewImplementation {
20
readonly priority = 100;
21
readonly name = 'replEditorInput';
22
readonly type = AccessibleViewType.View;
23
readonly when = ContextKeyExpr.and(IS_COMPOSITE_NOTEBOOK, NOTEBOOK_CELL_LIST_FOCUSED.negate());
24
getProvider(accessor: ServicesAccessor) {
25
const editorService = accessor.get(IEditorService);
26
return getAccessibleOutputProvider(editorService);
27
}
28
}
29
30
export function getAccessibleOutputProvider(editorService: IEditorService) {
31
const editorControl = editorService.activeEditorPane?.getControl();
32
33
if (editorControl && isReplEditorControl(editorControl) && editorControl.notebookEditor) {
34
const notebookEditor = editorControl.notebookEditor;
35
const viewModel = notebookEditor?.getViewModel();
36
if (notebookEditor && viewModel) {
37
// last cell of the viewmodel is the last cell history
38
const lastCellIndex = viewModel.length - 1;
39
if (lastCellIndex >= 0) {
40
const cell = viewModel.viewCells[lastCellIndex];
41
const outputContent = getAllOutputsText(viewModel.notebookDocument, cell);
42
43
if (outputContent) {
44
return new AccessibleContentProvider(
45
AccessibleViewProviderId.Notebook,
46
{ type: AccessibleViewType.View },
47
() => { return outputContent; },
48
() => {
49
editorControl.activeCodeEditor?.focus();
50
},
51
AccessibilityVerbositySettingId.ReplEditor,
52
);
53
}
54
}
55
}
56
}
57
58
return;
59
}
60
61