mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-02 14:25:42 +01:00
improve
This commit is contained in:
@@ -20,19 +20,23 @@ import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEdito
|
||||
import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
|
||||
import { IDisposable } from 'xterm';
|
||||
|
||||
interface IAccessibleViewProvider { id: string; provideContent(): string; onClose(): void }
|
||||
interface IAccessibleContentProvider { id: string; provideContent(): string; onClose(): void; options?: IAccessibleViewOptions }
|
||||
export const IAccessibleViewService = createDecorator<IAccessibleViewService>('accessibleViewService');
|
||||
|
||||
export interface IAccessibleViewService {
|
||||
readonly _serviceBrand: undefined;
|
||||
show(providerId: string): void;
|
||||
registerProvider(provider: IAccessibleViewProvider): void;
|
||||
registerProvider(provider: IAccessibleContentProvider): void;
|
||||
}
|
||||
|
||||
export interface IAccessibleViewOptions {
|
||||
isHelpMenu: boolean;
|
||||
}
|
||||
|
||||
export class AccessibleViewService extends Disposable implements IAccessibleViewService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private _providers: Map<string, IAccessibleViewProvider> = new Map();
|
||||
private _providers: Map<string, IAccessibleContentProvider> = new Map();
|
||||
private _editorWidget: CodeEditorWidget;
|
||||
private _editorContainer: HTMLElement;
|
||||
|
||||
@@ -66,7 +70,7 @@ export class AccessibleViewService extends Disposable implements IAccessibleView
|
||||
this._editorWidget = this._register(this._instantiationService.createInstance(CodeEditorWidget, this._editorContainer, editorOptions, codeEditorWidgetOptions));
|
||||
}
|
||||
|
||||
registerProvider(provider: IAccessibleViewProvider): void {
|
||||
registerProvider(provider: IAccessibleContentProvider): void {
|
||||
this._providers.set(provider.id, provider);
|
||||
}
|
||||
|
||||
@@ -83,16 +87,21 @@ export class AccessibleViewService extends Disposable implements IAccessibleView
|
||||
this._contextViewService.showContextView(delegate);
|
||||
}
|
||||
|
||||
private _getContent(providerId: string): string {
|
||||
private _getProviderOrThrow(providerId: string): IAccessibleContentProvider {
|
||||
const provider = this._providers.get(providerId);
|
||||
if (!provider) {
|
||||
throw new Error(`No accessible view provider with id: ${providerId}`);
|
||||
}
|
||||
return provider.provideContent();
|
||||
return provider;
|
||||
}
|
||||
|
||||
private _getContent(providerId: string): string {
|
||||
return this._getProviderOrThrow(providerId).provideContent();
|
||||
}
|
||||
|
||||
private _render(providerId: string, container: HTMLElement): IDisposable {
|
||||
const fragment = localize('introMsg', "Welcome to {0} Accessibility Help. Exit this menu and return to the terminal via the Escape key.\n", providerId) + this._getContent(providerId);
|
||||
const provider = this._getProviderOrThrow(providerId);
|
||||
const fragment = provider.options?.isHelpMenu ? localize('introMsg', "Welcome to {0} Accessibility Help. Exit this menu and return to the {0} via the Escape key.\n", providerId) : '' + this._getContent(providerId);
|
||||
this._getTextModel(URI.from({ path: `accessible-view-${providerId}`, scheme: 'accessible-view', fragment })).then((model) => {
|
||||
if (!model) {
|
||||
return;
|
||||
|
||||
@@ -74,12 +74,15 @@ export async function runAccessibilityHelpAction(accessor: ServicesAccessor, edi
|
||||
inputEditor.getSupportedActions();
|
||||
const helpText = getAccessibilityHelpText(accessor, type, type === 'editor' ? cachedInput : undefined);
|
||||
accessibleViewService.registerProvider({
|
||||
id: 'chat', provideContent: () => helpText, onClose: () => {
|
||||
id: 'chat',
|
||||
provideContent: () => helpText,
|
||||
onClose: () => {
|
||||
if (cachedPosition) {
|
||||
inputEditor.setPosition(cachedPosition);
|
||||
inputEditor.focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
options: { isHelpMenu: true }
|
||||
});
|
||||
accessibleViewService.show('chat');
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ export class AccessibilityHelpWidget {
|
||||
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
|
||||
@IAccessibleViewService private readonly _accessibleViewService: IAccessibleViewService
|
||||
) {
|
||||
this._accessibleViewService.registerProvider({ id: 'terminal', provideContent: () => this._getContent(), onClose: () => _instance.focus() });
|
||||
this._accessibleViewService.registerProvider({ id: 'terminal', provideContent: () => this._getContent(), onClose: () => _instance.focus(), options: { isHelpMenu: true } });
|
||||
this._hasShellIntegration = _xterm.shellIntegration.status === ShellIntegrationStatus.VSCode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user