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