diff --git a/src/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration.ts b/src/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration.ts index 21ef42df1c1..9e64c7226d7 100644 --- a/src/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration.ts +++ b/src/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration.ts @@ -712,7 +712,7 @@ const configuration: IConfigurationNode = { 'accessibility.replEditor.autoFocusReplExecution': { type: 'string', enum: ['none', 'input', 'lastExecution'], - default: 'lastExecution', + default: 'input', description: localize('replEditor.autoFocusAppendedCell', "Control whether focus should automatically be sent to the REPL when code is executed."), } } diff --git a/src/vs/workbench/contrib/notebook/browser/replEditorAccessibleView.ts b/src/vs/workbench/contrib/notebook/browser/replEditorAccessibleView.ts new file mode 100644 index 00000000000..98184cdfe3a --- /dev/null +++ b/src/vs/workbench/contrib/notebook/browser/replEditorAccessibleView.ts @@ -0,0 +1,59 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js'; +import { AccessibleViewType, AccessibleContentProvider, AccessibleViewProviderId } from '../../../../platform/accessibility/browser/accessibleView.js'; +import { IAccessibleViewImplentation } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js'; +import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js'; +import { IEditorService } from '../../../services/editor/common/editorService.js'; +import { AccessibilityVerbositySettingId } from '../../accessibility/browser/accessibilityConfiguration.js'; +import { isReplEditorControl } from '../../replNotebook/browser/replEditor.js'; +import { IS_COMPOSITE_NOTEBOOK, NOTEBOOK_CELL_LIST_FOCUSED } from '../common/notebookContextKeys.js'; +import { getAllOutputsText } from './viewModel/cellOutputTextHelper.js'; + +/** + * The REPL input is already accessible, so we can show a view for the most recent execution output. + */ +export class ReplEditorAccessibleView implements IAccessibleViewImplentation { + readonly priority = 100; + readonly name = 'replEditorInput'; + readonly type = AccessibleViewType.View; + readonly when = ContextKeyExpr.and(IS_COMPOSITE_NOTEBOOK, NOTEBOOK_CELL_LIST_FOCUSED.negate()); + getProvider(accessor: ServicesAccessor) { + const editorService = accessor.get(IEditorService); + return getAccessibleOutputProvider(editorService); + } +} + +export function getAccessibleOutputProvider(editorService: IEditorService) { + const editorControl = editorService.activeEditorPane?.getControl(); + + if (editorControl && isReplEditorControl(editorControl) && editorControl.notebookEditor) { + const notebookEditor = editorControl.notebookEditor; + const viewModel = notebookEditor?.getViewModel(); + if (notebookEditor && viewModel) { + // last cell of the viewmodel is the last cell history + const lastCellIndex = viewModel.length - 1; + if (lastCellIndex >= 0) { + const cell = viewModel.viewCells[lastCellIndex]; + const outputContent = getAllOutputsText(viewModel.notebookDocument, cell); + + if (outputContent) { + return new AccessibleContentProvider( + AccessibleViewProviderId.Notebook, + { type: AccessibleViewType.View }, + () => { return outputContent; }, + () => { + editorControl.activeCodeEditor?.focus(); + }, + AccessibilityVerbositySettingId.ReplEditor, + ); + } + } + } + } + + return; +} diff --git a/src/vs/workbench/contrib/replNotebook/browser/repl.contribution.ts b/src/vs/workbench/contrib/replNotebook/browser/repl.contribution.ts index af913c22053..77f57e10fed 100644 --- a/src/vs/workbench/contrib/replNotebook/browser/repl.contribution.ts +++ b/src/vs/workbench/contrib/replNotebook/browser/repl.contribution.ts @@ -43,6 +43,7 @@ import { NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from '../../notebook/browser/con import { INotebookEditorOptions } from '../../notebook/browser/notebookBrowser.js'; import { NotebookEditorWidget } from '../../notebook/browser/notebookEditorWidget.js'; import * as icons from '../../notebook/browser/notebookIcons.js'; +import { ReplEditorAccessibleView } from '../../notebook/browser/replEditorAccessibleView.js'; import { INotebookEditorService } from '../../notebook/browser/services/notebookEditorService.js'; import { CellEditType, CellKind, NotebookSetting, NotebookWorkingCopyTypeIdentifier, REPL_EDITOR_ID } from '../../notebook/common/notebookCommon.js'; import { IS_COMPOSITE_NOTEBOOK, MOST_RECENT_REPL_EDITOR, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_EDITOR_FOCUSED } from '../../notebook/common/notebookContextKeys.js'; @@ -473,6 +474,8 @@ async function executeReplInput( } } +AccessibleViewRegistry.register(new ReplEditorAccessibleView()); + KeybindingsRegistry.registerCommandAndKeybindingRule({ id: 'list.find.replInputFocus', weight: KeybindingWeight.WorkbenchContrib + 1,