Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityActions.ts
5292 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 { alert } from '../../../../../base/browser/ui/aria/aria.js';
7
import { localize } from '../../../../../nls.js';
8
import { Action2, registerAction2 } from '../../../../../platform/actions/common/actions.js';
9
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
10
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
11
import { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js';
12
import { IChatWidgetService } from '../chat.js';
13
import { ChatContextKeys } from '../../common/actions/chatContextKeys.js';
14
import { isResponseVM } from '../../common/model/chatViewModel.js';
15
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from '../../../../../platform/accessibility/common/accessibility.js';
16
17
export const ACTION_ID_FOCUS_CHAT_CONFIRMATION = 'workbench.action.chat.focusConfirmation';
18
19
class AnnounceChatConfirmationAction extends Action2 {
20
constructor() {
21
super({
22
id: ACTION_ID_FOCUS_CHAT_CONFIRMATION,
23
title: { value: localize('focusChatConfirmation', 'Focus Chat Confirmation'), original: 'Focus Chat Confirmation' },
24
category: { value: localize('chat.category', 'Chat'), original: 'Chat' },
25
precondition: ChatContextKeys.enabled,
26
f1: true,
27
keybinding: {
28
weight: KeybindingWeight.WorkbenchContrib,
29
primary: KeyMod.CtrlCmd | KeyCode.KeyA | KeyMod.Shift,
30
when: CONTEXT_ACCESSIBILITY_MODE_ENABLED
31
}
32
});
33
}
34
35
async run(accessor: ServicesAccessor): Promise<void> {
36
const chatWidgetService = accessor.get(IChatWidgetService);
37
const pendingWidget = chatWidgetService.getAllWidgets().find(widget => widget.viewModel?.model.requestNeedsInput.get());
38
39
if (!pendingWidget) {
40
alert(localize('noChatSession', 'No active chat session found.'));
41
return;
42
}
43
44
const viewModel = pendingWidget.viewModel;
45
if (!viewModel) {
46
alert(localize('chatNotReady', 'Chat interface not ready.'));
47
return;
48
}
49
50
// Check for active confirmations in the chat responses
51
let firstConfirmationElement: HTMLElement | undefined;
52
53
const lastResponse = viewModel.getItems()[viewModel.getItems().length - 1];
54
if (isResponseVM(lastResponse)) {
55
// eslint-disable-next-line no-restricted-syntax
56
const confirmationWidgets = pendingWidget.domNode.querySelectorAll('.chat-confirmation-widget-container');
57
if (confirmationWidgets.length > 0) {
58
firstConfirmationElement = confirmationWidgets[0] as HTMLElement;
59
}
60
}
61
62
if (firstConfirmationElement) {
63
firstConfirmationElement.focus();
64
} else {
65
alert(localize('noConfirmationRequired', 'No chat confirmation required'));
66
}
67
}
68
}
69
70
export function registerChatAccessibilityActions(): void {
71
registerAction2(AnnounceChatConfirmationAction);
72
}
73
74