Path: blob/main/src/vs/platform/accessibility/browser/accessibleView.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 { 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',22InlineChat = 'inlineChat',23AgentChat = 'agentChat',24QuickChat = 'quickChat',25InlineCompletions = 'inlineCompletions',26KeybindingsEditor = 'keybindingsEditor',27Notebook = 'notebook',28ReplEditor = 'replEditor',29Editor = 'editor',30Hover = 'hover',31Notification = 'notification',32EmptyEditorHint = 'emptyEditorHint',33Comments = 'comments',34CommentThread = 'commentThread',35Repl = 'repl',36ReplHelp = 'replHelp',37RunAndDebug = 'runAndDebug',38Walkthrough = 'walkthrough',39SourceControl = 'scm'40}4142export const enum AccessibleViewType {43Help = 'help',44View = 'view'45}4647export const enum NavigationType {48Previous = 'previous',49Next = 'next'50}5152export interface IAccessibleViewOptions {53readMoreUrl?: string;54/**55* Defaults to markdown56*/57language?: string;58type: AccessibleViewType;59/**60* By default, places the cursor on the top line of the accessible view.61* If set to 'initial-bottom', places the cursor on the bottom line of the accessible view and preserves it henceforth.62* If set to 'bottom', places the cursor on the bottom line of the accessible view.63*/64position?: 'bottom' | 'initial-bottom';65/**66* @returns a string that will be used as the content of the help dialog67* instead of the one provided by default.68*/69customHelp?: () => string;70/**71* If this provider might want to request to be shown again, provide an ID.72*/73id?: AccessibleViewProviderId;7475/**76* Keybinding items to configure77*/78configureKeybindingItems?: IQuickPickItem[];7980/**81* Keybinding items that are already configured82*/83configuredKeybindingItems?: IQuickPickItem[];84}858687export interface IAccessibleViewContentProvider extends IBasicContentProvider, IDisposable {88id: AccessibleViewProviderId;89verbositySettingKey: string;90/**91* Note that a Codicon class should be provided for each action.92* If not, a default will be used.93*/94onKeyDown?(e: IKeyboardEvent): void;95/**96* When the language is markdown, this is provided by default.97*/98getSymbols?(): IAccessibleViewSymbol[];99/**100* Note that this will only take effect if the provider has an ID.101*/102onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>;103}104105106export interface IAccessibleViewSymbol extends IPickerQuickAccessItem {107markdownToParse?: string;108firstListItem?: string;109lineNumber?: number;110endLineNumber?: number;111}112113export interface IPosition {114lineNumber: number;115column: number;116}117118export interface IAccessibleViewService {119readonly _serviceBrand: undefined;120// The provider will be disposed when the view is closed121show(provider: AccesibleViewContentProvider, position?: IPosition): void;122showLastProvider(id: AccessibleViewProviderId): void;123showAccessibleViewHelp(): void;124next(): void;125previous(): void;126navigateToCodeBlock(type: 'next' | 'previous'): void;127goToSymbol(): void;128disableHint(): void;129getPosition(id: AccessibleViewProviderId): IPosition | undefined;130setPosition(position: IPosition, reveal?: boolean, select?: boolean): void;131getLastPosition(): IPosition | undefined;132/**133* If the setting is enabled, provides the open accessible view hint as a localized string.134* @param verbositySettingKey The setting key for the verbosity of the feature135*/136getOpenAriaHint(verbositySettingKey: string): string | null;137getCodeBlockContext(): ICodeBlockActionContext | undefined;138configureKeybindings(unassigned: boolean): void;139openHelpLink(): void;140}141142143export interface ICodeBlockActionContext {144code: string;145languageId?: string;146codeBlockIndex: number;147element: unknown;148}149150export type AccesibleViewContentProvider = AccessibleContentProvider | ExtensionContentProvider;151152export class AccessibleContentProvider extends Disposable implements IAccessibleViewContentProvider {153154constructor(155public id: AccessibleViewProviderId,156public options: IAccessibleViewOptions,157public provideContent: () => string,158public onClose: () => void,159public verbositySettingKey: string,160public onOpen?: () => void,161public actions?: IAction[],162public provideNextContent?: () => string | undefined,163public providePreviousContent?: () => string | undefined,164public onDidChangeContent?: Event<void>,165public onKeyDown?: (e: IKeyboardEvent) => void,166public getSymbols?: () => IAccessibleViewSymbol[],167public onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>,168) {169super();170}171}172173export function isIAccessibleViewContentProvider(obj: any): obj is IAccessibleViewContentProvider {174return obj && obj.id && obj.options && obj.provideContent && obj.onClose && obj.verbositySettingKey;175}176177export class ExtensionContentProvider extends Disposable implements IBasicContentProvider {178179constructor(180public readonly id: string,181public options: IAccessibleViewOptions,182public provideContent: () => string,183public onClose: () => void,184public onOpen?: () => void,185public provideNextContent?: () => string | undefined,186public providePreviousContent?: () => string | undefined,187public actions?: IAction[],188public onDidChangeContent?: Event<void>,189) {190super();191}192}193194export interface IBasicContentProvider extends IDisposable {195id: string;196options: IAccessibleViewOptions;197onClose(): void;198provideContent(): string;199onOpen?(): void;200actions?: IAction[];201providePreviousContent?(): void;202provideNextContent?(): void;203onDidChangeContent?: Event<void>;204}205206207