Skip to content

Commit 7cc0427

Browse files
authored
[Accessibility] Subsequent "Hey Code" does not work in the Chat view (microsoft#204137) (microsoft#204224)
1 parent 559f5be commit 7cc0427

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) {
@@ -764,7 +752,6 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
764752
@ICommandService private readonly commandService: ICommandService,
765753
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
766754
@IInstantiationService instantiationService: IInstantiationService,
767-
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
768755
@IEditorService private readonly editorService: IEditorService,
769756
@IHostService private readonly hostService: IHostService,
770757
@IChatService private readonly chatService: IChatService
@@ -820,7 +807,7 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
820807
localize('voice.keywordActivation.off', "Keyword activation is disabled."),
821808
localize('voice.keywordActivation.chatInView', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the chat view."),
822809
localize('voice.keywordActivation.quickChat', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the quick chat."),
823-
localize('voice.keywordActivation.inlineChat', "Keyword activation is enabled and listening for 'Hey Code' to start a voice chat session in the active editor."),
810+
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."),
824811
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.")
825812
],
826813
'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."),
@@ -882,10 +869,12 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
882869
return InlineVoiceChatAction.ID;
883870
case KeywordActivationContribution.SETTINGS_VALUE.QUICK_CHAT:
884871
return QuickVoiceChatAction.ID;
885-
case KeywordActivationContribution.SETTINGS_VALUE.CHAT_IN_CONTEXT:
886-
if (getFocusedCodeEditor(this.editorService, this.codeEditorService)) {
872+
case KeywordActivationContribution.SETTINGS_VALUE.CHAT_IN_CONTEXT: {
873+
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorControl);
874+
if (activeCodeEditor?.hasWidgetFocus()) {
887875
return InlineVoiceChatAction.ID;
888876
}
877+
}
889878
default:
890879
return VoiceChatInChatViewAction.ID;
891880
}

0 commit comments

Comments
 (0)