Path: blob/main/src/vs/workbench/contrib/notebook/browser/replEditorAccessibleView.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';6import { AccessibleViewType, AccessibleContentProvider, AccessibleViewProviderId } from '../../../../platform/accessibility/browser/accessibleView.js';7import { IAccessibleViewImplementation } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js';8import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';9import { IEditorService } from '../../../services/editor/common/editorService.js';10import { AccessibilityVerbositySettingId } from '../../accessibility/browser/accessibilityConfiguration.js';11import { isReplEditorControl } from '../../replNotebook/browser/replEditor.js';12import { IS_COMPOSITE_NOTEBOOK, NOTEBOOK_CELL_LIST_FOCUSED } from '../common/notebookContextKeys.js';13import { getAllOutputsText } from './viewModel/cellOutputTextHelper.js';1415/**16* The REPL input is already accessible, so we can show a view for the most recent execution output.17*/18export class ReplEditorAccessibleView implements IAccessibleViewImplementation {19readonly priority = 100;20readonly name = 'replEditorInput';21readonly type = AccessibleViewType.View;22readonly when = ContextKeyExpr.and(IS_COMPOSITE_NOTEBOOK, NOTEBOOK_CELL_LIST_FOCUSED.negate());23getProvider(accessor: ServicesAccessor) {24const editorService = accessor.get(IEditorService);25return getAccessibleOutputProvider(editorService);26}27}2829export function getAccessibleOutputProvider(editorService: IEditorService) {30const editorControl = editorService.activeEditorPane?.getControl();3132if (editorControl && isReplEditorControl(editorControl) && editorControl.notebookEditor) {33const notebookEditor = editorControl.notebookEditor;34const viewModel = notebookEditor?.getViewModel();35if (notebookEditor && viewModel) {36// last cell of the viewmodel is the last cell history37const lastCellIndex = viewModel.length - 1;38if (lastCellIndex >= 0) {39const cell = viewModel.viewCells[lastCellIndex];40const outputContent = getAllOutputsText(viewModel.notebookDocument, cell);4142if (outputContent) {43return new AccessibleContentProvider(44AccessibleViewProviderId.Notebook,45{ type: AccessibleViewType.View },46() => { return outputContent; },47() => {48editorControl.activeCodeEditor?.focus();49},50AccessibilityVerbositySettingId.ReplEditor,51);52}53}54}55}5657return;58}596061