Skip to content

Commit 373ed50

Browse files
authored
voice - do not treat embedded editor as text editor (microsoft#202748)
1 parent 1404ba5 commit 373ed50

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarA
4646
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
4747
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
4848
import { IHostService } from 'vs/workbench/services/host/browser/host';
49+
import { ICodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser';
50+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
51+
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
4952

5053
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.") });
5154
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.") });
@@ -73,6 +76,15 @@ interface IVoiceChatSessionController {
7376
clearInputPlaceholder(): void;
7477
}
7578

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+
7688
class VoiceChatSessionControllerFactory {
7789

7890
static create(accessor: ServicesAccessor, context: 'inline'): Promise<IVoiceChatSessionController | undefined>;
@@ -87,6 +99,7 @@ class VoiceChatSessionControllerFactory {
8799
const codeEditorService = accessor.get(ICodeEditorService);
88100
const quickChatService = accessor.get(IQuickChatService);
89101
const layoutService = accessor.get(IWorkbenchLayoutService);
102+
const editorService = accessor.get(IEditorService);
90103

91104
// Currently Focused Context
92105
if (context === 'focused') {
@@ -114,7 +127,7 @@ class VoiceChatSessionControllerFactory {
114127
}
115128

116129
// Try with the inline chat
117-
const activeCodeEditor = codeEditorService.getFocusedCodeEditor();
130+
const activeCodeEditor = getFocusedCodeEditor(editorService, codeEditorService);
118131
if (activeCodeEditor) {
119132
const inlineChat = InlineChatController.get(activeCodeEditor);
120133
if (inlineChat?.hasFocus()) {
@@ -136,7 +149,7 @@ class VoiceChatSessionControllerFactory {
136149

137150
// Inline Chat
138151
if (context === 'inline') {
139-
const activeCodeEditor = codeEditorService.getFocusedCodeEditor();
152+
const activeCodeEditor = getFocusedCodeEditor(editorService, codeEditorService);
140153
if (activeCodeEditor) {
141154
const inlineChat = InlineChatController.get(activeCodeEditor);
142155
if (inlineChat) {
@@ -774,6 +787,7 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
774787
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
775788
@IInstantiationService instantiationService: IInstantiationService,
776789
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
790+
@IEditorService private readonly editorService: IEditorService,
777791
@IHostService private readonly hostService: IHostService
778792
) {
779793
super();
@@ -889,7 +903,7 @@ export class KeywordActivationContribution extends Disposable implements IWorkbe
889903
case KeywordActivationContribution.SETTINGS_VALUE.QUICK_CHAT:
890904
return QuickVoiceChatAction.ID;
891905
case KeywordActivationContribution.SETTINGS_VALUE.CHAT_IN_CONTEXT:
892-
if (this.codeEditorService.getFocusedCodeEditor()) {
906+
if (getFocusedCodeEditor(this.editorService, this.codeEditorService)) {
893907
return InlineVoiceChatAction.ID;
894908
}
895909
default:

0 commit comments

Comments
 (0)