From b0cd9493fadea98992735b8b1cdc2c187c099c23 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 25 Sep 2024 16:31:34 +0200 Subject: [PATCH] Cmd+I behavior in Chat input box (fix microsoft/vscode-copilot#8616) --- .../electron-sandbox/actions/voiceChatActions.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions.ts b/src/vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions.ts index 22a1c1285402f..a553dc67b1fde 100644 --- a/src/vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions.ts +++ b/src/vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions.ts @@ -245,6 +245,8 @@ interface IActiveVoiceChatSession extends IVoiceChatSession { readonly id: number; readonly controller: IVoiceChatSessionController; readonly disposables: DisposableStore; + + hasRecognizedInput: boolean; } class VoiceChatSessions { @@ -280,6 +282,7 @@ class VoiceChatSessions { const session: IActiveVoiceChatSession = this.currentVoiceChatSession = { id: sessionId, controller, + hasRecognizedInput: false, disposables: new DisposableStore(), setTimeoutDisabled: (disabled: boolean) => { disableTimeout = disabled; }, accept: () => this.accept(sessionId), @@ -317,6 +320,7 @@ class VoiceChatSessions { break; case SpeechToTextStatus.Recognizing: if (text) { + session.hasRecognizedInput = true; session.controller.updateInput(inputValue ? [inputValue, text].join(' ') : text); if (voiceChatTimeout > 0 && context?.voice?.disableTimeout !== true && !disableTimeout) { acceptTranscriptionScheduler.cancel(); @@ -325,6 +329,7 @@ class VoiceChatSessions { break; case SpeechToTextStatus.Recognized: if (text) { + session.hasRecognizedInput = true; inputValue = inputValue ? [inputValue, text].join(' ') : text; session.controller.updateInput(inputValue); if (voiceChatTimeout > 0 && context?.voice?.disableTimeout !== true && !waitingForInput && !disableTimeout) { @@ -381,6 +386,15 @@ class VoiceChatSessions { return; } + if (!this.currentVoiceChatSession.hasRecognizedInput) { + // If we have an active session but without recognized + // input, we do not want to just accept the input that + // was maybe typed before. But we still want to stop the + // voice session because `acceptInput` would do that. + this.stop(voiceChatSessionId, this.currentVoiceChatSession.controller.context); + return; + } + const controller = this.currentVoiceChatSession.controller; const response = await controller.acceptInput(); if (!response) {