Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/accessibility/browser/accessibleView.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { createDecorator } from '../../instantiation/common/instantiation.js';
7
import { IKeyboardEvent } from '../../keybinding/common/keybinding.js';
8
import { IPickerQuickAccessItem } from '../../quickinput/browser/pickerQuickAccess.js';
9
import { Event } from '../../../base/common/event.js';
10
import { IAction } from '../../../base/common/actions.js';
11
import { IQuickPickItem } from '../../quickinput/common/quickInput.js';
12
import { IDisposable, Disposable } from '../../../base/common/lifecycle.js';
13
14
export const IAccessibleViewService = createDecorator<IAccessibleViewService>('accessibleViewService');
15
16
export const enum AccessibleViewProviderId {
17
Terminal = 'terminal',
18
TerminalChat = 'terminal-chat',
19
TerminalHelp = 'terminal-help',
20
DiffEditor = 'diffEditor',
21
MergeEditor = 'mergeEditor',
22
PanelChat = 'panelChat',
23
InlineChat = 'inlineChat',
24
AgentChat = 'agentChat',
25
QuickChat = 'quickChat',
26
InlineCompletions = 'inlineCompletions',
27
KeybindingsEditor = 'keybindingsEditor',
28
Notebook = 'notebook',
29
ReplEditor = 'replEditor',
30
Editor = 'editor',
31
Hover = 'hover',
32
Notification = 'notification',
33
EmptyEditorHint = 'emptyEditorHint',
34
Comments = 'comments',
35
CommentThread = 'commentThread',
36
Repl = 'repl',
37
ReplHelp = 'replHelp',
38
RunAndDebug = 'runAndDebug',
39
Walkthrough = 'walkthrough',
40
SourceControl = 'scm'
41
}
42
43
export const enum AccessibleViewType {
44
Help = 'help',
45
View = 'view'
46
}
47
48
export const enum NavigationType {
49
Previous = 'previous',
50
Next = 'next'
51
}
52
53
export interface IAccessibleViewOptions {
54
readMoreUrl?: string;
55
/**
56
* Defaults to markdown
57
*/
58
language?: string;
59
type: AccessibleViewType;
60
/**
61
* By default, places the cursor on the top line of the accessible view.
62
* If set to 'initial-bottom', places the cursor on the bottom line of the accessible view and preserves it henceforth.
63
* If set to 'bottom', places the cursor on the bottom line of the accessible view.
64
*/
65
position?: 'bottom' | 'initial-bottom';
66
/**
67
* @returns a string that will be used as the content of the help dialog
68
* instead of the one provided by default.
69
*/
70
customHelp?: () => string;
71
/**
72
* If this provider might want to request to be shown again, provide an ID.
73
*/
74
id?: AccessibleViewProviderId;
75
76
/**
77
* Keybinding items to configure
78
*/
79
configureKeybindingItems?: IQuickPickItem[];
80
81
/**
82
* Keybinding items that are already configured
83
*/
84
configuredKeybindingItems?: IQuickPickItem[];
85
}
86
87
88
export interface IAccessibleViewContentProvider extends IBasicContentProvider, IDisposable {
89
id: AccessibleViewProviderId;
90
verbositySettingKey: string;
91
/**
92
* Note that a Codicon class should be provided for each action.
93
* If not, a default will be used.
94
*/
95
onKeyDown?(e: IKeyboardEvent): void;
96
/**
97
* When the language is markdown, this is provided by default.
98
*/
99
getSymbols?(): IAccessibleViewSymbol[];
100
/**
101
* Note that this will only take effect if the provider has an ID.
102
*/
103
onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>;
104
}
105
106
107
export interface IAccessibleViewSymbol extends IPickerQuickAccessItem {
108
markdownToParse?: string;
109
firstListItem?: string;
110
lineNumber?: number;
111
endLineNumber?: number;
112
}
113
114
export interface IPosition {
115
lineNumber: number;
116
column: number;
117
}
118
119
export interface IAccessibleViewService {
120
readonly _serviceBrand: undefined;
121
// The provider will be disposed when the view is closed
122
show(provider: AccesibleViewContentProvider, position?: IPosition): void;
123
showLastProvider(id: AccessibleViewProviderId): void;
124
showAccessibleViewHelp(): void;
125
next(): void;
126
previous(): void;
127
navigateToCodeBlock(type: 'next' | 'previous'): void;
128
goToSymbol(): void;
129
disableHint(): void;
130
getPosition(id: AccessibleViewProviderId): IPosition | undefined;
131
setPosition(position: IPosition, reveal?: boolean, select?: boolean): void;
132
getLastPosition(): IPosition | undefined;
133
/**
134
* If the setting is enabled, provides the open accessible view hint as a localized string.
135
* @param verbositySettingKey The setting key for the verbosity of the feature
136
*/
137
getOpenAriaHint(verbositySettingKey: string): string | null;
138
getCodeBlockContext(): ICodeBlockActionContext | undefined;
139
configureKeybindings(unassigned: boolean): void;
140
openHelpLink(): void;
141
}
142
143
144
export interface ICodeBlockActionContext {
145
code: string;
146
languageId?: string;
147
codeBlockIndex: number;
148
element: unknown;
149
}
150
151
export type AccesibleViewContentProvider = AccessibleContentProvider | ExtensionContentProvider;
152
153
export class AccessibleContentProvider extends Disposable implements IAccessibleViewContentProvider {
154
155
constructor(
156
public id: AccessibleViewProviderId,
157
public options: IAccessibleViewOptions,
158
public provideContent: () => string,
159
public onClose: () => void,
160
public verbositySettingKey: string,
161
public onOpen?: () => void,
162
public actions?: IAction[],
163
public provideNextContent?: () => string | undefined,
164
public providePreviousContent?: () => string | undefined,
165
public onDidChangeContent?: Event<void>,
166
public onKeyDown?: (e: IKeyboardEvent) => void,
167
public getSymbols?: () => IAccessibleViewSymbol[],
168
public onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>,
169
) {
170
super();
171
}
172
}
173
174
export function isIAccessibleViewContentProvider(obj: any): obj is IAccessibleViewContentProvider {
175
return obj && obj.id && obj.options && obj.provideContent && obj.onClose && obj.verbositySettingKey;
176
}
177
178
export class ExtensionContentProvider extends Disposable implements IBasicContentProvider {
179
180
constructor(
181
public readonly id: string,
182
public options: IAccessibleViewOptions,
183
public provideContent: () => string,
184
public onClose: () => void,
185
public onOpen?: () => void,
186
public provideNextContent?: () => string | undefined,
187
public providePreviousContent?: () => string | undefined,
188
public actions?: IAction[],
189
public onDidChangeContent?: Event<void>,
190
) {
191
super();
192
}
193
}
194
195
export interface IBasicContentProvider extends IDisposable {
196
id: string;
197
options: IAccessibleViewOptions;
198
onClose(): void;
199
provideContent(): string;
200
onOpen?(): void;
201
actions?: IAction[];
202
providePreviousContent?(): void;
203
provideNextContent?(): void;
204
onDidChangeContent?: Event<void>;
205
}
206
207