Skip to content

Commit 170042b

Browse files
authored
[Accessibility] Subsequent "Hey Code" does not work in the Chat view (fix microsoft#204137) (microsoft#204225)
1 parent c8599d6 commit 170042b

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ import { Registry } from 'vs/platform/registry/common/platform';
4444
import { IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
4545
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';
4646
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
47-
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
4847
import { IHostService } from 'vs/workbench/services/host/browser/host';
49-
import { ICodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser';
48+
import { getCodeEditor } from 'vs/editor/browser/editorBrowser';
5049
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
51-
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
5250

5351
const CONTEXT_VOICE_CHAT_GETTING_READY = new RawContextKey<boolean>('voiceChatGettingReady', false, { type: 'boolean', description: localize('voiceChatGettingReady', "True when getting ready for receiving voice input from the microphone for voice chat.") });
5452
const CONTEXT_VOICE_CHAT_IN_PROGRESS = new RawContextKey<boolean>('voiceChatInProgress', false, { type: 'boolean', description: localize('voiceChatInProgress', "True when voice recording from microphone is in progress for voice chat.") });
@@ -76,15 +74,6 @@ interface IVoiceChatSessionController {
7674
clearInputPlaceholder(): void;
7775
}
7876

79-
function getFocusedCodeEditor(editorService: IEditorService, codeEditorService: ICodeEditorService): ICodeEditor | null {
80-
const codeEditor = getCodeEditor(codeEditorService.getFocusedCodeEditor());
81-
if (codeEditor && !(codeEditor instanceof EmbeddedCodeEditorWidget)) {
82-
return codeEditor;
83-
}
84-
85-
return getCodeEditor(editorService.activeTextEditorControl);
86-
}
87-
8877
class VoiceChatSessionControllerFactory {
8978

9079
static create(accessor: ServicesAccessor, context: 'inline'): Promise<IVoiceChatSessionController | undefined>;
@@ -96,7 +85,6 @@ class VoiceChatSessionControllerFactory {
9685
const chatService = accessor.get(IChatService);
9786
const viewsService = accessor.get(IViewsService);
9887
const chatContributionService = accessor.get(IChatContributionService);
99-
const codeEditorService = accessor.get(ICodeEditorService);
10088
const quickChatService = accessor.get(IQuickChatService);
10189
const layoutService = accessor.get(IWorkbenchLayoutService);
10290
const editorService = accessor.get(IEditorService);
@@ -127,7 +115,7 @@ class VoiceChatSessionControllerFactory {
127115
}
128116

129117
// Try with the inline chat
130-
const activeCodeEditor = getFocusedCodeEditor(editorService, codeEditorService);
118+
const activeCodeEditor = getCodeEditor(editorService.activeTextEditorControl);
131119
if (activeCodeEditor) {
132120
const inlineChat = InlineChatController.get(activeCodeEditor);
133121
if (inlineChat?.hasFocus()) {
@@ -149,7 +137,7 @@ class VoiceChatSessionControllerFactory {
149137

150138
// Inline Chat
151139
if (context === 'inline') {
152-
const activeCodeEditor = getFocusedCodeEditor(editorService, codeEditorService);
140+
const activeCodeEditor = getCodeEditor(editorService.activeTextEditorControl);
153141
if (activeCodeEditor) {
154142
const inlineChat = InlineChatController.get(activeCodeEditor);
155143
if (inlineChat) {
@@ -794,7 +782,6 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
794782
@ICommandService private readonly commandService: ICommandService,
795783
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
796784
@IInstantiationService instantiationService: IInstantiationService,
797-
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
798785
@IEditorService private readonly editorService: IEditorService,
799786
@IHostService private readonly hostService: IHostService,
800787
@IChatService private readonly chatService: IChatService
@@ -850,7 +837,7 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
850837
localize('voice.keywordActivation.off', "Keyword activation is disabled."),
851838
localize('voice.keywordActivation.chatInView', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the chat view."),
852839
localize('voice.keywordActivation.quickChat', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the quick chat."),
853-
localize('voice.keywordActivation.inlineChat', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the active editor."),
840+
localize('voice.keywordActivation.inlineChat', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the active editor if possible."),
854841
localize('voice.keywordActivation.chatInContext', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the active editor or view depending on keyboard focus.")
855842
],
856843
'description': localize('voice.keywordActivation', "Controls whether the keyword phrase 'Hey Code' is recognized to start a voice chat session. Enabling this will start recording from the microphone but the audio is processed locally and never sent to a server."),
@@ -912,10 +899,12 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
912899
return InlineVoiceChatAction.ID;
913900
case KeywordActivationContribution.SETTINGS_VALUE.QUICK_CHAT:
914901
return QuickVoiceChatAction.ID;
915-
case KeywordActivationContribution.SETTINGS_VALUE.CHAT_IN_CONTEXT:
916-
if (getFocusedCodeEditor(this.editorService, this.codeEditorService)) {
902+
case KeywordActivationContribution.SETTINGS_VALUE.CHAT_IN_CONTEXT: {
903+
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorControl);
904+
if (activeCodeEditor?.hasWidgetFocus()) {
917905
return InlineVoiceChatAction.ID;
918906
}
907+
}
919908
default:
920909
return VoiceChatInChatViewAction.ID;
921910
}

0 commit comments

Comments
 (0)