mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
a11y view for last output from REPL input (#233943)
* a11y view for last output from REPL input * default auto focus to input * comment
This commit is contained in:
@@ -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."),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user