Path: blob/main/src/vs/platform/accessibility/browser/accessibleView.ts
5240 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 { createDecorator } from '../../instantiation/common/instantiation.js';6import { IKeyboardEvent } from '../../keybinding/common/keybinding.js';7import { IPickerQuickAccessItem } from '../../quickinput/browser/pickerQuickAccess.js';8import { Event } from '../../../base/common/event.js';9import { IAction } from '../../../base/common/actions.js';10import { IQuickPickItem } from '../../quickinput/common/quickInput.js';11import { IDisposable, Disposable } from '../../../base/common/lifecycle.js';1213export const IAccessibleViewService = createDecorator<IAccessibleViewService>('accessibleViewService');1415export const enum AccessibleViewProviderId {16Terminal = 'terminal',17TerminalChat = 'terminal-chat',18TerminalHelp = 'terminal-help',19DiffEditor = 'diffEditor',20MergeEditor = 'mergeEditor',21PanelChat = 'panelChat',22ChatTerminalOutput = 'chatTerminalOutput',23ChatThinking = 'chatThinking',24InlineChat = 'inlineChat',25AgentChat = 'agentChat',26QuickChat = 'quickChat',27InlineCompletions = 'inlineCompletions',28KeybindingsEditor = 'keybindingsEditor',29Notebook = 'notebook',30ReplEditor = 'replEditor',31Editor = 'editor',32Hover = 'hover',33Notification = 'notification',34EmptyEditorHint = 'emptyEditorHint',35Comments = 'comments',36CommentThread = 'commentThread',37Repl = 'repl',38ReplHelp = 'replHelp',39RunAndDebug = 'runAndDebug',40Walkthrough = 'walkthrough',41SourceControl = 'scm',42EditorFindHelp = 'editorFindHelp',43SearchHelp = 'searchHelp',44TerminalFindHelp = 'terminalFindHelp',45WebviewFindHelp = 'webviewFindHelp',46OutputFindHelp = 'outputFindHelp',47ProblemsFilterHelp = 'problemsFilterHelp',48}4950export const enum AccessibleViewType {51Help = 'help',52View = 'view'53}5455export const enum NavigationType {56Previous = 'previous',57Next = 'next'58}5960export interface IAccessibleViewOptions {61readMoreUrl?: string;62/**63* Defaults to markdown64*/65language?: string;66type: AccessibleViewType;67/**68* By default, places the cursor on the top line of the accessible view.69* If set to 'initial-bottom', places the cursor on the bottom line of the accessible view and preserves it henceforth.70* If set to 'bottom', places the cursor on the bottom line of the accessible view.71*/72position?: 'bottom' | 'initial-bottom';73/**74* @returns a string that will be used as the content of the help dialog75* instead of the one provided by default.76*/77customHelp?: () => string;78/**79* If this provider might want to request to be shown again, provide an ID.80*/81id?: AccessibleViewProviderId;8283/**84* Keybinding items to configure85*/86configureKeybindingItems?: IQuickPickItem[];8788/**89* Keybinding items that are already configured90*/91configuredKeybindingItems?: IQuickPickItem[];92}939495export interface IAccessibleViewContentProvider extends IBasicContentProvider, IDisposable {96id: AccessibleViewProviderId;97verbositySettingKey: string;98/**99* Note that a Codicon class should be provided for each action.100* If not, a default will be used.101*/102onKeyDown?(e: IKeyboardEvent): void;103/**104* When the language is markdown, this is provided by default.105*/106getSymbols?(): IAccessibleViewSymbol[];107/**108* Note that this will only take effect if the provider has an ID.109*/110readonly onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>;111}112113114export interface IAccessibleViewSymbol extends IPickerQuickAccessItem {115markdownToParse?: string;116firstListItem?: string;117lineNumber?: number;118endLineNumber?: number;119}120121export interface IPosition {122lineNumber: number;123column: number;124}125126export interface IAccessibleViewService {127readonly _serviceBrand: undefined;128// The provider will be disposed when the view is closed129show(provider: AccesibleViewContentProvider, position?: IPosition): void;130showLastProvider(id: AccessibleViewProviderId): void;131showAccessibleViewHelp(): void;132next(): void;133previous(): void;134navigateToCodeBlock(type: 'next' | 'previous'): void;135goToSymbol(): void;136disableHint(): void;137getPosition(id: AccessibleViewProviderId): IPosition | undefined;138setPosition(position: IPosition, reveal?: boolean, select?: boolean): void;139getLastPosition(): IPosition | undefined;140/**141* If the setting is enabled, provides the open accessible view hint as a localized string.142* @param verbositySettingKey The setting key for the verbosity of the feature143*/144getOpenAriaHint(verbositySettingKey: string): string | null;145getCodeBlockContext(): ICodeBlockActionContext | undefined;146configureKeybindings(unassigned: boolean): void;147openHelpLink(): void;148}149150151export interface ICodeBlockActionContext {152code: string;153languageId?: string;154codeBlockIndex: number;155element: unknown;156}157158export type AccesibleViewContentProvider = AccessibleContentProvider | ExtensionContentProvider;159160export class AccessibleContentProvider extends Disposable implements IAccessibleViewContentProvider {161162constructor(163public id: AccessibleViewProviderId,164public options: IAccessibleViewOptions,165public provideContent: () => string,166public onClose: () => void,167public verbositySettingKey: string,168public onOpen?: () => void,169public actions?: IAction[],170public provideNextContent?: () => string | undefined,171public providePreviousContent?: () => string | undefined,172public onDidChangeContent?: Event<void>,173public onKeyDown?: (e: IKeyboardEvent) => void,174public getSymbols?: () => IAccessibleViewSymbol[],175public onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>,176) {177super();178}179}180181export function isIAccessibleViewContentProvider(obj: unknown): obj is IAccessibleViewContentProvider {182if (!obj || typeof obj !== 'object') {183return false;184}185186const candidate = obj as Partial<IAccessibleViewContentProvider>;187return !!candidate.id188&& !!candidate.options189&& typeof candidate.provideContent === 'function'190&& typeof candidate.onClose === 'function'191&& typeof candidate.verbositySettingKey === 'string';192}193194export class ExtensionContentProvider extends Disposable implements IBasicContentProvider {195196constructor(197public readonly id: string,198public options: IAccessibleViewOptions,199public provideContent: () => string,200public onClose: () => void,201public onOpen?: () => void,202public provideNextContent?: () => string | undefined,203public providePreviousContent?: () => string | undefined,204public actions?: IAction[],205public onDidChangeContent?: Event<void>,206) {207super();208}209}210211export interface IBasicContentProvider extends IDisposable {212id: string;213options: IAccessibleViewOptions;214onClose(): void;215provideContent(): string;216onOpen?(): void;217actions?: IAction[];218providePreviousContent?(): void;219provideNextContent?(): void;220readonly onDidChangeContent?: Event<void>;221}222223224